Skip to content

Commit

Permalink
fix #23
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Aug 14, 2024
1 parent e14122c commit f1b5a18
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
20 changes: 15 additions & 5 deletions AM_Nihoul_website/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def get_context_data(self, *args, **kwargs):

# fetch list of pages
ctx['pages'] = Page.query.order_by(Page.slug).all()
ctx['categories'] = dict((c.id, c) for c in Category.query.all())
ctx['categories'] = Category.ordered_items().all()
ctx['categories'].append(None)

return ctx

Expand All @@ -145,18 +146,27 @@ def get_form(self):
form = super().get_form()

# add choices for categories
choices = [(-1, '')]
choices.extend((c.id, c.name) for c in Category.query.order_by(Category.name).all())
categories = Category.ordered_items().all()

choices = [(-1, '** pas de catégorie **')]
choices.extend((c.id, c.name) for c in categories)
form.category.choices = choices

# add choices for next
choices = [(-1, '')]
choices = {}
q = Page.query.order_by(Page.title)

if isinstance(self, PageEditView): # avoid getting the page looping to itself
q = q.filter(Page.id.isnot(self.object.id))

choices.extend((c.id, c.title) for c in q.all())
pages = q.all()

choices['No category'] = [(-1, '** pas de page suivante **')]
choices['No category'].extend((p.id, p.title) for p in pages if p.category_id is None)

for category in categories:
choices[category.name] = [(p.id, p.title) for p in pages if p.category_id == category.id]

form.next.choices = choices

return form
Expand Down
2 changes: 1 addition & 1 deletion AM_Nihoul_website/templates/admin/menus.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3>Menu {% if menus == main_menu %}principal{% else %}secondaire{% endif %}</h3
<tr>
<td class="left">
<span class="title">{{ menu.text }}</span>
<span class="info">Menu {% if menu.position.value == 2 %}secondaire{% else %}primaire{% endif %} &bull; <a href="{{ menu.url }}">{{ menu.url }}</a></span>
<span class="info"><a href="{{ menu.url }}">{{ menu.url }}</a></span>
</td>
<td class="right">
<span class="buttons">
Expand Down
9 changes: 7 additions & 2 deletions AM_Nihoul_website/templates/admin/pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
<a class="btn btn-primary" href="{{ url_for('admin.page-create') }}"><span class="fas fa-plus"></span> Ajouter une page</a>
</p>

{% for category in categories %}
<h3>{% if category is not none %}{{ category.name }}{% else %}Pas de catégorie{% endif %}</h3>
<table class="admin-list">
{% for page in pages %}
{% if (category is none and page.category is none) or page.category_id == category.id %}
<tr>
<td class="left">
<span class="title"><a href="{{ url_for('visitor.page-view', id=page.id, slug=page.slug) }}">{{ page.title }}</a></span>
<span class="info">{% if page.category_id != None %}{{ categories[page.category_id].name }}{% else %}<i>pas de catégorie</i>{% endif %}</span>
<span class="info">Dernière modification: {{ page.date_modified|date_formatter }}</span>
</td>
<td class="right">
<span class="buttons">
Expand All @@ -29,9 +32,11 @@
<a class="button-like" href="#"><span class="fas fa-lock"></span></a>
{% endif %}
</span>
<span class="info">Dernière modification: {{ page.date_modified|date_formatter }}</span>
<span class="info"></span>
</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% endfor %}
{% endblock %}
2 changes: 1 addition & 1 deletion AM_Nihoul_website/templates/briefs.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tr>
<td class="left">
<span class="title"><a href="{{ url_for('visitor.brief-view', id=brief.id, slug=brief.slug) }}">{{ brief.title }}</a></span>
<span class="info">{{ brief.summary }} &bull; Publication le {{ brief.date_created|date_formatter }}.</span>
<span class="info">{{ brief.summary }} &bull; Publication {{ brief.date_created|date_formatter }}.</span>
</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit f1b5a18

Please sign in to comment.