Commit 184ae087 authored by Hypsug0's avatar Hypsug0
Browse files

add links

parent 67f1fe9d
from django.db import models
from django.utils.translation import ugettext_lazy as _
# Create your models here.
class TypeLink(models.Model):
id_type_link = models.AutoField(primary_key=True, db_index=True)
label = models.CharField(
verbose_name=_("Type de lien"), max_length=255, db_index=True, unique=True, null=False
)
desc = models.TextField(verbose_name=_("Description"), null=True, blank=True)
class Links(models.Model):
id_link = models.AutoField(primary_key=True, db_index=True)
link = models.URLField(verbose_name=_("Lien internet (URL)"), null=False)
desc = models.TextField(verbose_name=_("Description"), null=True, blank=True)
import datetime
import logging
import os.path
import uuid
import logging
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
from django.contrib.gis.db import models as gismodels
from django.contrib.gis.db.models import Union
......@@ -12,16 +11,17 @@ from django.contrib.gis.geos import GEOSGeometry
from django.contrib.postgres.fields import JSONField
from django.core.files.storage import FileSystemStorage
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models import Sum
from django.db.models.deletion import DO_NOTHING
from django.db.models.signals import post_save, post_delete
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
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 geodata.models import Territory, Municipality, LandCover
from geodata.models import LandCover, Municipality, Territory
from management.models import Study, Transmitter
logger = logging.getLogger(__name__)
......@@ -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,9 +57,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,
......@@ -102,6 +100,11 @@ class MetaPlace(gismodels.Model):
related_name="metaplace_modifier",
on_delete=models.SET_NULL,
)
links = models.ManyToManyField(
"core.Links",
related_name="metaplace_related",
related_query_name="metaplaces",
)
def __str__(self):
return "%s ∙ %s" % (self.name, self.type)
......@@ -117,9 +120,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 +146,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 +155,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 +170,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 +195,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,
......@@ -252,6 +245,11 @@ class Place(models.Model):
verbose_name="Plan du site et/ou topo de la cavité",
)
comment = models.TextField(blank=True, null=True, verbose_name=_("Commentaire"))
links = models.ManyToManyField(
"core.Links",
related_name="place_related",
related_query_name="places",
)
other_imported_data = models.TextField(
blank=True, null=True, verbose_name=_("Autres données importées")
)
......@@ -283,9 +281,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,
......@@ -361,6 +357,11 @@ class PlaceManagement(models.Model):
"Si vous voulez charger plusieurs fichiers, créez une archive avec un logiciel de compression comme 7zip"
),
)
links = models.ManyToManyField(
"core.Links",
related_name="place_management_related",
related_query_name="place_managements",
)
bdsource = models.CharField(max_length=100, blank=True, null=True)
id_bdsource = models.CharField(max_length=100, blank=True, null=True)
extra_data = JSONField(blank=True, null=True)
......@@ -408,9 +409,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")
......@@ -754,19 +753,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")
)
......@@ -810,15 +801,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>."),
......@@ -855,9 +842,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,
......@@ -866,15 +851,20 @@ class Session(models.Model):
blank=True,
null=True,
)
dataset = models.ForeignKey(
"metadata.Dataset",
models.DO_NOTHING,
verbose_name="Jeu de données",
related_name="dataset",
blank=True,
null=True,
)
# dataset = models.ForeignKey(
# "metadata.Dataset",
# models.DO_NOTHING,
# verbose_name="Jeu de données",
# related_name="dataset",
# blank=True,
# null=True,
# )
comment = models.TextField(blank=True, null=True, verbose_name=_("Commentaire"))
links = models.ManyToManyField(
"core.Links",
related_name="session_related",
related_query_name="sessions",
)
bdsource = models.CharField(max_length=100, blank=True, null=True)
id_bdsource = models.TextField(blank=True, null=True)
extra_data = JSONField(blank=True, null=True)
......@@ -906,18 +896,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,
)
......@@ -1004,21 +990,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
)
......@@ -1078,9 +1058,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é")
)
......@@ -1091,9 +1069,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é")
)
......@@ -1131,36 +1107,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,
......@@ -1293,7 +1251,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()
Supports Markdown
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