forked from rc/aircox
related on SectionItemItem instead of Section; remember original type + specific() on SectionItems;...
This commit is contained in:
parent
ac5db1ea84
commit
74e4f42ca5
|
@ -354,14 +354,6 @@ class Section(ClusterableModel):
|
||||||
blank = True, null = True,
|
blank = True, null = True,
|
||||||
help_text=_('section container\'s "class" attribute')
|
help_text=_('section container\'s "class" attribute')
|
||||||
)
|
)
|
||||||
related = models.ForeignKey(
|
|
||||||
ContentType,
|
|
||||||
blank = True, null = True,
|
|
||||||
help_text=_('this section is displayed only for this model'),
|
|
||||||
#limit_choices_to = {
|
|
||||||
# 'page__isnull': False
|
|
||||||
#}
|
|
||||||
)
|
|
||||||
position = models.CharField(
|
position = models.CharField(
|
||||||
_('position'),
|
_('position'),
|
||||||
max_length=16,
|
max_length=16,
|
||||||
|
@ -374,11 +366,8 @@ class Section(ClusterableModel):
|
||||||
MultiFieldPanel([
|
MultiFieldPanel([
|
||||||
FieldPanel('name'),
|
FieldPanel('name'),
|
||||||
FieldPanel('css_class'),
|
FieldPanel('css_class'),
|
||||||
], heading=_('General')),
|
|
||||||
MultiFieldPanel([
|
|
||||||
FieldPanel('related'),
|
|
||||||
FieldPanel('position'),
|
FieldPanel('position'),
|
||||||
], heading=_('Position')),
|
], heading=_('General')),
|
||||||
InlinePanel('section_items', label=_('section items')),
|
InlinePanel('section_items', label=_('section items')),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -389,28 +378,24 @@ class Section(ClusterableModel):
|
||||||
|
|
||||||
class SectionItemItem(Orderable):
|
class SectionItemItem(Orderable):
|
||||||
section = ParentalKey(Section, related_name='section_items')
|
section = ParentalKey(Section, related_name='section_items')
|
||||||
|
related = models.ForeignKey(
|
||||||
|
ContentType,
|
||||||
|
blank = True, null = True,
|
||||||
|
help_text=_('this section is displayed only for this model'),
|
||||||
|
limit_choices_to = {
|
||||||
|
'model__in': ('publication','programpage','diffusionpage',
|
||||||
|
'eventpage'),
|
||||||
|
}
|
||||||
|
)
|
||||||
item = models.ForeignKey(
|
item = models.ForeignKey(
|
||||||
'SectionItem',
|
'SectionItem',
|
||||||
verbose_name=_('item')
|
verbose_name=_('item')
|
||||||
)
|
)
|
||||||
panels = [
|
panels = [
|
||||||
SnippetChooserPanel('item'),
|
SnippetChooserPanel('item'),
|
||||||
|
FieldPanel('related'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def specific(self):
|
|
||||||
"""
|
|
||||||
Return a downcasted version of the post if it is from another
|
|
||||||
model, or itself
|
|
||||||
"""
|
|
||||||
if not self.real_type or type(self) != Post:
|
|
||||||
return self
|
|
||||||
return getattr(self, self.real_type)
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
#if type(self) != SectionItem and not self.real_type:
|
|
||||||
# self.real_type = type(self).__name__.lower()
|
|
||||||
return super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}: {}'.format(self.__class__.__name__, self.title or self.pk)
|
return '{}: {}'.format(self.__class__.__name__, self.title or self.pk)
|
||||||
|
|
||||||
|
@ -445,8 +430,26 @@ class SectionItem(models.Model):
|
||||||
], heading=_('General')),
|
], heading=_('General')),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def specific(self):
|
||||||
|
"""
|
||||||
|
Return a downcasted version of the post if it is from another
|
||||||
|
model, or itself
|
||||||
|
"""
|
||||||
|
if not self.real_type or type(self) != Post:
|
||||||
|
return self
|
||||||
|
return getattr(self, self.real_type)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if type(self) != SectionItem and not self.real_type:
|
||||||
|
self.real_type = type(self).__name__.lower()
|
||||||
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}: {}'.format(self.__class__.__name__, self.title or self.pk)
|
return '{}: {}'.format(
|
||||||
|
(self.real_type or 'section item').replace('section','section '),
|
||||||
|
self.title or self.pk
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register_snippet
|
@register_snippet
|
||||||
|
@ -471,12 +474,30 @@ class SectionImage(SectionItem):
|
||||||
|
|
||||||
@register_snippet
|
@register_snippet
|
||||||
class SectionLink(BaseRelatedLink,SectionItem):
|
class SectionLink(BaseRelatedLink,SectionItem):
|
||||||
|
"""
|
||||||
|
Can either be used standalone or in a SectionLinkList
|
||||||
|
"""
|
||||||
|
parent = ParentalKey('SectionLinkList', related_name='links',
|
||||||
|
blank=True, null=True)
|
||||||
panels = SectionItem.panels + BaseRelatedLink.panels
|
panels = SectionItem.panels + BaseRelatedLink.panels
|
||||||
|
|
||||||
|
|
||||||
|
@register_snippet
|
||||||
|
class SectionLinkList(SectionItem,ClusterableModel):
|
||||||
|
panels = SectionItem.panels + [
|
||||||
|
InlinePanel('links', label=_('links'))
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@register_snippet
|
@register_snippet
|
||||||
class SectionPublicationList(BaseList,SectionItem):
|
class SectionPublicationList(BaseList,SectionItem):
|
||||||
panels = SectionItem.panels + BaseList.panels
|
focus_available = models.BooleanField(
|
||||||
|
_('focus available'),
|
||||||
|
default = False,
|
||||||
|
help_text = _('if true, highlight the first focused article found')
|
||||||
|
)
|
||||||
|
panels = SectionItem.panels + [ FieldPanel('focus_available') ] +\
|
||||||
|
BaseList.panels
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user