-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
24 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
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)), | ||
], | ||
), | ||
] |
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 |
---|---|---|
|
@@ -894,21 +894,24 @@ def alert_on_blocked_diagnostic(self) -> None: | |
@shared_task(max_retries=5) | ||
def create_zip_departement_rnu_package_one_off(departement_id: str) -> None: | ||
departement = Departement.objects.get(source_id=departement_id) | ||
commune_in_departement_ids_as_string = [ | ||
str(commune_id) for commune_id in departement.commune_set.values_list("id", flat=True) | ||
] | ||
requests_created_by_the_rnu_package_service_account = Request.objects.filter( | ||
email="[email protected]", | ||
project__land_id=departement.pk, | ||
project__land_id__in=commune_in_departement_ids_as_string, | ||
) | ||
|
||
file_name = f"rnu_package_departement_{departement_id}.zip" | ||
|
||
with zipfile.ZipFile(file_name, "a", compression=zipfile.ZIP_DEFLATED) as zipf: | ||
for request in requests_created_by_the_rnu_package_service_account: | ||
if not request.sent_file: | ||
raise ValueError(f"Request {request.id} has no sent file") | ||
|
||
file_name_in_zip = f"{departement_id}_COMM_{request.project.land.official_id}.docx" | ||
zipf.write( | ||
filename=request.sent_file, | ||
arcname=file_name_in_zip, | ||
) | ||
zipf.writestr(file_name_in_zip, request.sent_file.read()) | ||
RNUPackage.objects.create( | ||
departement_official_id=departement.source_id, | ||
file_name=file_name, | ||
file=file_name, | ||
) |
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 |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
class Command(BaseCommand): | ||
help = "create_rnu_diagnostics" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("--departement", type=str, required=True) | ||
|
||
def handle(self, *args, **options): | ||
mondiagartif_user, _ = User.objects.get_or_create( | ||
email="[email protected]", | ||
|
@@ -26,8 +29,11 @@ def handle(self, *args, **options): | |
defaults={"email_checked": timezone.now()}, | ||
) | ||
|
||
projects = [] | ||
|
||
for commune in Commune.objects.filter( | ||
insee__in=[Sudocuh.objects.filter(du_opposable=DocumentUrbanismeChoices.RNU).values("code_insee")] | ||
departement__source_id=options["departement"], | ||
insee__in=[Sudocuh.objects.filter(du_opposable=DocumentUrbanismeChoices.RNU).values("code_insee")], | ||
): | ||
land = Land(public_key=f"COMM_{commune.pk}") | ||
project = Project.objects.create( | ||
|
@@ -58,6 +64,8 @@ def handle(self, *args, **options): | |
async_add_comparison_lands_done=True, | ||
) | ||
|
||
project.cities.add(commune) | ||
|
||
Emprise.objects.create( | ||
mpoly=fix_poly(commune.mpoly), | ||
srid_source=commune.srid_source, | ||
|
@@ -70,7 +78,9 @@ def handle(self, *args, **options): | |
|
||
project.refresh_from_db() | ||
|
||
project = project.add_look_a_like(public_key=similar_lands_public_keys, many=True) | ||
project.add_look_a_like(public_key=similar_lands_public_keys, many=True) | ||
|
||
projects.append(project) | ||
|
||
for project in Project.objects.filter(user=mondiagartif_user): | ||
for project in projects: | ||
trigger_async_tasks_rnu_pakage_one_off(project) |
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