Skip to content

Commit

Permalink
Merge pull request #546 from MTES-MCT/staging
Browse files Browse the repository at this point in the history
MEP 7.4
  • Loading branch information
alexisig authored Jul 20, 2024
2 parents f39a750 + 013a9e4 commit 8fbc3ea
Show file tree
Hide file tree
Showing 27 changed files with 808 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.redis import RedisIntegration

OFFICIAL_VERSION = "7.3"
OFFICIAL_VERSION = "7.4"


root = environ.Path(__file__) - 2 # get root of the project
Expand Down
64 changes: 64 additions & 0 deletions home/templates/home/download.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends "index.html" %}

{% load static %}
{% load sri %}

{% block pagetitle %}Téléchargements{% endblock pagetitle %}

{% block headers %}
{% sri_static "home/css/home.css" %}
{% endblock headers %}

{% block body_class %}home{% endblock body_class %}

<!-- Hide breadcrumbs on home page -->
{% block breadcrumbs %}
{% endblock breadcrumbs %}

{% block content %}
<section class="fr-py-6w">
<div class="fr-container">
<h1>Trames de rapport triennal local des communes au RNU</h1>
<p>
Mon Diagnostic Artificialisation met à disposition des DDT les trames de rapport triennal local par paquets de leurs communes au RNU
</p>
<div class="fr-table fr-table--bordered">
<div class="fr-table__wrapper">
<div class="fr-table__container">
<div class="fr-table__content fr-table--no-scrol">
<table>
<thead>
<tr>
<th scope="col">Département</th>
<th scope="col">Nombre de communes au RNU</th>
<th scope="col">Date de création</th>
<th scope="col">Lien</th>
</tr>
</thead>
<tbody>
{% for package in rnu_packages %}
<tr>
<td>{{ package.departement_official_id }} - {{ package.departement.name }}</td>
<td>{{ package.communes|length }}</td>
<td>{{ package.created_at }}</td>
<td><a target="_blank" rel="noopener noreferrer" href="{% url 'home:download_rnu_package' package.departement.source_id %}">Lien de téléchargement</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>
{% include "home/partials/newsletter_form.html" %}
{% endblock content %}

{% block tagging %}
<script language="javascript" nonce="[NONCE_PLACEHOLDER]">
window.onload = function(event) {
_paq.push(['trackEvent', 'local_report_download_funnel', 'open_home_local_report', 'local_report_home_opened'])
}
</script>
{% endblock tagging %}
3 changes: 2 additions & 1 deletion home/templates/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ <h1 class="fr-mb-0">Mon Diagnostic Artificialisation vous aide à analyser et ma
<div class="fr-notice__body">
<p class="fr-badge fr-badge--new">Nouveau</p>
<p class="fr-text--sm">
Exportez une trame pour votre rapport triennal local de suivi de l'artificialisation des sols conformément à l'<a href="https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000048470630" rel="noopener external" target="_blank">article L. 2231-1 du code général des collectivités territoriales</a>
Exportez une trame de votre rapport triennal local de suivi de l'artificialisation des sols conformément à l'<a href="https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000048470630" rel="noopener external" target="_blank">article L. 2231-1 du code général des collectivités territoriales</a>.<br>
<strong>Pour les DDT, ces trames sont disponibles en <a href="{% url 'home:downloads' %}">téléchargement par paquets</a> pour les communes au RNU.</strong>
</p>
</div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion home/templates/home/home_rapport_local.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
<h1 class="fr-mb-0">Préparer le rapport triennal local de suivi de l’artificialisation des sols avec Mon Diag Artif</h1>
</div>
<div class="fr-col fr-col-12 fr-col-md-8">
<p class="text-white">Notre équipe travaille en partenariat avec la DGALN à la production automatique d'une trame pré-remplie du rapport triennal local de suivi de l’artificialisation des sols de votre territoire.</p>
<p class="fr-badge fr-badge--new fr-badge--sm text-dark fr-mb-3w">Nouveau</p>
<p class="text-white">Notre équipe travaille en partenariat avec la DGALN à la production automatique d'une trame pré-remplie du rapport triennal local de suivi de l’artificialisation des sols de votre territoire.</p>
<div class="fr-notice fr-notice--info fr-mb-3w rounded">
<div class="fr-container">
<div class="fr-notice__body">
<p class="fr-text--sm">
<strong>Pour les DDT, ces trames sont disponibles en <a href="{% url 'home:downloads' %}">téléchargement par paquets</a> pour les communes au RNU.</strong>
</p>
</div>
</div>
</div>
{% include "project/partials/search.html" %}
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
urlpatterns = [
path("", views.HomeView.as_view(), name="home"),
path("rapport-local", views.HomeRapportLocalView.as_view(), name="home_rapport_local"),
path("telechargements", views.DownloadView.as_view(), name="downloads"),
path("telechargements/rnu-package/<str:departement>", views.download_package_request, name="download_rnu_package"),
path("mentions-legales", views.LegalNoticeView.as_view(), name="cgv"),
path("confidentialité", views.PrivacyView.as_view(), name="privacy"),
path("test", views.TestView.as_view(), name="test"),
Expand Down
32 changes: 30 additions & 2 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import UserPassesTestMixin
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.db.models import F, Value
from django.http import HttpRequest, HttpResponse, HttpResponseGone
from django.shortcuts import redirect
Expand All @@ -12,7 +13,7 @@
from django_app_parameter import app_parameter

from brevo.connectors import Brevo
from project.models import Request
from project.models import Request, RNUPackage, RNUPackageRequest
from users.models import User
from utils.functions import get_url_with_domain
from utils.htmx import HtmxRedirectMixin, StandAloneMixin
Expand All @@ -35,6 +36,33 @@ def get_context_data(self, **kwargs):
return super().get_context_data(**kwargs)


class DownloadView(LoginRequiredMixin, BreadCrumbMixin, TemplateView):
template_name = "home/download.html"

def get_context_data(self, **kwargs):
kwargs |= {
"form": NewsletterForm(),
"rnu_packages": RNUPackage.objects.all().order_by("departement_official_id"),
}
return super().get_context_data(**kwargs)


@login_required
def download_package_request(request: Request, departement: str) -> HttpResponse:
rnu_package = RNUPackage.objects.get(departement_official_id=departement)
user: User = request.user
RNUPackageRequest.objects.create(
user=request.user,
rnu_package=rnu_package,
departement_official_id=rnu_package.departement_official_id,
email=user.email,
requested_at=timezone.now(),
requested_diagnostics_before_package_request=user.request_set.filter(done=True).count(),
account_created_for_package=user.created_today,
)
return redirect(rnu_package.file.url)


class HomeRapportLocalView(BreadCrumbMixin, TemplateView):
template_name = "home/home_rapport_local.html"

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparte",
"version": "7.3",
"version": "7.4",
"private": true,
"scripts": {
"dev": "webpack --watch --mode development",
Expand Down
34 changes: 33 additions & 1 deletion project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from simple_history.admin import SimpleHistoryAdmin

from project import tasks
from project.models import ErrorTracking, Project, Request
from project.models import (
ErrorTracking,
Project,
Request,
RNUPackage,
RNUPackageRequest,
)
from project.models.exceptions import TooOldException


Expand Down Expand Up @@ -243,3 +249,29 @@ def response_change(self, request, obj):
messages.add_message(request, messages.INFO, msg)
return HttpResponseRedirect(".")
return super().response_change(request, obj)


@admin.register(RNUPackage)
class RNUPackageAdmin(admin.ModelAdmin):
model = RNUPackage
list_display = (
"departement_official_id",
"created_at",
"updated_at",
)
search_fields = ("departement_official_id",)
readonly_fields = (
"created_at",
"updated_at",
)


@admin.register(RNUPackageRequest)
class RNUPackageRequestAdmin(admin.ModelAdmin):
model = RNUPackageRequest
list_display = (
"user",
"rnu_package",
"departement_official_id",
)
search_fields = ("email",)
22 changes: 22 additions & 0 deletions project/migrations/0084_rnupackage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.13 on 2024-07-14 15:54

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("project", "0083_alter_historicalrequest_organism_and_more"),
]

operations = [
migrations.CreateModel(
name="RNUPackage",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("file", models.FileField(upload_to="rnu_packages/")),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("departement_official_id", models.CharField(max_length=10)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.13 on 2024-07-16 07:49

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("project", "0084_rnupackage"),
]

operations = [
migrations.AlterField(
model_name="rnupackage",
name="departement_official_id",
field=models.CharField(max_length=10, unique=True),
),
]
18 changes: 18 additions & 0 deletions project/migrations/0086_rnupackage_app_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.13 on 2024-07-16 08:00

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("project", "0085_alter_rnupackage_departement_official_id"),
]

operations = [
migrations.AddField(
model_name="rnupackage",
name="app_version",
field=models.CharField(default="", max_length=10),
preserve_default=False,
),
]
17 changes: 17 additions & 0 deletions project/migrations/0087_alter_rnupackage_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.13 on 2024-07-16 08:26

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("project", "0086_rnupackage_app_version"),
]

operations = [
migrations.AlterField(
model_name="rnupackage",
name="file",
field=models.FileField(upload_to="rnu_packages"),
),
]
17 changes: 17 additions & 0 deletions project/migrations/0088_alter_rnupackage_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.13 on 2024-07-16 08:34

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("project", "0087_alter_rnupackage_file"),
]

operations = [
migrations.AlterField(
model_name="rnupackage",
name="file",
field=models.FileField(blank=True, null=True, upload_to="rnu_packages"),
),
]
38 changes: 38 additions & 0 deletions project/migrations/0089_rnupackagerequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.13 on 2024-07-18 12:14

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("project", "0088_alter_rnupackage_file"),
]

operations = [
migrations.CreateModel(
name="RNUPackageRequest",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("departement_official_id", models.CharField(max_length=10)),
("email", models.EmailField(max_length=254)),
("requested_at", models.DateTimeField(auto_now_add=True)),
("requested_diagnostics_before_package_request", models.IntegerField()),
("account_created_for_package", models.BooleanField()),
(
"rnu_package",
models.ForeignKey(
null=True, on_delete=django.db.models.deletion.SET_NULL, to="project.rnupackage"
),
),
(
"user",
models.ForeignKey(
null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL
),
),
],
),
]
27 changes: 27 additions & 0 deletions project/models/RNUPackage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.db import models
from django.utils.functional import cached_property

from public_data.models import Departement
from public_data.models.sudocuh import DocumentUrbanismeChoices, Sudocuh


class RNUPackage(models.Model):
file = models.FileField(upload_to="rnu_packages", blank=True, null=True)
app_version = models.CharField(max_length=10)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
departement_official_id = models.CharField(
max_length=10,
unique=True,
)

@cached_property
def departement(self):
return Departement.objects.get(source_id=self.departement_official_id)

@cached_property
def communes(self):
sudocuh = Sudocuh.objects.filter(du_opposable=DocumentUrbanismeChoices.RNU)
return self.departement.commune_set.filter(
insee__in=sudocuh.values("code_insee"),
)
Loading

0 comments on commit 8fbc3ea

Please sign in to comment.