Skip to content

Commit

Permalink
fix(project): remove unused fields and add alpha validator
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisig committed Oct 1, 2024
1 parent e30968b commit 85a3fd0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 234 deletions.
1 change: 0 additions & 1 deletion project/models/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def create_from_public_key(
user=user if user and user.is_authenticated else None,
)
project._change_reason = ProjectChangeReason.CREATED_FROM_PUBLIC_KEY
project.set_success(save=True)

trigger_async_tasks(project, public_key)

Expand Down
66 changes: 4 additions & 62 deletions project/models/project_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import collections
import logging
import traceback
from decimal import Decimal
from typing import Dict, List, Literal

Expand All @@ -16,7 +15,6 @@
from django.db.models import Case, Count, DecimalField, F, Q, QuerySet, Sum, Value, When
from django.db.models.functions import Cast, Coalesce, Concat
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from simple_history.models import HistoricalRecords

Expand Down Expand Up @@ -44,6 +42,7 @@
from public_data.models.gpu import ArtifAreaZoneUrba, ZoneUrba
from public_data.models.mixins import DataColorationMixin
from utils.db import cast_sum_area
from utils.validators import is_alpha_validator

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,20 +73,7 @@ class Status(models.TextChoices):
blank=True,
null=True,
)
name = models.CharField("Nom", max_length=100)
# fields to track the shape files importation into the database
import_error = models.TextField(
"Message d'erreur traitement emprise",
null=True,
blank=True,
)
import_date = models.DateTimeField("Date et heure d'import", null=True, blank=True)
import_status = models.CharField(
"Statut import",
max_length=10,
choices=Status.choices,
default=Status.MISSING,
)
name = models.CharField("Nom", max_length=100, validators=[is_alpha_validator])

@cached_property
def combined_emprise(self) -> MultiPolygon:
Expand All @@ -101,23 +87,6 @@ def combined_emprise(self) -> MultiPolygon:
def __str__(self):
return self.name

def set_success(self, save=True):
self.import_status = self.Status.SUCCESS
self.import_date = timezone.now()
self.import_error = None
if save:
self.save_without_historical_record()

def set_failed(self, save=True, trace=None):
self.import_status = self.Status.FAILED
self.import_date = timezone.now()
if trace:
self.import_error = trace
else:
self.import_error = traceback.format_exc()
if save:
self.save_without_historical_record()

class Meta:
abstract = True

Expand Down Expand Up @@ -318,7 +287,8 @@ def get_public_key(self) -> str:
max_length=250,
blank=True,
null=True,
help_text=("C'est le nom qui est utilisé pour désigner votre territoire, notamment " "dans le rapport word."),
help_text="C'est le nom qui est utilisé pour désigner votre territoire, notamment dans le rapport word.",
validators=[is_alpha_validator],
)

cover_image = models.ImageField(
Expand Down Expand Up @@ -658,20 +628,6 @@ def get_look_a_like(self):
self.save(update_fields=["look_a_like"])
return sorted(lands, key=lambda x: x.name)

# calculated fields
# Following field contains calculated dict :
# {
# '2015': { # millésime
# 'couverture': { # covering type
# 'cs1.1.1': 123, # code and area in km square
# 'cs1.1.2': 23,
# },
# 'usage': { ... }, # same as couverture
# },
# '2018': { ... }, # same as 2015
# }
couverture_usage = models.JSONField(blank=True, null=True)

def get_cerema_cities(self, group_name=None):
if not group_name:
code_insee = self.cities.all().values_list("insee", flat=True)
Expand Down Expand Up @@ -737,8 +693,6 @@ def get_bilan_conso_time_scoped(self):
analyze_start_data and analyze_end_date)
Evaluation is based on city consumption, not geo work."""
qs = self.get_cerema_cities()
# if not qs.exists():
# return 0
fields = Cerema.get_art_field(self.analyse_start_date, self.analyse_end_date)
sum_function = sum([F(f) for f in fields])
qs = qs.annotate(line_sum=sum_function)
Expand Down Expand Up @@ -840,17 +794,6 @@ def get_look_a_like_pop_change_per_year(
def get_absolute_url(self):
return reverse("project:detail", kwargs={"pk": self.pk})

def reset(self, save=False):
"""Remove everything from project dependencies
..TODO:: overload delete to remove files"""
self.emprise_set.all().delete()
self.import_status = BaseProject.Status.MISSING
self.import_date = None
self.import_error = None
self.couverture_usage = None
if save:
self.save()

def get_artif_area(self):
"""Return artificial surface total for all city inside diagnostic"""
result = self.cities.all().aggregate(total=Sum("surface_artif"))
Expand Down Expand Up @@ -1014,7 +957,6 @@ def get_bounding_box(self):
return list(result["bbox"])

def get_centroid(self):
# result = self.emprise_set.aggregate(bbox=Extent('mpoly'))
result = self.emprise_set.aggregate(center=Centroid(Union("mpoly")))
return result["center"]

Expand Down
109 changes: 0 additions & 109 deletions public_data/management/commands/create_rnu_diagnostics.py

This file was deleted.

62 changes: 0 additions & 62 deletions public_data/management/commands/create_rnu_packages.py

This file was deleted.

0 comments on commit 85a3fd0

Please sign in to comment.