Commit d07c63e5 authored by Hypsug0's avatar Hypsug0
Browse files

split sighting/views.py into one file per ModelViews

parent 54b6cdfa
......@@ -2,134 +2,227 @@ from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from sights.views import (PlaceUpdate, PlaceDelete, PlaceList, PlaceDetail, PlaceManagementCreate,
PlaceManagementUpdate, PlaceManagementDelete, BuildCreate, BuildUpdate, BuildDelete,
BridgeCreate, BridgeUpdate, BridgeDelete,
CaveCreate, CaveUpdate, CaveDelete, TreeCreate, TreeUpdate, TreeDelete, TreeDetail,
TreeGiteCreate,
TreeGiteUpdate, TreeGiteDelete,
SessionCreate, SessionDetail, SessionUpdate, SessionDelete, SessionMyList, SightingCreate,
SightingUpdate, SightingDelete, SightingDetail, SightingList,
SightingMyList, DeviceCreate, DeviceUpdate, DeviceDelete,
CountDetailCreate, CountDetailUpdate, CountDetailDelete,
PlaceCreate, PlaceMyList, SightingUserList, SessionChangePlaceUpdate)
from sights.views.countdetail import (
CountDetailCreate,
CountDetailUpdate,
CountDetailDelete,
)
from sights.views.metaplace import MetaPlaceCreate, MetaPlaceList
from sights.views.place import (
PlaceCreate,
PlaceUpdate,
PlaceDelete,
PlaceList,
PlaceDetail,
PlaceMyList,
)
from sights.views.place_bridge import BridgeCreate, BridgeUpdate, BridgeDelete
from sights.views.place_build import BuildCreate, BuildUpdate, BuildDelete
from sights.views.place_cave import CaveCreate, CaveUpdate, CaveDelete
from sights.views.place_management import (
PlaceManagementCreate,
PlaceManagementUpdate,
PlaceManagementDelete,
)
from sights.views.place_tree import (
TreeCreate,
TreeUpdate,
TreeDelete,
TreeDetail,
TreeGiteCreate,
TreeGiteUpdate,
TreeGiteDelete,
)
from sights.views.session import (
SessionCreate,
SessionDetail,
SessionUpdate,
SessionDelete,
SessionMyList,
SessionChangePlaceUpdate,
DeviceCreate,
DeviceUpdate,
DeviceDelete,
)
from sights.views.sighting import (
SightingCreate,
SightingUpdate,
SightingDelete,
SightingDetail,
SightingList,
SightingUserList,
SightingMyList,
)
urlpatterns = [
# url de recherches de localités
url(r'^place/search$', PlaceList.as_view(), name='place_search'),
url(r"^place/search$", PlaceList.as_view(), name="place_search"),
# User views relative URLS
url(r'^user/place/list$',
PlaceMyList.as_view(), name='place_mylist'),
url(r'^user/session/list$',
SessionMyList.as_view(), name='session_mylist'),
url(r'^user/sighting/list$',
SightingMyList.as_view(), name='sighting_mylist'),
url(r'^user/(?P<pk>[0-9]+)/sighting/list',
SightingUserList.as_view(), name='user_sighting_list'),
url(r"^user/place/list$", PlaceMyList.as_view(), name="place_mylist"),
url(r"^user/session/list$", SessionMyList.as_view(), name="session_mylist"),
url(r"^user/sighting/list$", SightingMyList.as_view(), name="sighting_mylist"),
url(
r"^user/(?P<pk>[0-9]+)/sighting/list",
SightingUserList.as_view(),
name="user_sighting_list",
),
# Place views
url(r'^place/map$', login_required(TemplateView.as_view(
template_name='sights/place_map.html')), name='place_map'),
url(r'^place/tiledmap$', login_required(TemplateView.as_view(
template_name='sights/place_map_tiled.html')), name='place_tiled_map'),
url(r'^place/tilemap$', login_required(TemplateView.as_view(
template_name='sights/place_tilemap.html')), name='place_tilemap', ),
url(r'^place/add$', PlaceCreate.as_view(), name='place_create'),
url(r'^place/(?P<pk>\d+)/detail$',
PlaceDetail.as_view(), name='place_detail'),
url(r'^place/(?P<pk>[0-9]+)/update$',
PlaceUpdate.as_view(), name='place_update'),
url(r'^place/(?P<pk>[0-9]+)/delete$',
PlaceDelete.as_view(), name='place_delete'),
url(
r"^place/map$",
login_required(TemplateView.as_view(template_name="sights/place_map.html")),
name="place_map",
),
url(
r"^place/tiledmap$",
login_required(
TemplateView.as_view(template_name="sights/place_map_tiled.html")
),
name="place_tiled_map",
),
url(
r"^place/tilemap$",
login_required(TemplateView.as_view(template_name="sights/place_tilemap.html")),
name="place_tilemap",
),
url(r"^metaplace/add$", MetaPlaceCreate.as_view(), name="metaplace_create"),
url(r"^metaplace/search$", MetaPlaceList.as_view(), name="metaplace_search"),
url(r"^place/add$", PlaceCreate.as_view(), name="place_create"),
url(r"^place/(?P<pk>\d+)/detail$", PlaceDetail.as_view(), name="place_detail"),
url(r"^place/(?P<pk>[0-9]+)/update$", PlaceUpdate.as_view(), name="place_update"),
url(r"^place/(?P<pk>[0-9]+)/delete$", PlaceDelete.as_view(), name="place_delete"),
# Place management relative URLS
url(r'^place/(?P<pk>[0-9]+)/management/add$',
PlaceManagementCreate.as_view(), name='management_create'),
url(r'^management/(?P<pk>[0-9]+)/update$',
PlaceManagementUpdate.as_view(), name='management_update'),
url(r'^management/(?P<pk>[0-9]+)/delete$',
PlaceManagementDelete.as_view(), name='management_delete'),
url(
r"^place/(?P<pk>[0-9]+)/management/add$",
PlaceManagementCreate.as_view(),
name="management_create",
),
url(
r"^management/(?P<pk>[0-9]+)/update$",
PlaceManagementUpdate.as_view(),
name="management_update",
),
url(
r"^management/(?P<pk>[0-9]+)/delete$",
PlaceManagementDelete.as_view(),
name="management_delete",
),
# Build views
url(r'^place/(?P<pk>[0-9]+)/build/add$',
BuildCreate.as_view(), name='build_create'),
url(r'^build/(?P<pk>[0-9]+)/update$',
BuildUpdate.as_view(), name='build_update'),
url(r'^build/(?P<pk>[0-9]+)/delete$',
BuildDelete.as_view(), name='build_delete'),
url(
r"^place/(?P<pk>[0-9]+)/build/add$", BuildCreate.as_view(), name="build_create"
),
url(r"^build/(?P<pk>[0-9]+)/update$", BuildUpdate.as_view(), name="build_update"),
url(r"^build/(?P<pk>[0-9]+)/delete$", BuildDelete.as_view(), name="build_delete"),
# Tree views
url(r'^place/(?P<pk>[0-9]+)/tree/add$',
TreeCreate.as_view(), name='tree_create'),
url(r'^tree/(?P<pk>[0-9]+)/update$',
TreeUpdate.as_view(), name='tree_update'),
url(r'^tree/(?P<pk>[0-9]+)/delete$',
TreeDelete.as_view(), name='tree_delete'),
url(r'^tree/(?P<pk>[0-9]+)/detail$',
TreeDetail.as_view(), name='tree_detail'),
url(r"^place/(?P<pk>[0-9]+)/tree/add$", TreeCreate.as_view(), name="tree_create"),
url(r"^tree/(?P<pk>[0-9]+)/update$", TreeUpdate.as_view(), name="tree_update"),
url(r"^tree/(?P<pk>[0-9]+)/delete$", TreeDelete.as_view(), name="tree_delete"),
url(r"^tree/(?P<pk>[0-9]+)/detail$", TreeDetail.as_view(), name="tree_detail"),
# TreeGite views
url(r'^tree/(?P<pk>[0-9]+)/treegite/add$',
TreeGiteCreate.as_view(), name='treegite_create'),
url(r'^treegite/(?P<pk>[0-9]+)/update$',
TreeGiteUpdate.as_view(), name='treegite_update'),
url(r'^treegite/(?P<pk>[0-9]+)/delete$',
TreeGiteDelete.as_view(), name='treegite_delete'),
url(
r"^tree/(?P<pk>[0-9]+)/treegite/add$",
TreeGiteCreate.as_view(),
name="treegite_create",
),
url(
r"^treegite/(?P<pk>[0-9]+)/update$",
TreeGiteUpdate.as_view(),
name="treegite_update",
),
url(
r"^treegite/(?P<pk>[0-9]+)/delete$",
TreeGiteDelete.as_view(),
name="treegite_delete",
),
# Cave views
url(r'^place/(?P<pk>[0-9]+)/cave/add$',
CaveCreate.as_view(), name='cave_create'),
url(r'^cave/(?P<pk>[0-9]+)/update$',
CaveUpdate.as_view(), name='cave_update'),
url(r'^cave/(?P<pk>[0-9]+)/delete$',
CaveDelete.as_view(), name='cave_delete'),
url(r"^place/(?P<pk>[0-9]+)/cave/add$", CaveCreate.as_view(), name="cave_create"),
url(r"^cave/(?P<pk>[0-9]+)/update$", CaveUpdate.as_view(), name="cave_update"),
url(r"^cave/(?P<pk>[0-9]+)/delete$", CaveDelete.as_view(), name="cave_delete"),
# Bridge views
url(r'^place/(?P<pk>[0-9]+)/bridge/add$',
BridgeCreate.as_view(), name='bridge_create'),
url(r'^bridge/(?P<pk>[0-9]+)/update$',
BridgeUpdate.as_view(), name='bridge_update'),
url(r'^bridge/(?P<pk>[0-9]+)/delete$',
BridgeDelete.as_view(), name='bridge_delete'),
url(
r"^place/(?P<pk>[0-9]+)/bridge/add$",
BridgeCreate.as_view(),
name="bridge_create",
),
url(
r"^bridge/(?P<pk>[0-9]+)/update$", BridgeUpdate.as_view(), name="bridge_update"
),
url(
r"^bridge/(?P<pk>[0-9]+)/delete$", BridgeDelete.as_view(), name="bridge_delete"
),
# Session relative URLS
url(r'^place/(?P<pk>[0-9]+)/session/add$',
SessionCreate.as_view(), name='session_create'),
url(r'^session/(?P<pk>[0-9]+)/detail$',
SessionDetail.as_view(), name='session_detail'),
url(r'^session/(?P<pk>[0-9]+)/update$',
SessionUpdate.as_view(), name='session_update'),
url(r'^session/(?P<pk>[0-9]+)/change_place$',
SessionChangePlaceUpdate.as_view(), name='sessionchangeplace_update'),
url(r'^session/(?P<pk>[0-9]+)/delete$',
SessionDelete.as_view(), name='session_delete'),
url(
r"^place/(?P<pk>[0-9]+)/session/add$",
SessionCreate.as_view(),
name="session_create",
),
url(
r"^session/(?P<pk>[0-9]+)/detail$",
SessionDetail.as_view(),
name="session_detail",
),
url(
r"^session/(?P<pk>[0-9]+)/update$",
SessionUpdate.as_view(),
name="session_update",
),
url(
r"^session/(?P<pk>[0-9]+)/change_place$",
SessionChangePlaceUpdate.as_view(),
name="sessionchangeplace_update",
),
url(
r"^session/(?P<pk>[0-9]+)/delete$",
SessionDelete.as_view(),
name="session_delete",
),
# Device relative URLS
url(r'^session/(?P<pk>[0-9]+)/device/add$',
DeviceCreate.as_view(), name='device_create'),
url(r'^device/(?P<pk>[0-9]+)/update$',
DeviceUpdate.as_view(), name='device_update'),
url(r'^device/(?P<pk>[0-9]+)/delete$',
DeviceDelete.as_view(), name='device_delete'),
url(
r"^session/(?P<pk>[0-9]+)/device/add$",
DeviceCreate.as_view(),
name="device_create",
),
url(
r"^device/(?P<pk>[0-9]+)/update$", DeviceUpdate.as_view(), name="device_update"
),
url(
r"^device/(?P<pk>[0-9]+)/delete$", DeviceDelete.as_view(), name="device_delete"
),
# Sighting relative URLS
url(r'^session/(?P<pk>[0-9]+)/sighting/add$',
SightingCreate.as_view(), name='sighting_create'),
url(r'^sighting/(?P<pk>[0-9]+)/detail$',
SightingDetail.as_view(), name='sighting_detail'),
url(r'^sighting/(?P<pk>[0-9]+)/update$',
SightingUpdate.as_view(), name='sighting_update'),
url(r'^sighting/(?P<pk>[0-9]+)/delete$',
SightingDelete.as_view(), name='sighting_delete'),
url(r'^sighting/list$',
SightingList.as_view(), name='sighting_list'),
url(
r"^session/(?P<pk>[0-9]+)/sighting/add$",
SightingCreate.as_view(),
name="sighting_create",
),
url(
r"^sighting/(?P<pk>[0-9]+)/detail$",
SightingDetail.as_view(),
name="sighting_detail",
),
url(
r"^sighting/(?P<pk>[0-9]+)/update$",
SightingUpdate.as_view(),
name="sighting_update",
),
url(
r"^sighting/(?P<pk>[0-9]+)/delete$",
SightingDelete.as_view(),
name="sighting_delete",
),
url(r"^sighting/list$", SightingList.as_view(), name="sighting_list"),
# CountDetail relative URLS
url(r'^sighting/(?P<pk>[0-9]+)/countdetail/add$',
CountDetailCreate.as_view(), name='countdetail_create'),
url(r'^countdetail/(?P<pk>[0-9]+)/update$',
CountDetailUpdate.as_view(), name='countdetail_update'),
url(r'^countdetail/(?P<pk>[0-9]+)/delete$',
CountDetailDelete.as_view(), name='countdetail_delete'),
url(
r"^sighting/(?P<pk>[0-9]+)/countdetail/add$",
CountDetailCreate.as_view(),
name="countdetail_create",
),
url(
r"^countdetail/(?P<pk>[0-9]+)/update$",
CountDetailUpdate.as_view(),
name="countdetail_update",
),
url(
r"^countdetail/(?P<pk>[0-9]+)/delete$",
CountDetailDelete.as_view(),
name="countdetail_delete",
),
]
This diff is collapsed.
"""
Vues de l'application Sights
"""
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from core import js
from dicts.models import CountPrecision
from ..forms import (
CountDetailBiomForm,
CountDetailOtherForm,
CountDetailAcousticForm,
CountDetailTelemetryForm,
)
from ..mixins import (
CountDetailEditAuthMixin,
)
from ..models import (
CountDetail,
Sighting,
)
IMAGE_FILE_TYPES = ["png", "jpg", "jpeg"]
DOCUMENT_FILE_TYPES = ["doc", "docx", "odt", "pdf"]
#################################################
# CountDetail model views #
#################################################
class CountDetailCreate(LoginRequiredMixin, CreateView):
model = CountDetail
template_name = "normal_form.html"
def get_form_class(self):
sighting_id = self.kwargs.get("pk")
contact = Sighting.objects.get(
id_sighting=sighting_id
).session.contact.code
if contact in ("vm", "ca"):
return CountDetailBiomForm
if contact == "du":
return CountDetailAcousticForm
if contact == "te":
return CountDetailTelemetryForm
else:
return CountDetailOtherForm
def get_form_kwargs(self):
kwargs = super(CountDetailCreate, self).get_form_kwargs()
sighting_id = self.kwargs.get("pk")
kwargs["sighting_id"] = sighting_id
contact = Sighting.objects.get(
id_sighting=sighting_id
).session.contact.code
kwargs["contact"] = contact
if contact in ("vm", "ca"):
kwargs["session"] = Sighting.objects.get(
id_sighting=sighting_id
).session.id_session
return kwargs
def get_initial(self):
initial = super(CountDetailCreate, self).get_initial()
initial = initial.copy()
sighting_id = self.kwargs.get("pk")
contact = Sighting.objects.get(
id_sighting=sighting_id
).session.contact.code
if contact in ("vm", "ca"):
initial["manipulator"] = self.request.user
initial["validator"] = self.request.user
if CountDetail.objects.filter(sighting_id=sighting_id):
lastcountdetail = CountDetail.objects.filter(
sighting_id=sighting_id
).order_by("-timestamp_create")[0]
if contact in ("vm", "du"):
if lastcountdetail:
initial["time"] = lastcountdetail.time
initial["method"] = lastcountdetail.method
initial["unit"] = lastcountdetail.unit
initial["precision"] = lastcountdetail.precision
initial["device"] = lastcountdetail.device
return initial
def form_valid(self, form):
form.instance.created_by = self.request.user
form.instance.sighting_id = self.kwargs.get("pk")
contact = Sighting.objects.get(
id_sighting=self.kwargs.get("pk")
).session.contact.code
if contact == "du":
form.instance.precision = CountPrecision.objects.get(
contact=contact
)
if contact in ("vm", "te"):
form.instance.count = 1
return super(CountDetailCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(CountDetailCreate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-fw fa-venus-mars"
context["title"] = _("Ajout d'une observation détaillée")
context["js"] = js.TimeInput
return context
def get_success_url(self):
sighting_id = self.object.sighting_id
if self.request.method == "POST" and "_addanother" in self.request.POST:
print("lala")
return reverse_lazy(
"sights:countdetail_create", kwargs={"pk": sighting_id}
)
return reverse_lazy(
"sights:sighting_detail", kwargs={"pk": self.object.sighting_id}
)
class CountDetailUpdate(CountDetailEditAuthMixin, UpdateView):
model = CountDetail
template_name = "normal_form.html"
def get_form_class(self):
sighting_id = self.object.sighting_id
contact = Sighting.objects.get(
id_sighting=sighting_id
).session.contact.code
if contact in ("vm", "ca"):
return CountDetailBiomForm
if contact == "du":
return CountDetailAcousticForm
if contact == "te":
return CountDetailTelemetryForm
else:
return CountDetailOtherForm
def get_form_kwargs(self):
kwargs = super(CountDetailUpdate, self).get_form_kwargs()
sighting_id = self.object.sighting_id
kwargs["sighting_id"] = sighting_id
contact = Sighting.objects.get(
id_sighting=sighting_id
).session.contact.code
kwargs["contact"] = contact
if contact in ("vm", "ca"):
kwargs["session"] = Sighting.objects.get(
id_sighting=sighting_id
).session.id_session
return kwargs
def form_valid(self, form):
form.instance.updated_by = self.request.user
contact = Sighting.objects.get(
id_sighting=self.object.sighting_id
).session.contact.code
if contact == "du":
form.instance.precision = CountPrecision.objects.get(
contact=contact
)
if contact in ("vm", "te"):
form.instance.count = 1
return super(CountDetailUpdate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(CountDetailUpdate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-venus-mars"
context["title"] = _("Modification d'une observation détaillée")
jsAddAnother = """
$('#addanother').hide();
"""
context["js"] = jsAddAnother + js.TimeInput
return context
class CountDetailDelete(CountDetailEditAuthMixin, DeleteView):
model = CountDetail
template_name = "confirm_delete.html"
def get_success_url(self):
return reverse_lazy(
"sights:sighting_detail", kwargs={"pk": self.object.sighting_id}
)
def get_context_data(self, **kwargs):
context = super(CountDetailDelete, self).get_context_data(**kwargs)
context["icon"] = "fa fa-fw fa-trash"
context["title"] = _("Suppression d'une observation détaillée")
context["message_alert"] = _(
"Êtes-vous certain de vouloir supprimer l'observation détaillée"
)
return context
"""
Vues de l'application Sights
"""
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django_filters.views import FilterView
from django_tables2 import SingleTableView
from django_tables2.export import ExportMixin
from ..filters import PlaceFilter
from ..forms import (
MetaPlaceForm,
PlaceSearchFilterForm,
)
from ..mixins import (
PlaceEditAuthMixin,
)
from ..models import (
MetaPlace,
Place,
)
from ..tables import (
MetaPlaceTable
)
IMAGE_FILE_TYPES = ["png", "jpg", "jpeg"]
DOCUMENT_FILE_TYPES = ["doc", "docx", "odt", "pdf"]
class MetaPlaceCreate(LoginRequiredMixin, CreateView):
"""Créateview for MetaPlace model"""
model = MetaPlace
form_class = MetaPlaceForm
template_name = "normal_form.html"
success_url = reverse_lazy("sights:metaplace_list")
# def form_valid(self, form):
# form.instance.created_by = self.request.user
# return super(MetaPlaceCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(MetaPlaceCreate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-fw fa-map"
context["title"] = "Création d'un métasite"
context[
"js"
] = """
"""
return context
class MetaPlaceUpdate(PlaceEditAuthMixin, UpdateView):
"""UpdateView form MetaPlace"""
model = MetaPlace
form_class = MetaPlaceForm
template_name = "normal_form.html"
success_url = reverse_lazy("sights:metaplace_list")
def get_context_data(self, **kwargs):
context = super(MetaPlaceUpdate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-fw fa-map"
context["title"] = "Modification d'un métasite"
context[