Commit db45adf0 authored by Hypsug0's avatar Hypsug0
Browse files

Formatting with black

parent fc3d8c6b
......@@ -8,7 +8,7 @@ from django.template.defaultfilters import slugify
def version():
"""Return SITE VERSION to frontend"""
with open("VERSION", "r") as VERSION:
version = VERSION.read().replace("\n", "n")
version = VERSION.read().replace("\n", "")
return version
......
......@@ -45,9 +45,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,7 +57,9 @@ 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,
......@@ -115,9 +117,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:
......@@ -141,7 +143,9 @@ 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,
......@@ -150,7 +154,9 @@ 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,
......@@ -165,8 +171,12 @@ 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,
......@@ -190,7 +200,9 @@ 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,
......@@ -271,7 +283,9 @@ 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,
......@@ -396,7 +410,9 @@ 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")
......@@ -740,11 +756,19 @@ 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")
)
......@@ -788,11 +812,15 @@ 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>."),
......@@ -829,7 +857,9 @@ 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,
......@@ -878,14 +908,18 @@ 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,
)
......@@ -905,7 +939,9 @@ 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")
)
......@@ -998,15 +1034,21 @@ 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
)
......@@ -1066,7 +1108,9 @@ 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é")
)
......@@ -1077,7 +1121,9 @@ 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é")
)
......@@ -1115,18 +1161,36 @@ 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,
......@@ -1259,7 +1323,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()
......@@ -8,7 +8,10 @@ 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.mixins import (
LargeGeoJsonPageNumberPagination,
SightingFilteredListWithPermissions,
)
from sights.models import CountDetail, Sighting
from sights.observation.serializers import EditSightingSerializer, SightingSerializer
......@@ -17,9 +20,7 @@ logger = logging.getLogger(__name__)
class GeoJSONSighting(
LoginRequiredMixin,
SightingFilteredListWithPermissions,
generics.ListAPIView,
LoginRequiredMixin, SightingFilteredListWithPermissions, generics.ListAPIView,
):
serializer_class = SightingSerializer
pagination_class = LargeGeoJsonPageNumberPagination
......
......@@ -91,9 +91,10 @@ class SightingSerializer(serializers.GeoFeatureModelSerializer):
class EditSightingSerializer(serializers.ModelSerializer):
"""Sighting serializer for editing data (insert/update) from sighting and count details model"""
"""Sighting serializer for editing data (insert/update)
from sighting and count details model"""
# countdetail_sighting = CountDetailSerializer(many=True)
countdetail_sighting = CountDetailSerializer(many=True)
class Meta:
model = Sighting
......@@ -110,5 +111,13 @@ class EditSightingSerializer(serializers.ModelSerializer):
)
def get_countdetail_sighting(self, sighting):
"""Retrieve all child count details
Args:
sighting (Sighting): Sighting
Returns:
list: A list of child count details
"""
countdetails = CountDetail.objects.filter(sighting=sighting.id_sighting).all()
return countdetails
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