Skip to content

Commit

Permalink
Merge branch 'new_faq'
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Jun 30, 2023
2 parents dd05ff6 + ce298b5 commit e6f29d3
Show file tree
Hide file tree
Showing 24 changed files with 820 additions and 171 deletions.
10 changes: 10 additions & 0 deletions envergo/pages/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin

from envergo.pages.models import NewsItem


@admin.register(NewsItem)
class NewsItemAdmin(admin.ModelAdmin):
list_display = ["title", "created_at"]
search_fields = ["title", "content_md"]
fields = ["title", "content_md", "created_at"]
39 changes: 39 additions & 0 deletions envergo/pages/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 4.2 on 2023-04-25 08:29

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="NewsItem",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("content_md", models.TextField(verbose_name="Content")),
("content_html", models.TextField(verbose_name="Content HTML")),
(
"created_at",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="Date created"
),
),
],
options={
"verbose_name": "News item",
"verbose_name_plural": "News items",
},
),
]
18 changes: 18 additions & 0 deletions envergo/pages/migrations/0002_newsitem_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2023-05-22 08:00

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("pages", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="newsitem",
name="title",
field=models.CharField(default="", max_length=255, verbose_name="Title"),
preserve_default=False,
),
]
25 changes: 25 additions & 0 deletions envergo/pages/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from envergo.utils.markdown import markdown_to_html


class NewsItem(models.Model):
"""A news item to be displayed on the FAQ page."""

title = models.CharField(_("Title"), max_length=255)
content_md = models.TextField(_("Content"))
content_html = models.TextField(_("Content HTML"))
created_at = models.DateTimeField(_("Date created"), default=timezone.now)

class Meta:
verbose_name = _("News item")
verbose_name_plural = _("News items")

def __str__(self):
return self.title

def save(self, *args, **kwargs):
self.content_html = markdown_to_html(self.content_md)
super().save(*args, **kwargs)
56 changes: 44 additions & 12 deletions envergo/pages/templatetags/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,71 @@ def nav_link(route, label, aria_current=False):


@register.simple_tag(takes_context=True)
def menu_item(context, route, label):
"""Generate html for a main menu item."""
def menu_item(context, route, label, subroutes=[]):
"""Generate html for a main menu item.
If you pass a list of subroutes, the menu item will be highlighted
if the current url is any on the main route or subroutes.
"""

try:
current_route = context.request.resolver_match.url_name
except AttributeError:
current_route = ""

aria_current = route == current_route
aria_current = route == current_route or current_route in subroutes
return nav_link(route, label, aria_current)


@register.simple_tag(takes_context=True)
def evalreq_menu(context):
"""Generate html for the "Demander une évaluation" collapsible menu."""

link_route = "request_evaluation"
link_label = "Demander une évaluation manuelle"

def sidemenu_item(context, route, label):
try:
current_route = context.request.resolver_match.url_name
except AttributeError:
current_route = ""

routes = [
aria_current = route == current_route
url = reverse(route)
sidemenu_class = "fr-sidemenu__item--current" if aria_current else ""
aria_attr = 'aria-current="page"' if aria_current else ""
return mark_safe(
f"""
<li class="fr-sidemenu__item {sidemenu_class}">
<a class="fr-sidemenu__link" href="{url}" {aria_attr}>
{label}
</a>
</li>
"""
)


@register.simple_tag(takes_context=True)
def evalreq_menu(context):
"""Generate html for the "Demander une évaluation" collapsible menu."""

link_route = "request_evaluation"
link_label = "Demander une évaluation manuelle"
subroutes = [
"request_eval_wizard_step_1",
"request_eval_wizard_step_2",
"request_eval_wizard_step_3",
"request_success",
]
return menu_item(context, link_route, link_label, subroutes)

aria_current = 'aria-current="page"' if current_route in routes else ""
return nav_link(link_route, link_label, aria_current)

@register.simple_tag(takes_context=True)
def faq_menu(context):
"""Generate html for the "Faq" collapsible menu."""

link_route = "faq"
link_label = "Questions fréquentes"
subroutes = [
"faq_loi_sur_leau",
"faq_natura_2000",
"faq_eval_env",
]
return menu_item(context, link_route, link_label, subroutes)


@register.simple_tag(takes_context=True)
Expand Down
38 changes: 35 additions & 3 deletions envergo/pages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.views.generic import RedirectView, TemplateView

from envergo.geodata.views import ParcelsExport
from envergo.pages.views import LegalMentionsView, Outlinks
from envergo.pages.views import LegalMentionsView, NewsFeed, NewsView, Outlinks

urlpatterns = [
path(
Expand All @@ -25,8 +25,40 @@
),
path(
_("faq/"),
TemplateView.as_view(template_name="pages/faq.html"),
name="faq",
include(
[
path(
"",
TemplateView.as_view(template_name="pages/faq/index.html"),
name="faq",
),
path(
_("loi-sur-leau/"),
TemplateView.as_view(template_name="pages/faq/loi_sur_leau.html"),
name="faq_loi_sur_leau",
),
path(
_("natura-2000/"),
TemplateView.as_view(template_name="pages/faq/natura_2000.html"),
name="faq_natura_2000",
),
path(
_("eval-env/"),
TemplateView.as_view(template_name="pages/faq/eval_env.html"),
name="faq_eval_env",
),
path(
_("envergo-news/"),
NewsView.as_view(),
name="faq_news",
),
path(
_("envergo-news/feed/"),
NewsFeed(),
name="news_feed",
),
]
),
),
path(
_("map/"),
Expand Down
36 changes: 35 additions & 1 deletion envergo/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import requests
from django.conf import settings
from django.contrib import messages
from django.views.generic import TemplateView
from django.contrib.syndication.views import Feed
from django.urls import reverse
from django.utils.formats import date_format
from django.utils.html import mark_safe
from django.views.generic import ListView, TemplateView

from envergo.pages.models import NewsItem


class HomeView(TemplateView):
Expand Down Expand Up @@ -60,3 +66,31 @@ def check_links(self):
links.append({"label": label, "url": url, "status": req.status_code})

return links


class NewsView(ListView):
template_name = "pages/faq/news.html"
context_object_name = "news_items"

def get_queryset(self):
return NewsItem.objects.all().order_by("-created_at")


class NewsFeed(Feed):
title = "Les actualités d'EnvErgo"
link = "/foire-aux-questions/envergo-news/feed/"
description = "Les nouveautés du projet EnvErgo"

def items(self):
return NewsItem.objects.order_by("-created_at")[:10]

def item_title(self, item):
return date_format(item.created_at, "DATE_FORMAT")

def item_description(self, item):
return mark_safe(item.content_html)

def item_link(self, item):
base_url = reverse("faq_news")
item_url = f"{base_url}#news-item-{item.id}"
return item_url
42 changes: 23 additions & 19 deletions envergo/static/sass/project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ html.nojs .js {
display: none !important;
}

/**
* Useful components
*/
.alert-debug {
background-color: $white;
border-color: $mint-green;
Expand All @@ -27,6 +30,22 @@ html.nojs .js {
color: $red;
}

/**
* Update some margins for paragraphs and lists
*/
article {
--li-bottom: .5rem;
--text-spacing: 0 0 1rem;

ul {
margin-bottom: 1rem;
}

li p {
margin-bottom: .5rem;
}
}

.probability {
text-transform: uppercase;
font-weight: bold;
Expand Down Expand Up @@ -240,17 +259,6 @@ nav#evaluation-summary {

section.regulation {

--li-bottom: .5rem;
--text-spacing: 0 0 1rem;

ul {
margin-bottom: 1rem;
}

li p {
margin-bottom: .5rem;
}

h2 {
display: flex;
align-items: center;
Expand Down Expand Up @@ -679,14 +687,10 @@ button[data-fr-js-collapse-button="true"] {
}

// Don't force a 16:9 ratio on images
.fr-content-media__img::before {
content: none;
}

.fr-content-media__img img,
.fr-content-media__img svg {
position: unset;
object-fit: unset;
.fr-content-media {
.fr-responsive-img {
aspect-ratio: unset;
}
}

// Remove double margins below images with captions
Expand Down
2 changes: 1 addition & 1 deletion envergo/templates/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<li class="fr-nav__item">{% evalreq_menu %}</li>

<li class="fr-nav__item">{% menu_item 'faq' "Questions fréquentes" %}</li>
<li class="fr-nav__item">{% faq_menu %}</li>

<li class="fr-nav__item">{% evaluation_menu %}</li>
</ul>
Expand Down
5 changes: 5 additions & 0 deletions envergo/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
href="{% static '@gouvfr/dsfr/dist/favicon/favicon.ico' %}"
type="image/x-icon">

<link rel="alternate"
type="application/rss+xml"
title="Les actualités EnvErgo"
href="https://envergo.beta.gouv.fr{% url 'news_feed' %}" />

{% block css %}
{% compress css %}
<link href="{% static '@gouvfr/dsfr/dist/dsfr/dsfr.css' %}"
Expand Down
2 changes: 1 addition & 1 deletion envergo/templates/evaluations/_learn_more.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h2>Pour en savoir plus…</h2>

<p>
Consultez notre <a href="{% url 'faq' %}">page d'information sur la Loi sur l'eau</a>
Consultez notre <a href="{% url 'faq' %}">page d'information</a>
ou <a href="{% url 'contact_us' %}">contactez l'équipe EnvErgo</a>.
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion envergo/templates/moulinette/base_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2>Saisissez les caractéristiques de votre projet</h2>
<h2>Pour en savoir plus…</h2>

<p>
Consultez notre <a href="{% url 'faq' %}">page d'information sur la Loi sur l'eau</a>
Consultez notre <a href="{% url 'faq' %}">page d'information</a>
ou <a href="{% url 'contact_us' %}">contactez l'équipe EnvErgo</a>.
</p>
{% endblock %}
Expand Down
4 changes: 4 additions & 0 deletions envergo/templates/moulinette/eval_body_action_requise.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ <h3 class="fr-h4">Comment l'instruction du dossier Loi sur l'eau se déroule-t-e
Le délai d'instruction d'un dossier de déclaration Loi sur l'eau est de 2 mois, extensible en cas de demande de compléments.
</p>

<p>
Consultez <a href="{% url 'faq_loi_sur_leau' %}#accordion-instruction">notre article décrivant l'instruction Loi sur l'eau</a>.
</p>

<p>
Consultez <a href="{% url 'faq' %}#accordion-instruction">notre article décrivant l'instruction Loi sur l'eau</a>.
</p>
Expand Down
Loading

0 comments on commit e6f29d3

Please sign in to comment.