forked from rc/aircox
fix error in page filtering; sectionitems are now directly children of section
This commit is contained in:
parent
b8d6c435d2
commit
f183669c04
|
@ -422,6 +422,7 @@ class Schedule(models.Model):
|
||||||
# the schedule is present.
|
# the schedule is present.
|
||||||
# For ponctual programs, there is no need for a schedule, only a diffusion
|
# For ponctual programs, there is no need for a schedule, only a diffusion
|
||||||
class Frequency(IntEnum):
|
class Frequency(IntEnum):
|
||||||
|
ponctual = 0b000000
|
||||||
first = 0b000001
|
first = 0b000001
|
||||||
second = 0b000010
|
second = 0b000010
|
||||||
third = 0b000100
|
third = 0b000100
|
||||||
|
@ -445,6 +446,7 @@ class Schedule(models.Model):
|
||||||
_('frequency'),
|
_('frequency'),
|
||||||
choices = [
|
choices = [
|
||||||
(int(y), {
|
(int(y), {
|
||||||
|
'ponctual': _('ponctual'),
|
||||||
'first': _('first week of the month'),
|
'first': _('first week of the month'),
|
||||||
'second': _('second week of the month'),
|
'second': _('second week of the month'),
|
||||||
'third': _('third week of the month'),
|
'third': _('third week of the month'),
|
||||||
|
|
|
@ -487,8 +487,9 @@ class Section(ClusterableModel):
|
||||||
FieldPanel('name'),
|
FieldPanel('name'),
|
||||||
FieldPanel('position'),
|
FieldPanel('position'),
|
||||||
FieldPanel('model'),
|
FieldPanel('model'),
|
||||||
|
FieldPanel('page'),
|
||||||
], heading=_('General')),
|
], heading=_('General')),
|
||||||
InlinePanel('places', label=_('Section Items')),
|
# InlinePanel('items', label=_('Section Items')),
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -499,12 +500,15 @@ class Section(ClusterableModel):
|
||||||
"""
|
"""
|
||||||
qs = Section.objects.filter(position = position)
|
qs = Section.objects.filter(position = position)
|
||||||
if page:
|
if page:
|
||||||
|
qs = qs.filter(
|
||||||
|
models.Q(page__isnull = True) |
|
||||||
|
models.Q(page = page)
|
||||||
|
)
|
||||||
qs = qs.filter(
|
qs = qs.filter(
|
||||||
models.Q(model__isnull = True) |
|
models.Q(model__isnull = True) |
|
||||||
models.Q(
|
models.Q(
|
||||||
model = ContentType.objects.get_for_model(page).pk
|
model = ContentType.objects.get_for_model(page).pk
|
||||||
) |
|
)
|
||||||
models.Q(page = page)
|
|
||||||
)
|
)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
@ -513,39 +517,22 @@ class Section(ClusterableModel):
|
||||||
Add an item to the section. Automatically save the item and
|
Add an item to the section. Automatically save the item and
|
||||||
create the corresponding SectionPlace.
|
create the corresponding SectionPlace.
|
||||||
"""
|
"""
|
||||||
# TODO: arbitrary position; Orderable.sort_order?
|
item.section = self
|
||||||
item.save()
|
item.save()
|
||||||
place, created = SectionPlace.objects.get_or_create(
|
|
||||||
section = self,
|
|
||||||
item = item,
|
|
||||||
)
|
|
||||||
|
|
||||||
def render(self, request, page = None, context = None, *args, **kwargs):
|
def render(self, request, page = None, context = None, *args, **kwargs):
|
||||||
|
# if self.page and page != self.page.specific:
|
||||||
|
# return ''
|
||||||
|
|
||||||
return ''.join([
|
return ''.join([
|
||||||
place.item.specific.render(request, page, context, *args, **kwargs)
|
item.specific.render(request, page, context, *args, **kwargs)
|
||||||
for place in self.places.all()
|
for item in self.items.all().order_by('order')
|
||||||
])
|
])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}: {}'.format(self.__class__.__name__, self.name or self.pk)
|
return '{}: {}'.format(self.__class__.__name__, self.name or self.pk)
|
||||||
|
|
||||||
|
|
||||||
class SectionPlace(Orderable):
|
|
||||||
section = ParentalKey(Section, related_name='places')
|
|
||||||
item = models.ForeignKey(
|
|
||||||
'SectionItem',
|
|
||||||
verbose_name=_('item'),
|
|
||||||
)
|
|
||||||
|
|
||||||
panels = [ SnippetChooserPanel('item'), ]
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
unique_together = ('section', 'item')
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return '{}: {}'.format(self.__class__.__name__, self.title or self.pk)
|
|
||||||
|
|
||||||
|
|
||||||
class SectionItemMeta(models.base.ModelBase):
|
class SectionItemMeta(models.base.ModelBase):
|
||||||
"""
|
"""
|
||||||
Metaclass for SectionItem, assigning needed values such as `template`.
|
Metaclass for SectionItem, assigning needed values such as `template`.
|
||||||
|
@ -576,6 +563,12 @@ class SectionItem(models.Model,metaclass=SectionItemMeta):
|
||||||
"""
|
"""
|
||||||
Base class for a section item.
|
Base class for a section item.
|
||||||
"""
|
"""
|
||||||
|
section = ParentalKey(Section, related_name='items')
|
||||||
|
order = models.IntegerField(
|
||||||
|
_('order'),
|
||||||
|
default = 100,
|
||||||
|
help_text = _('position in the menu. The higher, the latest to render')
|
||||||
|
)
|
||||||
real_type = models.CharField(
|
real_type = models.CharField(
|
||||||
max_length=32,
|
max_length=32,
|
||||||
blank = True, null = True,
|
blank = True, null = True,
|
||||||
|
@ -598,8 +591,10 @@ class SectionItem(models.Model,metaclass=SectionItemMeta):
|
||||||
)
|
)
|
||||||
panels = [
|
panels = [
|
||||||
MultiFieldPanel([
|
MultiFieldPanel([
|
||||||
|
FieldPanel('section'),
|
||||||
FieldPanel('title'),
|
FieldPanel('title'),
|
||||||
FieldPanel('show_title'),
|
FieldPanel('show_title'),
|
||||||
|
FieldPanel('order'),
|
||||||
FieldPanel('css_class'),
|
FieldPanel('css_class'),
|
||||||
], heading=_('General')),
|
], heading=_('General')),
|
||||||
]
|
]
|
||||||
|
@ -782,33 +777,9 @@ class SectionLink(RelatedLinkBase, SectionItem):
|
||||||
Render a link to a page or a given url.
|
Render a link to a page or a given url.
|
||||||
Can either be used standalone or in a SectionLinkList
|
Can either be used standalone or in a SectionLinkList
|
||||||
"""
|
"""
|
||||||
parent = ParentalKey('SectionLinkList', related_name='links',
|
|
||||||
blank=True, null=True)
|
|
||||||
panels = SectionItem.panels + RelatedLinkBase.panels
|
panels = SectionItem.panels + RelatedLinkBase.panels
|
||||||
|
|
||||||
|
|
||||||
@register_snippet
|
|
||||||
class SectionLinkList(SectionRelativeItem, ClusterableModel):
|
|
||||||
"""
|
|
||||||
Render a list of links. If related to the current page, print
|
|
||||||
the page's links otherwise, the assigned link list.
|
|
||||||
|
|
||||||
Note: assign the link's class to the <a> tag if there is some.
|
|
||||||
"""
|
|
||||||
panels = SectionItem.panels + [
|
|
||||||
InlinePanel('links', label=_('links'), help_text=_(
|
|
||||||
'If the list is related to the current page, theses links '
|
|
||||||
'will be used when there is no links found for this publication'
|
|
||||||
))
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_context(self, request, page):
|
|
||||||
context = super().get_context(request, page)
|
|
||||||
links = self.related_attr(page, 'related_link') or self.links
|
|
||||||
context['object_list'] = links.all()
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
@register_snippet
|
@register_snippet
|
||||||
class SectionList(ListBase, SectionRelativeItem):
|
class SectionList(ListBase, SectionRelativeItem):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -29,7 +29,7 @@ def station_post_saved(sender, instance, created, *args, **kwargs):
|
||||||
body = _(
|
body = _(
|
||||||
'If you see this page, then Aircox is running for the station '
|
'If you see this page, then Aircox is running for the station '
|
||||||
'{station.name}. You might want to change it to a better one. '
|
'{station.name}. You might want to change it to a better one. '
|
||||||
),
|
).format(station = instance),
|
||||||
)
|
)
|
||||||
root_page.add_child(instance=homepage)
|
root_page.add_child(instance=homepage)
|
||||||
|
|
||||||
|
@ -75,13 +75,14 @@ def station_post_saved(sender, instance, created, *args, **kwargs):
|
||||||
homepage.add_child(instance = programs)
|
homepage.add_child(instance = programs)
|
||||||
|
|
||||||
section = sections.Section(
|
section = sections.Section(
|
||||||
name = _('Programs List'),
|
name = _('Programs'),
|
||||||
position = 'post_content',
|
position = 'post_content',
|
||||||
page = programs,
|
page = programs,
|
||||||
)
|
)
|
||||||
section.save();
|
section.save();
|
||||||
section.add_item(sections.SectionList(
|
section.add_item(sections.SectionList(
|
||||||
count = 15,
|
count = 15,
|
||||||
|
title = _('Programs'),
|
||||||
url_text = _('All programs'),
|
url_text = _('All programs'),
|
||||||
model = ContentType.objects.get_for_model(models.ProgramPage),
|
model = ContentType.objects.get_for_model(models.ProgramPage),
|
||||||
related = programs,
|
related = programs,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user