-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(communications): page nouveautés
feat(communications): render news modal on first device visit feat(communications/admin): AnnouncementCampaign admin and validation fix(AnnouncementCampaignAdminForm): modifying date range feat(communications): render news modal on first device visit feat(communications): implemented a cache for AnnouncementCampaign greatly restricts database usage refactor(CommunicationsConfig): django signals safe to import at module level refactor(communications): model changes requested in feedback refactor(communications): implemented requested cache changes fix: make quality fix(static): delete unused image file refactor(communications): cache changes, added live field feat(communications): render news modal on first device visit feat(communications/admin): AnnouncementCampaign admin and validation fix(AnnouncementCampaignAdminForm): modifying date range feat(communications): render news modal on first device visit feat(communications): implemented a cache for AnnouncementCampaign greatly restricts database usage refactor(communications): implemented requested cache changes feat(communications): news item model fields, admin and form WIP: page nouveautés feat(news.html): styling for news items fix: merge error requirements: merge errors fix: test and code quality feat(news): limit candidate news to relevant news only feat(news.html): collapse icon on monthly news summaries fix: rebase errors feat: links to news page fix: code quality fix(tests): reset_model_sequence for snapshot fix: some ui adjusments refactor(communications/admin.py): change import style refactor(communications/forms.py): relying more on Python core feat(communications/models.py): alt_text field, other model changes refactor(configure_bucket): more concise version of configuration WIP: diverse requested changes feat(news): pagination refactor: enhance testing fix(settings): more specific addition to CSP_IMG_SRC policy fix: tests fix: tests fix: content policy fix: conflict fix: link to news in header content fix: quality fix(news): standardise image height fix(AnnouncementItemForm): restrict user_kind_tags following the spec refactor: requested changes fix: quality error fix: test failure on pipeline refactor: requested changes refactor: consistent naming convention on news fix: rebase mistake minor fixes fix: quality
- Loading branch information
1 parent
d5b4072
commit 6ba18f4
Showing
35 changed files
with
948 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
from django.contrib import admin | ||
|
||
from itou.communications import models | ||
from itou.utils.admin import ItouModelAdmin, ItouTabularInline | ||
from itou.communications.forms import AnnouncementItemForm | ||
from itou.utils.admin import ItouModelAdmin, ItouStackedInline | ||
|
||
|
||
class AnnouncementItemInline(ItouTabularInline): | ||
class AnnouncementItemInline(ItouStackedInline): | ||
model = models.AnnouncementItem | ||
fields = ("priority", "title", "description") | ||
form = AnnouncementItemForm | ||
extra = 0 | ||
|
||
|
||
@admin.register(models.AnnouncementCampaign) | ||
class AnnouncementCampaignAdmin(ItouModelAdmin): | ||
class Media: | ||
css = {"all": ("css/itou-admin.css",)} | ||
|
||
list_display = ("start_date", "end_date", "live") | ||
fields = ("max_items", "start_date", "live") | ||
inlines = (AnnouncementItemInline,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pathlib | ||
import uuid | ||
|
||
from django import forms | ||
|
||
from itou.communications.models import AnnouncementItem | ||
from itou.files.forms import ItouAdminImageInput | ||
from itou.users.enums import UserKind | ||
from itou.utils import constants as global_constants | ||
|
||
|
||
def user_kind_tag_choices(): | ||
valid_choices = [UserKind.JOB_SEEKER, UserKind.PRESCRIBER, UserKind.EMPLOYER] | ||
return [(u.value, u.label) for u in valid_choices] | ||
|
||
|
||
class AnnouncementItemForm(forms.ModelForm): | ||
class Meta: | ||
model = AnnouncementItem | ||
fields = ["priority", "title", "description", "user_kind_tags", "image", "image_alt_text", "link"] | ||
|
||
user_kind_tags = forms.MultipleChoiceField( | ||
required=False, | ||
widget=forms.CheckboxSelectMultiple, | ||
choices=user_kind_tag_choices, | ||
label="Utilisateurs concernés", | ||
) | ||
image = forms.ImageField( | ||
required=False, | ||
widget=ItouAdminImageInput(attrs={"accept": global_constants.SUPPORTED_IMAGE_FILE_TYPES}), | ||
label="Capture d'écran", | ||
) | ||
|
||
def clean_image(self): | ||
image = self.cleaned_data.get("image") | ||
if image: | ||
extension = pathlib.Path(image.name).suffix | ||
image.name = f"{uuid.uuid4()}{extension}" | ||
return image |
78 changes: 78 additions & 0 deletions
78
itou/communications/migrations/0003_alter_announcementitem_options_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Generated by Django 5.0.7 on 2024-07-29 12:26 | ||
|
||
import django.contrib.postgres.fields | ||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import itou.communications.models | ||
import itou.utils.storage.s3 | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("communications", "0002_announcementcampaign_announcementitem_and_more"), | ||
("files", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="announcementitem", | ||
name="image", | ||
field=models.ImageField( | ||
blank=True, | ||
storage=itou.utils.storage.s3.PublicStorage(), | ||
upload_to="news-images/", | ||
verbose_name="capture d'écran", | ||
help_text="1200x600 recommandé", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="announcementitem", | ||
name="image_alt_text", | ||
field=models.TextField( | ||
blank=True, | ||
help_text=( | ||
"la description est importante pour les utilisateurs de lecteurs d'écran," | ||
" et lorsque l'image ne se télécharge pas" | ||
), | ||
verbose_name="description de l'image", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="announcementitem", | ||
name="link", | ||
field=models.URLField( | ||
help_text="URL d'une page où l'utilisateur peut obtenir plus d'informations sur l'article", | ||
blank=True, | ||
verbose_name="lien externe", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="announcementitem", | ||
name="user_kind_tags", | ||
field=django.contrib.postgres.fields.ArrayField( | ||
base_field=models.CharField( | ||
choices=[ | ||
("job_seeker", "candidat"), | ||
("prescriber", "prescripteur"), | ||
("employer", "employeur"), | ||
("labor_inspector", "inspecteur du travail"), | ||
("itou_staff", "administrateur"), | ||
] | ||
), | ||
default=list, | ||
size=None, | ||
verbose_name="utilisateurs concernés", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="announcementitem", | ||
name="image_storage", | ||
field=models.OneToOneField( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
to="files.file", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% extends "layout/base.html" %} | ||
{% load theme_inclusion %} | ||
|
||
{% block title %}Nouveautés {{ block.super }}{% endblock %} | ||
|
||
{% block title_prevstep %} | ||
{% include "layout/previous_step.html" with back_url=back_url only %} | ||
{% endblock %} | ||
|
||
{% block title_content %}<h1>Nouveautés</h1>{% endblock %} | ||
|
||
{% block content %} | ||
<section class="s-section"> | ||
<div class="s-section__container container"> | ||
<ul class="list-group list-group-collapse list-group-flush"> | ||
{% for month_news in news_page %} | ||
<li class="list-group-item list-group-item-action"> | ||
<button class="d-block w-100" | ||
data-bs-toggle="collapse" | ||
data-bs-target="#news-{{ forloop.counter }}" | ||
type="button" | ||
aria-expanded="{% if forloop.counter > 1 %}false{% else %}true{% endif %}" | ||
aria-controls="news-{{ forloop.counter }}"> | ||
<div class="h3 mb-0"> | ||
{{ month_news.start_date|date:"F Y"|capfirst }} | ||
<span class="badge badge-sm bg-emploi-light text-info rounded-pill ms-2">{{ month_news.count_items }}<span class="visually-hidden">article{{ month_news.count_items|pluralize }}"</span></span> | ||
</div> | ||
</button> | ||
<article class="mt-3 collapse{% if forloop.counter == 1 %} show{% endif %}" id="news-{{ forloop.counter }}" aria-controls="news-{{ forloop.counter }}"> | ||
{% for news_item in month_news.items.all %} | ||
<div class="row mb-3"> | ||
<div class="col-12 col-md-4{% if news_item.image %} mb-3{% else %} d-none d-md-inline{% endif %}"> | ||
{% if news_item.image %} | ||
<img src="{{ news_item.image.url }}" | ||
alt="{{ news_item.image_alt_text }}" | ||
{% if not news_item.image_alt_text %}aria-hidden="true"{% endif %} | ||
class="img-fluid img-fitcover img-thumbnail" | ||
height="{{ news_item.image.height }}" | ||
width="{{ news_item.image.width }}" | ||
{% if forloop.counter > 1 %}loading="lazy"{% endif %} /> | ||
{% else %} | ||
<img src="{% static_theme_images 'ico-bicro-important.svg' %}" loading="lazy" alt="" height="240" width="420" class="img-fluid img-fitcover img-thumbnail img-muted" aria-hidden="true" /> | ||
{% endif %} | ||
</div> | ||
<div class="col-12 col-md-8"> | ||
{% if news_item.user_kind_tags %} | ||
<div aria-label="groupes d'utilisateurs concernés"> | ||
{% for tag in news_item.user_kind_labels %} | ||
<span class="tag tag-base bg-info-lighter text-info">{{ tag|upper }}</span> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
<p class="h4 my-2">{{ news_item.title }}</p> | ||
<p>{{ news_item.description|linebreaksbr }}</p> | ||
{% if news_item.link %} | ||
<a href="{{ news_item.link }}" rel="noopener" target="_blank" class="btn-link has-external-link" aria-label="Plus d'informations sur {{ news_item.title }}">En savoir plus</a> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</article> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
{% include "includes/pagination.html" with page=news_page %} | ||
</section> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.