Tri des annuaires

This commit is contained in:
Evarin 2018-01-28 19:09:35 +01:00
parent 8488beeb4e
commit c11ccf2ecc
2 changed files with 33 additions and 4 deletions

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-01-28 16:17
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cofcms', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='cofdirectoryentrypage',
name='sort_order',
field=models.IntegerField(blank=True, editable=False, null=True),
),
migrations.AddField(
model_name='cofdirectorypage',
name='alphabetique',
field=models.BooleanField(default=True, verbose_name='Tri par ordre alphabétique ?'),
),
]

View file

@ -154,9 +154,12 @@ class COFActuPage(Page):
# Annuaires (Clubs, partenaires, bonnes adresses) # Annuaires (Clubs, partenaires, bonnes adresses)
class COFDirectoryPage(Page): class COFDirectoryPage(Page):
introduction = RichTextField("Introduction") introduction = RichTextField("Introduction")
alphabetique = models.BooleanField("Tri par ordre alphabétique ?",
default=True, blank=True)
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel('introduction'), FieldPanel('introduction'),
FieldPanel('alphabetique'),
] ]
subpage_types = ['COFActuPage', 'COFDirectoryEntryPage'] subpage_types = ['COFActuPage', 'COFDirectoryEntryPage']
@ -165,8 +168,9 @@ class COFDirectoryPage(Page):
@property @property
def entries(self): def entries(self):
entries = COFDirectoryEntryPage.objects.live()\ entries = COFDirectoryEntryPage.objects.live()\
.descendant_of(self)\ .descendant_of(self)
.order_by("title") if self.alphabetique:
entries = entries.order_by("title")
return entries return entries
class Meta: class Meta:
@ -174,7 +178,7 @@ class COFDirectoryPage(Page):
verbose_name_plural = "Annuaires" verbose_name_plural = "Annuaires"
class COFDirectoryEntryPage(Page): class COFDirectoryEntryPage(Page, Orderable):
body = RichTextField("Description") body = RichTextField("Description")
links = StreamField([ links = StreamField([
('lien', blocks.StructBlock([ ('lien', blocks.StructBlock([