-class NodeNavigationOverride(Entity):
- parent = models.ForeignKey(Node, related_name="child_navigation_overrides", blank=True, null=True)
- child = models.ForeignKey(Node, related_name="navigation_overrides")
-
- title = models.CharField(max_length=100, blank=True)
- url = models.CharField(max_length=200, validators=[RedirectValidator()], blank=True)
- order = models.PositiveSmallIntegerField(blank=True, null=True)
- child_navigation = JSONField()
- hide = models.BooleanField()
-
- def get_navigation(self, node, max_depth):
- default = node.view.get_navigation(node, max_depth)
- if self.url:
- default['url'] = self.url
- if self.title:
- default['title'] = self.title
- if self.order:
- default['order'] = self.order
- if isinstance(self.child_navigation, list) and node.get_level() < max_depth:
- child_navigation = self.child_navigation[:]
-
- for child in child_navigation:
- child['url'] = default['url'] + child['url']
-
- if 'children' in default:
- overridden = set([child['url'] for child in default['children']]) & set([child['url'] for child in self.child_navigation])
- if overridden:
- for child in default[:]:
- if child['url'] in overridden:
- default.remove(child)
- default['children'] += self.child_navigation
- else:
- default['children'] = self.child_navigation
- return default
-
- class Meta:
- ordering = ['order']
- unique_together = ('parent', 'child',)
- app_label = 'philo'
-
-