Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions envergo/pages/templatetags/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,21 @@ def querystring(context, *args, **kwargs):
params[key] = value
query_string = params.urlencode() if params else ""
return f"?{query_string}"


@register.inclusion_tag("_truncated_comment.html")
def truncated_comment(text, uid, limit=50):
"""
Display a truncated comment with DSFR-compatible expand/collapse.
"""
if not text:
return {"text": None}

return {
"text": text,
"limit": limit,
"uid": uid,
"is_truncated": len(text) > limit,
"head": text[:limit],
"tail": text[limit:],
}
27 changes: 27 additions & 0 deletions envergo/petitions/migrations/0029_statuslog_resumed_by_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.23 on 2025-12-18 05:27

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),
("petitions", "0028_alter_statuslog_options_and_more"),
]

operations = [
migrations.AddField(
model_name="statuslog",
name="resumed_by",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="resumed_logs",
to=settings.AUTH_USER_MODEL,
verbose_name="Auteur de la reprise de la procédure suite à la réception d'informations complémentaires",
),
),
]
13 changes: 13 additions & 0 deletions envergo/petitions/migrations/0034_merge_20260107_0633.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 4.2.23 on 2026-01-07 05:33

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("petitions", "0029_statuslog_resumed_by_and_more"),
("petitions", "0033_merge_20251211_1513"),
]

operations = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 4.2.23 on 2026-01-07 05:34

from django.db import migrations, models


def fix_missing_resumed_by(apps, schema_editor):
"""Set resumed_by for logs that have info_receipt_date but no resumed_by."""
StatusLog = apps.get_model("petitions", "StatusLog")
User = apps.get_model("users", "User")
qs = StatusLog.objects.filter(
info_receipt_date__isnull=False,
resumed_by__isnull=True,
)
if qs.count() == 0:
return

user = User.objects.get(id=1)
qs.update(resumed_by=user)


class Migration(migrations.Migration):
atomic = False

dependencies = [
("petitions", "0034_merge_20260107_0633"),
]

operations = [
migrations.RemoveConstraint(
model_name="statuslog",
name="receipt_date_data_is_consistent",
),
migrations.RunPython(fix_missing_resumed_by, migrations.RunPython.noop),
migrations.AddConstraint(
model_name="statuslog",
constraint=models.CheckConstraint(
check=models.Q(
models.Q(
("info_receipt_date__isnull", True),
("resumed_by__isnull", True),
),
models.Q(
("info_receipt_date__isnull", False),
("resumed_by__isnull", False),
("suspension_date__isnull", False),
("response_due_date__isnull", False),
),
_connector="OR",
),
name="receipt_date_data_is_consistent",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.2.27 on 2026-01-14 10:35

from django.db import migrations, models

class Migration(migrations.Migration):

dependencies = [
("petitions", "0035_remove_statuslog_receipt_date_data_is_consistent_and_more"),
]

operations = [
migrations.RemoveConstraint(
model_name="statuslog",
name="suspension_data_is_consistent",
),
migrations.RemoveConstraint(
model_name="statuslog",
name="receipt_date_data_is_consistent",
),
migrations.AddField(
model_name="statuslog",
name="type",
field=models.CharField(
choices=[
("status_change", "Changement d'état"),
("suspension", "Demande de compléments"),
("resumption", "Compléments reçus"),
],
default="status_change",
max_length=20,
verbose_name="Type de log",
),
),
migrations.AlterField(
model_name="petitionproject",
name="latest_petitioner_msg",
field=models.DateTimeField(
blank=True,
default=None,
null=True,
verbose_name="Date du dernier message pétitionnaire",
),
),
]
62 changes: 62 additions & 0 deletions envergo/petitions/migrations/0037_split_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generated by Django 4.2.27 on 2026-01-14 10:48
from datetime import datetime, time

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


def split_logs(apps, schema_editor):
StatusLog = apps.get_model("petitions", "StatusLog")
suspended_qs = StatusLog.objects.filter(suspension_date__isnull=False)
for suspended in suspended_qs:
StatusLog.objects.create(
petition_project=suspended.petition_project,
type='suspension',
response_due_date=suspended.response_due_date,
original_due_date=suspended.original_due_date,
created_by=suspended.suspended_by,
update_comment="Suspension de l’instruction, message envoyé au demandeur.",
created_at=timezone.make_aware(
datetime.combine(suspended.suspension_date, time(hour=12)),
timezone.get_current_timezone(),
),
)
suspended.suspension_date = None
suspended.response_due_date = None
suspended.original_due_date = None
suspended.save()

resumed_qs = StatusLog.objects.filter(info_receipt_date__isnull=False)
for resumed in resumed_qs:
interruption_days = 0
if resumed.info_receipt_date and resumed.suspension_date :
interruption_days = resumed.info_receipt_date - resumed.suspension_date
if resumed.original_due_date:
new_due_date = resumed.original_due_date + interruption_days
else:
new_due_date = None

StatusLog.objects.create(
petition_project=resumed.petition_project,
type='resumption',
info_receipt_date=resumed.info_receipt_date,
due_date=new_due_date,
created_by=resumed.resumed_by,
update_comment="Reprise de l’instruction, date d'échéance ajustée.",
created_at=timezone.make_aware(
datetime.combine(resumed.info_receipt_date, time(hour=12)),
timezone.get_current_timezone(),
),
)
resumed.info_receipt_date = None
resumed.save()


class Migration(migrations.Migration):
dependencies = [
("petitions", "0036_remove_statuslog_suspension_data_is_consistent_and_more"),
]

operations = [
migrations.RunPython(split_logs, migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 4.2.27 on 2026-01-14 10:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("petitions", "0037_split_logs"),
]

operations = [
migrations.RemoveField(
model_name="statuslog",
name="resumed_by",
),
migrations.RemoveField(
model_name="statuslog",
name="suspended_by",
),
migrations.RemoveField(
model_name="statuslog",
name="suspension_date",
),
migrations.AddConstraint(
model_name="statuslog",
constraint=models.CheckConstraint(
check=models.Q(
models.Q(
("type", "suspension"), ("response_due_date__isnull", False)
),
models.Q(
("type", "status_change"),
("response_due_date__isnull", True),
("original_due_date__isnull", True),
("info_receipt_date__isnull", True),
),
models.Q(
("type", "resumption"), ("info_receipt_date__isnull", False)
),
_connector="OR",
),
name="suspension_data_is_consistent",
),
),]
Loading