Commit a5ab5082 authored by Hypsug0's avatar Hypsug0
Browse files

some code cleanup

parent 71b6e79f
......@@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _
from leaflet.forms.widgets import LeafletWidget
from core.forms import DangerAccordionGroup, InfoAccordionGroup, PrimaryAccordionGroup
from dicts.models import CountPrecision, CountUnit, LinkType, Method, TypeDevice
from dicts.models import CountPrecision, CountUnit, Method, TypeDevice
from management.models import Transmitter
from .models import (
......@@ -826,7 +826,7 @@ class SessionForm(forms.ModelForm):
widgets = {
"id_session": forms.HiddenInput(),
"date_end": forms.DateInput(),
"date_end": forms.DateInput(),
"date_start": forms.DateInput(),
"main_observer": autocomplete.ModelSelect2(url="api:all_user_autocomplete"),
"other_observer": autocomplete.ModelSelect2Multiple(url="api:all_user_autocomplete"),
"place": autocomplete.ModelSelect2(url="api:place_autocomplete"),
......@@ -1115,8 +1115,8 @@ class SightingForm(forms.ModelForm):
}
def __init__(self, *args, **kwargs):
main_observer = kwargs.pop("main_observer", None)
other_observer = kwargs.pop("other_observer", None)
# main_observer = kwargs.pop("main_observer", None)
# other_observer = kwargs.pop("other_observer", None)
session_id = kwargs.pop("session_id", None)
contact = kwargs.pop("contact", None)
if session_id:
......
......@@ -4,7 +4,6 @@ import os.path
import uuid
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.gis.db import models as gismodels
from django.contrib.gis.db.models import Union
from django.contrib.gis.geos import GEOSGeometry
......@@ -20,7 +19,42 @@ from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from core.functions import get_sight_period
from dicts.models import *
from dicts.models import (
Age,
BiomChinspot,
BiomDent,
BiomEpiphyse,
BiomEpipidyme,
BiomGestation,
BiomGlandCoul,
BiomGlandTaille,
BiomMamelle,
BiomTesticule,
BiomTuniqVag,
BuildCover,
Contact,
CountPrecision,
CountUnit,
GiteBatAccess,
Interest,
MetaPlaceType,
Method,
PlaceManagementAction,
PlacePrecision,
PropertyDomain,
Sex,
Specie,
TreeCircumstance,
TreeContext,
TreeForestStands,
TreeGiteOrigin,
TreeGitePlace,
TreeGiteType,
TreeHealth,
TreeSpecies,
TypeDevice,
TypePlace,
)
from geodata.models import LandCover, Municipality, Territory
from management.models import Study, Transmitter
......@@ -45,9 +79,9 @@ def update_metaplace_autogeom(id_metaplace):
place_geom = places.first().geom
metaplace.geom = place_geom.buffer(0.0005)
elif len(places) > 1:
places_collection = Place.objects.filter(
metaplace_id=id_metaplace
).aggregate(union=Union("geom"))
places_collection = Place.objects.filter(metaplace_id=id_metaplace).aggregate(
union=Union("geom")
)
if len(places) == 2:
metaplace.geom = GEOSGeometry(places_collection["union"]).envelope
elif len(places) > 2:
......@@ -57,9 +91,7 @@ def update_metaplace_autogeom(id_metaplace):
class MetaPlace(gismodels.Model):
id_metaplace = models.AutoField(primary_key=True, db_index=True)
name = models.CharField(
max_length=255, db_index=True, verbose_name=_("nom du métasite")
)
name = models.CharField(max_length=255, db_index=True, verbose_name=_("nom du métasite"))
type = models.ForeignKey(
MetaPlaceType,
db_index=True,
......@@ -80,7 +112,8 @@ class MetaPlace(gismodels.Model):
verbose_name="Géométrie automatiquement générée",
default=True,
help_text=_(
"La géométrie sera automatiquement générée selon les localités associés au métasite. Décocher l'option pour dessiner un polygone à main levée."
"La géométrie sera automatiquement générée selon les localités associés au métasite."
" Décocher l'option pour dessiner un polygone à main levée."
),
)
extra_data = JSONField(blank=True, null=True)
......@@ -117,9 +150,9 @@ class MetaPlace(gismodels.Model):
place_geom = places.first().geom
self.geom = place_geom.buffer(0.0005)
elif len(places) > 1:
places_collection = Place.objects.filter(
metaplace_id=id_metaplace
).aggregate(union=Union("geom"))
places_collection = Place.objects.filter(metaplace_id=id_metaplace).aggregate(
union=Union("geom")
)
if len(places) == 2:
self.geom = GEOSGeometry(places_collection["union"]).envelope
elif len(places) > 2:
......@@ -143,9 +176,7 @@ class MetaPlace(gismodels.Model):
class Place(models.Model):
id_place = models.AutoField(primary_key=True, db_index=True)
uuid = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
name = models.CharField(
max_length=255, db_index=True, verbose_name=_("nom du lieu")
)
name = models.CharField(max_length=255, db_index=True, verbose_name=_("nom du lieu"))
metaplace = models.ForeignKey(
MetaPlace,
db_index=True,
......@@ -154,9 +185,7 @@ class Place(models.Model):
verbose_name=_("Métasite associé"),
on_delete=models.SET_NULL,
)
is_hidden = models.BooleanField(
db_index=True, default=False, verbose_name="Site sensible"
)
is_hidden = models.BooleanField(db_index=True, default=False, verbose_name="Site sensible")
authorized_user = models.ManyToManyField(
settings.AUTH_USER_MODEL,
blank=True,
......@@ -171,12 +200,8 @@ class Place(models.Model):
verbose_name=_("Type de gîte"),
on_delete=models.SET_NULL,
)
is_gite = models.BooleanField(
db_index=True, verbose_name="Est un gîte", default=False
)
is_managed = models.BooleanField(
db_index=True, default=False, verbose_name="Site géré"
)
is_gite = models.BooleanField(db_index=True, verbose_name="Est un gîte", default=False)
is_managed = models.BooleanField(db_index=True, default=False, verbose_name="Site géré")
proprietary = models.CharField(
max_length=100,
db_index=True,
......@@ -200,9 +225,7 @@ class Place(models.Model):
photo_file = models.ImageField(
upload_to="photo/", blank=True, null=True, verbose_name="Photo de la localité"
)
habitat = models.CharField(
max_length=255, blank=True, null=True, verbose_name=_("Habitat")
)
habitat = models.CharField(max_length=255, blank=True, null=True, verbose_name=_("Habitat"))
altitude = models.PositiveIntegerField(
blank=True,
null=True,
......@@ -283,9 +306,7 @@ class Place(models.Model):
verbose_name="Localisation géographique",
)
timestamp_create = models.DateTimeField(auto_now_add=True, editable=False)
timestamp_update = models.DateTimeField(
auto_now=True, db_index=True, editable=False
)
timestamp_update = models.DateTimeField(auto_now=True, db_index=True, editable=False)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
null=True,
......@@ -360,7 +381,8 @@ class PlaceManagement(models.Model):
null=True,
verbose_name=_("Fichier"),
help_text=_(
"Si vous voulez charger plusieurs fichiers, créez une archive avec un logiciel de compression comme 7zip"
"Si vous voulez charger plusieurs fichiers, créez une archive avec un logiciel de "
"compression comme 7zip"
),
)
bdsource = models.CharField(max_length=100, blank=True, null=True)
......@@ -410,9 +432,7 @@ class Bridge(models.Model):
on_delete=models.SET_NULL,
)
renovated = models.NullBooleanField(verbose_name="Rénové")
renovated_date = models.DateField(
null=True, blank=True, verbose_name="Date de rénovation"
)
renovated_date = models.DateField(null=True, blank=True, verbose_name="Date de rénovation")
joint = models.NullBooleanField(verbose_name="Joints")
rift = models.NullBooleanField(verbose_name="Fissures")
expansion = models.NullBooleanField(verbose_name="Joints de dilatations")
......@@ -756,19 +776,11 @@ class Cave(models.Model):
verbose_name="Intérêt pour les chiros",
on_delete=models.SET_NULL,
)
length = models.PositiveIntegerField(
blank=True, null=True, verbose_name="Développement"
)
altdiff = models.IntegerField(
blank=True, null=True, verbose_name="Dénivellé vers la cavité"
)
n_entry = models.PositiveIntegerField(
blank=True, null=True, verbose_name="Nombre d" "entrées"
)
length = models.PositiveIntegerField(blank=True, null=True, verbose_name="Développement")
altdiff = models.IntegerField(blank=True, null=True, verbose_name="Dénivellé vers la cavité")
n_entry = models.PositiveIntegerField(blank=True, null=True, verbose_name="Nombre d" "entrées")
equip_req = models.NullBooleanField(verbose_name="Equipement requis?")
equipment = models.TextField(
blank=True, null=True, verbose_name=_("Equipement nécessaire")
)
equipment = models.TextField(blank=True, null=True, verbose_name=_("Equipement nécessaire"))
access_walk_duration = models.TimeField(
blank=True, null=True, verbose_name=_("Durée de la marche d'accès")
)
......@@ -812,15 +824,11 @@ class Cave(models.Model):
class Session(models.Model):
id_session = models.AutoField(primary_key=True)
uuid = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
name = models.CharField(
max_length=150, blank=True, verbose_name="Intitulé de la session"
)
name = models.CharField(max_length=150, blank=True, verbose_name="Intitulé de la session")
contact = models.ForeignKey(
Contact, models.DO_NOTHING, default=10, verbose_name=_("Type de contact")
)
place = models.ForeignKey(
Place, on_delete=models.CASCADE, verbose_name=_("Localité associée")
)
place = models.ForeignKey(Place, on_delete=models.CASCADE, verbose_name=_("Localité associée"))
date_start = models.DateField(
verbose_name=_("Date de début"),
help_text=_("Format de date: <em>01/01/2017</em>."),
......@@ -857,9 +865,7 @@ class Session(models.Model):
other_observer = models.ManyToManyField(
settings.AUTH_USER_MODEL, blank=True, related_name="otherobs"
)
is_confidential = models.BooleanField(
default=False, verbose_name=_("Données confidentielles")
)
is_confidential = models.BooleanField(default=False, verbose_name=_("Données confidentielles"))
study = models.ForeignKey(
Study,
models.DO_NOTHING,
......@@ -908,18 +914,14 @@ class Session(models.Model):
def __str__(self):
return "%s ∙ %s ∙ %s" % (
self.place,
datetime.date(
self.date_start.year, self.date_start.month, self.date_start.day
),
datetime.date(self.date_start.year, self.date_start.month, self.date_start.day),
self.contact,
)
def save(self, *args, **kwargs):
self.name = "loc%s %s %s %s" % (
self.place_id,
datetime.date(
self.date_start.year, self.date_start.month, self.date_start.day
),
datetime.date(self.date_start.year, self.date_start.month, self.date_start.day),
self.contact.code,
self.main_observer.username,
)
......@@ -939,9 +941,7 @@ class SessionLink(models.Model):
type_link = models.ForeignKey(
"dicts.LinkType", on_delete=models.DO_NOTHING, verbose_name=_("Type de lien")
)
link = models.URLField(
null=False, verbose_name=_("Hyperlien"), help_text=_("http(s)://...")
)
link = models.URLField(null=False, verbose_name=_("Hyperlien"), help_text=_("http(s)://..."))
comment = models.CharField(
max_length=500, null=True, blank=True, verbose_name=_("Commentaire")
)
......@@ -1034,21 +1034,15 @@ class Sighting(models.Model):
class Device(models.Model):
id_device = models.AutoField(primary_key=True)
session = models.ForeignKey(
Session, on_delete=models.CASCADE, verbose_name="Session associée"
)
session = models.ForeignKey(Session, on_delete=models.CASCADE, verbose_name="Session associée")
ref = models.CharField(
max_length=30,
verbose_name=_("Référence du dispositif pour la session"),
default="nd",
)
type = models.ForeignKey(TypeDevice, on_delete=models.CASCADE)
height = models.FloatField(
blank=True, null=True, default=None, verbose_name=_("Hauteur")
)
width = models.FloatField(
blank=True, null=True, default=None, verbose_name=_("Largeur")
)
height = models.FloatField(blank=True, null=True, default=None, verbose_name=_("Hauteur"))
width = models.FloatField(blank=True, null=True, default=None, verbose_name=_("Largeur"))
context = models.CharField(
max_length=150, blank=True, null=True, verbose_name=_("Contexte"), default=None
)
......@@ -1108,9 +1102,7 @@ class CountDetail(models.Model):
blank=True,
null=True,
)
sex = models.ForeignKey(
Sex, models.DO_NOTHING, blank=True, null=True, verbose_name=_("Sexe")
)
sex = models.ForeignKey(Sex, models.DO_NOTHING, blank=True, null=True, verbose_name=_("Sexe"))
age = models.ForeignKey(
Age, models.DO_NOTHING, blank=True, null=True, verbose_name=_("Age estimé")
)
......@@ -1121,9 +1113,7 @@ class CountDetail(models.Model):
null=True,
verbose_name=_("Précision du comptage"),
)
count = models.PositiveIntegerField(
blank=True, null=True, verbose_name=_("Effectif")
)
count = models.PositiveIntegerField(blank=True, null=True, verbose_name=_("Effectif"))
unit = models.ForeignKey(
CountUnit, on_delete=DO_NOTHING, blank=True, null=True, verbose_name=_("Unité")
)
......@@ -1161,36 +1151,18 @@ class CountDetail(models.Model):
verbose_name=_("Emetteur de télémétrie"),
on_delete=models.SET_NULL,
)
ab = models.FloatField(
blank=True, null=True, verbose_name=_("AB"), help_text=_("en mm")
)
d5 = models.FloatField(
blank=True, null=True, verbose_name=_("D5"), help_text=_("en mm")
)
d3 = models.FloatField(
blank=True, null=True, verbose_name=_("D3"), help_text=_("en mm")
)
pouce = models.FloatField(
blank=True, null=True, verbose_name=_("Pouce"), help_text=_("en mm")
)
queue = models.FloatField(
blank=True, null=True, verbose_name=_("Queue"), help_text=_("en mm")
)
tibia = models.FloatField(
blank=True, null=True, verbose_name=_("Tibia"), help_text=_("en mm")
)
pied = models.FloatField(
blank=True, null=True, verbose_name=_("Pied"), help_text=_("en mm")
)
cm3 = models.FloatField(
blank=True, null=True, verbose_name=_("CM3"), help_text=_("en mm")
)
ab = models.FloatField(blank=True, null=True, verbose_name=_("AB"), help_text=_("en mm"))
d5 = models.FloatField(blank=True, null=True, verbose_name=_("D5"), help_text=_("en mm"))
d3 = models.FloatField(blank=True, null=True, verbose_name=_("D3"), help_text=_("en mm"))
pouce = models.FloatField(blank=True, null=True, verbose_name=_("Pouce"), help_text=_("en mm"))
queue = models.FloatField(blank=True, null=True, verbose_name=_("Queue"), help_text=_("en mm"))
tibia = models.FloatField(blank=True, null=True, verbose_name=_("Tibia"), help_text=_("en mm"))
pied = models.FloatField(blank=True, null=True, verbose_name=_("Pied"), help_text=_("en mm"))
cm3 = models.FloatField(blank=True, null=True, verbose_name=_("CM3"), help_text=_("en mm"))
tragus = models.FloatField(
blank=True, null=True, verbose_name=_("Tragus"), help_text=_("en mm")
)
poids = models.FloatField(
blank=True, null=True, verbose_name=_("Poids"), help_text=_("en g")
)
poids = models.FloatField(blank=True, null=True, verbose_name=_("Poids"), help_text=_("en g"))
testicule = models.ForeignKey(
BiomTesticule,
blank=True,
......@@ -1323,7 +1295,7 @@ def sighting_total_count(sender, instance, **kwargs):
contact = Sighting.objects.get(id_sighting=sighting_id).session.contact.code
sighting = Sighting.objects.get(id_sighting=sighting_id)
if contact != "du":
sighting.total_count = CountDetail.objects.filter(
sighting_id=sighting_id
).aggregate(Sum("count"))["count__sum"]
sighting.total_count = CountDetail.objects.filter(sighting_id=sighting_id).aggregate(
Sum("count")
)["count__sum"]
sighting.save()
......@@ -3,16 +3,14 @@ import logging
from django.contrib.auth.mixins import LoginRequiredMixin
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
# from rest_framework.permissions import IsAuthenticated
# from rest_framework.response import Response
# from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from sights.mixins import (
LargeGeoJsonPageNumberPagination,
SightingFilteredListWithPermissions,
)
from sights.models import CountDetail, Sighting
from sights.mixins import LargeGeoJsonPageNumberPagination, SightingFilteredListWithPermissions
from sights.models import Sighting
from sights.observation.serializers import EditSightingSerializer, SightingSerializer
# Get an instance of a logger
......@@ -20,7 +18,9 @@ logger = logging.getLogger(__name__)
class GeoJSONSighting(
LoginRequiredMixin, SightingFilteredListWithPermissions, generics.ListAPIView,
LoginRequiredMixin,
SightingFilteredListWithPermissions,
generics.ListAPIView,
):
serializer_class = SightingSerializer
pagination_class = LargeGeoJsonPageNumberPagination
......
from rest_framework.serializers import SerializerMethodField
# from rest_framework.serializers import SerializerMethodField
from rest_framework_gis import serializers
from accounts.models import Profile
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment