Commit e15ff62a authored by fred.perso's avatar fred.perso

cutting the main application sights into several modules

parent d583f442
from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin
# from django.contrib.auth.admin import UserAdmin
from .models import User
admin.site.register(User, LeafletGeoAdmin)
from django.apps import AppConfig
class AccountsConfig(AppConfig):
name = 'accounts'
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-11-16 01:17
from __future__ import unicode_literals
import django.contrib.auth.models
import django.contrib.auth.validators
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=30, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('status', models.CharField(choices=[('resp', 'Responsable'), ('obs', 'Observateur')], default='obs', max_length=10, verbose_name="Statut de l'utilisateur")),
('auth_access_alldata', models.NullBooleanField()),
('auth_edit_alldata', models.NullBooleanField()),
('organism', models.CharField(blank=True, max_length=255, null=True, verbose_name='Organisme')),
('home_phone', models.CharField(blank=True, max_length=50, null=True, verbose_name='Numéro de téléphone fixe')),
('mobile_phone', models.CharField(blank=True, max_length=50, null=True, verbose_name='Numéro de téléphone portable')),
('addr_appt', models.CharField(blank=True, max_length=50, null=True, verbose_name='Appartement')),
('addr_building', models.CharField(blank=True, max_length=255, null=True, verbose_name='Immeuble')),
('addr_street', models.CharField(blank=True, max_length=255, null=True, verbose_name='Rue')),
('addr_city', models.CharField(blank=True, max_length=255, null=True, verbose_name='Commune')),
('addr_city_code', models.CharField(blank=True, max_length=10, null=True, verbose_name='Code postal')),
('addr_dept', models.CharField(blank=True, max_length=255, null=True, verbose_name='Département')),
('addr_country', models.CharField(blank=True, max_length=255, null=True, verbose_name='Pays')),
('comment', models.TextField(blank=True, null=True, verbose_name='Commentaire')),
('id_bdsource', models.CharField(blank=True, max_length=100, null=True)),
('bdsource', models.CharField(blank=True, max_length=100, null=True)),
('geom', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=2154, verbose_name='Localisation géographique')),
('timestamp_create', models.DateTimeField(auto_now_add=True)),
('timestamp_update', models.DateTimeField(auto_now=True)),
],
options={
'verbose_name_plural': 'Détails des utilisateurs',
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-11-16 01:17
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('management', '0001_initial'),
('accounts', '0001_initial'),
('geodata', '0001_initial'),
('auth', '0008_alter_user_username_max_length'),
]
operations = [
migrations.AddField(
model_name='user',
name='catchauth',
field=models.ManyToManyField(blank=True, to='management.CatchAuth', verbose_name='Authorisations de capture'),
),
migrations.AddField(
model_name='user',
name='coord_territory',
field=models.ManyToManyField(blank=True, to='geodata.Territory', verbose_name='Territoires du rôle de coordinateur'),
),
migrations.AddField(
model_name='user',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups'),
),
migrations.AddField(
model_name='user',
name='user_permissions',
field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions'),
),
]
from django.contrib.auth.models import AbstractUser
# from django.db import models
from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _
from sights.models import Territory
from management.models import CatchAuth
# Create your models here.
class User(AbstractUser):
STATUS = [
('resp', _('Responsable')),
('obs', _('Observateur'))
]
status = models.CharField(max_length=10, choices=STATUS, default='obs', verbose_name=_('Statut de l\'utilisateur'))
coord_territory = models.ManyToManyField(Territory, blank=True,
verbose_name=_('Territoires du rôle de coordinateur'))
auth_access_alldata = models.NullBooleanField()
auth_edit_alldata = models.NullBooleanField()
catchauth = models.ManyToManyField(
CatchAuth,
blank=True, verbose_name=_('Authorisations de capture'))
organism = models.CharField(max_length=255, blank=True, null=True, verbose_name=_('Organisme'))
home_phone = models.CharField(max_length=50, blank=True, null=True, verbose_name=_('Numéro de téléphone fixe'))
mobile_phone = models.CharField(max_length=50, blank=True, null=True,
verbose_name=_('Numéro de téléphone portable'))
addr_appt = models.CharField(max_length=50, blank=True, null=True, verbose_name=_('Appartement'))
addr_building = models.CharField(max_length=255, blank=True, null=True, verbose_name=_('Immeuble'))
addr_street = models.CharField(max_length=255, blank=True, null=True, verbose_name=_('Rue'))
addr_city = models.CharField(max_length=255, blank=True, null=True, verbose_name=_('Commune'))
addr_city_code = models.CharField(max_length=10, blank=True, null=True, verbose_name=_('Code postal'))
addr_dept = models.CharField(max_length=255, blank=True, null=True, verbose_name=_('Département'))
addr_country = models.CharField(max_length=255, blank=True, null=True, verbose_name=_('Pays'))
comment = models.TextField(blank=True, null=True, verbose_name=_('Commentaire'))
id_bdsource = models.CharField(max_length=100, blank=True, null=True)
bdsource = models.CharField(max_length=100, blank=True, null=True)
geom = models.PointField(srid=2154, blank=True, null=True, verbose_name=_('Localisation géographique'))
timestamp_create = models.DateTimeField(
auto_now_add=True, editable=False)
timestamp_update = models.DateTimeField(
auto_now=True, editable=False)
def __str__(self):
return "Détails de %s" % (self.username)
class Meta:
verbose_name_plural = "Détails des utilisateurs"
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from dal import autocomplete
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.core.serializers import serialize
from django.db.models import Q, F
from django.http import HttpResponse
from djgeojson.views import GeoJSONLayerView, TiledGeoJSONLayerView
from sights.models import Place, UserDetail, Territory, Municipality
from sights.models import Place, Territory, Municipality
class ActiveUserAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
if not self.request.user.is_authenticated():
return User.objects.none()
return settings.AUTH_USER_MODEL.objects.none()
qs = User.objects.filter(is_active=True).order_by('username')
qs = settings.AUTH_USER_MODEL.objects.filter(is_active=True).order_by('username')
if self.q:
qs = qs.filter(username__icontains=self.q)
......@@ -27,9 +27,9 @@ class AllUserAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
if not self.request.user.is_authenticated():
return User.objects.none()
return settings.AUTH_USER_MODEL.objects.none()
qs = User.objects.all().order_by('username')
qs = settings.AUTH_USER_MODEL.objects.all().order_by('username')
if self.q:
qs = qs.filter(username__icontains=self.q)
......@@ -85,7 +85,7 @@ def PlaceAsGeoJSON(request):
:return:
'''
loggeduser = request.user
userdetail = UserDetail.objects.get(user=loggeduser)
userdetail = settings.AUTH_USER_MODEL.objects.get(user=loggeduser)
if userdetail.auth_access_alldata == True:
print('Chargement de la carte pour l\'utilisateur avec accès total')
place_list = Place.objects.all()
......
......@@ -45,7 +45,11 @@ INSTALLED_APPS = [
'django.contrib.admindocs',
'haystack',
'debug_toolbar',
'accounts',
'dicts',
'geodata',
'sights',
'management',
'ckeditor',
'leaflet',
'crispy_forms',
......@@ -118,6 +122,10 @@ HAYSTACK_CONNECTIONS = {
},
}
# Customizing User model
AUTH_USER_MODEL = 'accounts.User'
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
......
This diff is collapsed.
from django.contrib import admin
from .models import TypeDevice, TypePlace, Contact, BiomDent, PlaceManagementAction, LandCoverCLC
admin.site.register(TypePlace)
admin.site.register(Contact)
admin.site.register(TypeDevice)
admin.site.register(BiomDent)
admin.site.register(PlaceManagementAction)
admin.site.register(LandCoverCLC)
from django.apps import AppConfig
class DictsConfig(AppConfig):
name = 'dicts'
This diff is collapsed.
This diff is collapsed.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin
from .models import Territory, Municipality, LandCover
admin.site.register(Territory, LeafletGeoAdmin)
admin.site.register(Municipality, LeafletGeoAdmin)
admin.site.register(LandCover, LeafletGeoAdmin)
from django.apps import AppConfig
class GeodataConfig(AppConfig):
name = 'geodata'
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-11-16 01:17
from __future__ import unicode_literals
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dicts', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='LandCover',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=2154, verbose_name='Géométries')),
('code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dicts.LandCoverCLC', verbose_name='Code')),
],
options={
'verbose_name': 'Occupation du sol',
'verbose_name_plural': 'Occupation du sol',
},
),
migrations.CreateModel(
name='Municipality',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100, verbose_name='Nom')),
('code', models.CharField(max_length=5, verbose_name='Code')),
('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=2154, verbose_name='Emprise géographique')),
],
options={
'verbose_name': 'Commune',
'verbose_name_plural': 'Communes',
},
),
migrations.CreateModel(
name='Territory',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100, verbose_name='Nom')),
('code', models.CharField(max_length=5, verbose_name='Code')),
('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=2154, verbose_name='Emprise géographique')),
],
options={
'verbose_name': 'Territoire du groupe local',
'verbose_name_plural': 'Territoires des groupes locaux',
},
),
]
from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _
from dicts.models import LandCoverCLC
# =========================================================================
# Données géographiques
# =========================================================================
class Territory(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, verbose_name='Nom')
code = models.CharField(max_length=5, verbose_name='Code')
geom = models.MultiPolygonField(
srid=2154, verbose_name='Emprise géographique')
def __str__(self):
return "%s ∙ %s" % (self.code, self.name)
class Meta:
verbose_name = _('Territoire du groupe local')
verbose_name_plural = _('Territoires des groupes locaux')
class Municipality(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, verbose_name='Nom')
code = models.CharField(max_length=5, verbose_name='Code')
geom = models.MultiPolygonField(
srid=2154, verbose_name='Emprise géographique')
def __str__(self):
return "%s %s" % (self.code[0:2], self.name)
class Meta:
verbose_name = _('Commune')
verbose_name_plural = _('Communes')
class LandCover(models.Model):
id = models.AutoField(primary_key=True)
code = models.ForeignKey(LandCoverCLC, verbose_name=_("Code"), blank=True, null=True)
geom = models.MultiPolygonField(srid=2154, verbose_name=_("Géométries"))
def __str__(self):
return "%s %s" % (self.code, self.code_descr.descr)
# TODO Créer model dico CLC12
class Meta:
verbose_name = _('Occupation du sol')
verbose_name_plural = _('Occupation du sol')
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
from .models import CatchAuth, PlaceManagementAction
class CatchAuthAdmin(admin.ModelAdmin):
model = CatchAuth
list_display = ('id_catchauth', 'date_start', 'date_end',
'territory', 'official_reference', 'file')
search_fields = ('territory',)
sortable_field_name = ['__all__']
# Register your models here.
admin.site.register(CatchAuth, CatchAuthAdmin)
# admin.site.register(PlaceManagementAction)
from django.apps import AppConfig
class ManagementConfig(AppConfig):
name = 'management'
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-11-16 01:17
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dicts', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('geodata', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='CatchAuth',
fields=[
('id_catchauth', models.AutoField(primary_key=True, serialize=False)),
('date_start', models.DateField()),
('date_end', models.DateField()),
('official_reference', models.CharField(blank=True, max_length=255, null=True)),
('file', models.FileField(blank=True, null=True, upload_to='catchauth/%Y/')),
('timestamp_create', models.DateTimeField(auto_now_add=True)),
('timestamp_update', models.DateTimeField(auto_now=True)),
('creator', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='catchauth_creator', to=settings.AUTH_USER_MODEL)),
('territory', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='geodata.Territory')),
],
options={
'verbose_name': 'Autorisation de manipulation / capture',
'verbose_name_plural': 'Autorisations de manipulation / capture',
},
),
migrations.CreateModel(
name='PlaceManagement',
fields=[
('id_placemanagement', models.AutoField(primary_key=True, serialize=False)),
('date', models.DateField(verbose_name='Date')),
('comment', models.TextField(blank=True, null=True, verbose_name='Commentaire')),
('file', models.FileField(blank=True, null=True, upload_to='place/management/', verbose_name='Fichier')),
('timestamp_create', models.DateTimeField(auto_now_add=True)),
('timestamp_update', models.DateTimeField(auto_now=True)),
('action', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dicts.PlaceManagementAction', verbose_name='Action')),
('creator', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Action de gestion',
'verbose_name_plural': 'Actions de gestion',
},
),
migrations.CreateModel(
name='Study',
fields=[
('id_study', models.AutoField(db_index=True, primary_key=True, serialize=False)),
('name', models.CharField(db_index=True, max_length=255, verbose_name="nom du l'étude")),
('year', models.CharField(db_index=True, max_length=10, verbose_name="Année de réalisation l'étude")),
('project_manager', models.CharField(db_index=True, max_length=100, verbose_name="Responsable de l'étude")),
('public_funding', models.BooleanField(verbose_name='Financement publique')),
('public_report', models.BooleanField(verbose_name='Rapport rendu publique')),
('public_raw_data', models.BooleanField(verbose_name='Donnée brute publique')),
('confidential', models.BooleanField(verbose_name='Confidentiel')),
('confidential_end_date', models.DateField(blank=True, null=True, verbose_name='Date de fin de la confidentialité')),
('type_etude', models.CharField(max_length=255, verbose_name="Type d'étude")),
('type_espace', models.CharField(blank=True, max_length=255, null=True, verbose_name="Type d'espace")),
('comment', models.TextField(blank=True, null=True, verbose_name='Commentaire')),
('timestamp_create', models.DateTimeField(auto_now_add=True)),
('timestamp_update', models.DateTimeField(auto_now=True)),
('creator', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-timestamp_create'],
'verbose_name': 'Etude',
'verbose_name_plural': 'Etudes',
},
),
migrations.AddIndex(
model_name='study',
index=models.Index(fields=['-timestamp_update'], name='etude_timestamp_update_idx'),
),
migrations.AddIndex(
model_name='study',
index=models.Index(fields=['name'], name='etude_name_idx'),
),
migrations.AddIndex(
model_name='study',
index=models.Index(fields=['creator'], name='etude_creator_idx'),
),
migrations.AlterUniqueTogether(
name='study',
unique_together=set([('name', 'year')]),
),
]
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from dicts.models import PlaceManagementAction
from geodata.models import Territory
# from sights.models import Place
class CatchAuth(models.Model):
id_catchauth = models.AutoField(primary_key=True)
territory = models.ForeignKey(
Territory, models.DO_NOTHING, db_index=True, blank=True, null=True)
date_start = models.DateField()
date_end = models.DateField()
official_reference = models.CharField(
max_length=255, blank=True, null=True)
# territory = models.CharField(
# max_length=255, blank=True, null=True)
file = models.FileField(upload_to='catchauth/%Y/', blank=True, null=True)
timestamp_create = models.DateTimeField(
auto_now_add=True, editable=False)
timestamp_update = models.DateTimeField(
auto_now=True, editable=False)
creator = models.ForeignKey(
settings.AUTH_USER_MODEL, null=True, blank=True, editable=False, related_name='catchauth_creator')
def __str__(self):
return "%s : Autorisation %s du %s au %s" % (
self.territory, self.official_reference, self.date_start, self.date_end)
class Meta:
verbose_name = "Autorisation de manipulation / capture"
verbose_name_plural = "Autorisations de manipulation / capture"
class PlaceManagement(models.Model):
id_placemanagement = models.AutoField(primary_key=True)
# place = models.ForeignKey(Place)
date = models.DateField(verbose_name=_("Date"))
action = models.ForeignKey(PlaceManagementAction, verbose_name=_("Action"))
comment = models.TextField(blank=True, null=True, verbose_name=_("Commentaire"))
file = models.FileField(upload_to='place/management/', blank=True, null=True, verbose_name=_("Fichier"))
timestamp_create = models.DateTimeField(
auto_now_add=True, editable=False)
timestamp_update = models.DateTimeField(
auto_now=True, editable=False)
creator = models.ForeignKey(
settings.AUTH_USER_MODEL, null=True, editable=False)
def __str__(self):
return "%s ∙ %s" % (self.date, self.action)
class Meta:
verbose_name = _("Action de gestion")
verbose_name_plural = _("Actions de gestion")
# =========================================================================
# Données d'études des chiroptères
# =========================================================================
class Study(models.Model):
id_study = models.AutoField(primary_key=True, db_index=True)
name = models.CharField(max_length=255, db_index=True,
verbose_name='nom du l\'étude')
year = models.CharField(
max_length=10, db_index=True, verbose_name='Année de réalisation l\'étude')
project_manager = models.CharField(max_length=100, db_index=True,
verbose_name='Responsable de l\'étude')
# study_organism = models.ForeignKey(
# 'Organism',
# models.DO_NOTHING,
# db_column='name',
# blank=True,
# null=True)
# study_sponsor = models.ForeignKey(
# 'Organism',
# models.DO_NOTHING,
# db_column='name',
# blank=True,
# null=True)
public_funding = models.BooleanField(
verbose_name='Financement publique')
public_report = models.BooleanField(
verbose_name='Rapport rendu publique')
public_raw_data = models.BooleanField(
verbose_name='Donnée brute publique')
confidential = models.BooleanField(
verbose_name='Confidentiel')
confidential_end_date = models.DateField(
blank=True, null=True, verbose_name='Date de fin de la confidentialité')
type_etude = models.CharField(max_length=255, verbose_name='Type d\'étude')
type_espace = models.CharField(
max_length=255, blank=True, null=True, verbose_name='Type d\'espace')
comment = models.TextField(
blank=True, null=True, verbose_name='Commentaire')
timestamp_create = models.DateTimeField(
auto_now_add=True, editable=False)
timestamp_update = models.DateTimeField(
auto_now=True, editable=False)
creator = models.ForeignKey(
settings.AUTH_USER_MODEL, null=True, db_index=True, editable=False)
def __str__(self):
return "%s (%s)" % (self.name, self.year)
def get_absolute_url(self):
return reverse('place_detail', kwargs={'pk': self.id_place})
class Meta:
verbose_name = "Etude"
verbose_name_plural = "Etudes"
indexes = [
models.Index(fields=['-timestamp_update'],
name='etude_timestamp_update_idx'),
models.Index(fields=['name'], name='etude_name_idx'),
models.Index(fields=['creator'], name='etude_creator_idx'),
]
unique_together = ["name", "year"]
ordering = ['-timestamp_create']
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
......@@ -3,50 +3,48 @@ from django.contrib import admin
from django.contrib.auth.models import User
from leaflet.admin import LeafletGeoAdminMixin, LeafletGeoAdmin
from .models import (Actu, CatchAuth, Comment, CountDetail, DictSpecie,
DictSpecieDetail, DictSpecieStatus, Place,Territory,
from .models import (Actu, CountDetail,Place,
PlaceBridgeDetail, PlaceBuildDetail, PlaceCaveDetail,
PlaceTreeDetail, Session, Sighting, Transmitter,
UserDetail, Study)
# =========================================================================