Commit 19feb100 authored by Hypsug0's avatar Hypsug0
Browse files

reorganize views and urls in sights module

parent aad6125b
import logging
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth import get_user_model, update_session_auth_hash
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.mail import send_mail
from django.shortcuts import render
from django.urls import reverse
from django.urls import reverse_lazy
from django.urls import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
......@@ -27,6 +27,7 @@ from .mixins import ManageAccountAuthMixin, ManageMyAccountAuthMixin
from .models import Profile
from .tables import ProfileTable
logger = logging.getLogger(__name__)
class UserCreate(ManageAccountAuthMixin, CreateView):
"""
......@@ -146,7 +147,7 @@ class UserPassword(ManageAccountAuthMixin, UpdateView):
def get_form_kwargs(self):
kwargs = super(UserPassword, self).get_form_kwargs()
username = self.object.username
print(username)
logger.debug(username)
return kwargs
def get_success_url(self):
......@@ -211,6 +212,7 @@ class UserDelete(ManageAccountAuthMixin, DeleteView):
class UserDetail(LoginRequiredMixin, DetailView):
model = get_user_model()
template_name = "accounts/profile.html"
class MyProfileDetail(LoginRequiredMixin, DetailView):
......@@ -218,9 +220,10 @@ class MyProfileDetail(LoginRequiredMixin, DetailView):
template_name = "accounts/profile.html"
def get_object(self):
logger.info(self.request.user.id)
return get_user_model().objects.get(
id=self.request.user.id
) # or request.POST
)
@login_required()
......
......@@ -51,7 +51,6 @@ class AllUserAutocomplete(autocomplete.Select2QuerySetView):
class TaxaAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
logger.debug("is auth")
if not self.request.user.is_authenticated:
return Specie.objects.none()
......
from django.urls import path
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from sights.countdetail.views import (
CountDetailCreate,
CountDetailUpdate,
CountDetailDelete,
)
urlpatterns = [
path(
'sighting/<int:pk>/countdetail/add',
CountDetailCreate.as_view(),
name="countdetail_create",
),
path(
'countdetail/<int:pk>/update',
CountDetailUpdate.as_view(),
name="countdetail_update",
),
path(
'countdetail/<int:pk>/delete',
CountDetailDelete.as_view(),
name="countdetail_delete",
),
]
\ No newline at end of file
......@@ -2,6 +2,8 @@
Vues de l'application Sights
"""
import logging
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
......@@ -9,6 +11,8 @@ from django.views.generic.edit import CreateView, DeleteView, UpdateView
from core import js
from dicts.models import CountPrecision
from dbchiro.settings.base import DOCUMENT_FILE_TYPES, IMAGE_FILE_TYPES
from ..forms import (
CountDetailBiomForm,
CountDetailOtherForm,
......@@ -23,8 +27,7 @@ from ..models import (
Sighting,
)
IMAGE_FILE_TYPES = ["png", "jpg", "jpeg"]
DOCUMENT_FILE_TYPES = ["doc", "docx", "odt", "pdf"]
logger = logging.getLogger(__name__)
#################################################
......@@ -111,7 +114,7 @@ class CountDetailCreate(LoginRequiredMixin, CreateView):
def get_success_url(self):
sighting_id = self.object.sighting_id
if self.request.method == "POST" and "_addanother" in self.request.POST:
print("lala")
logger.debug("lala")
return reverse_lazy(
"sights:countdetail_create", kwargs={"pk": sighting_id}
)
......
from django.contrib.auth.decorators import login_required
from django.urls import include, path
from django.views.generic import TemplateView
from sights.metaplace.views import (
MetaPlaceCreate,
MetaPlaceDelete,
MetaPlaceDetail,
MetaPlaceList,
MetaPlaceUpdate,
)
urlpatterns=[
path("metaplace/add", MetaPlaceCreate.as_view(), name="metaplace_create"),
path("metaplace/search", MetaPlaceList.as_view(), name="metaplace_search"),
path("metaplace/<int:pk>/detail", MetaPlaceDetail.as_view(), name="metaplace_detail"),
path("metaplace/<int:pk>/update", MetaPlaceUpdate.as_view(), name="metaplace_update"),
path("metaplace/<int:pk>/delete", MetaPlaceDelete.as_view(), name="metaplace_delete"),
]
\ No newline at end of file
from django.contrib.auth.decorators import login_required
from django.urls import include, path
from django.views.generic import TemplateView
from sights.observation.views import (
SightingCreate,
SightingDelete,
SightingDetail,
SightingList,
SightingMyList,
SightingUpdate,
SightingUserList,
)
urlpatterns = [
# Sighting relative URLS
path(
"session/<int:pk>/sighting/add",
SightingCreate.as_view(),
name="sighting_create",
),
path("sighting/<int:pk>/detail", SightingDetail.as_view(), name="sighting_detail"),
path("sighting/<int:pk>/update", SightingUpdate.as_view(), name="sighting_update"),
path("sighting/<int:pk>/delete", SightingDelete.as_view(), name="sighting_delete"),
path("sighting/list", SightingList.as_view(), name="sighting_list"),
]
from django.contrib.auth.decorators import login_required
from django.urls import path
from django.views.generic import TemplateView
from sights.place.views import (
BridgeCreate,
BridgeDelete,
BridgeUpdate,
BuildCreate,
BuildDelete,
BuildUpdate,
CaveCreate,
CaveDelete,
CaveUpdate,
PlaceCreate,
PlaceDelete,
PlaceDetail,
PlaceList,
PlaceManagementCreate,
PlaceManagementDelete,
PlaceManagementUpdate,
PlaceMyList,
PlaceUpdate,
TreeCreate,
TreeDelete,
TreeDetail,
TreeGiteCreate,
TreeGiteDelete,
TreeGiteUpdate,
TreeUpdate,
)
urlpatterns = [
# url de recherches de localités
path("place/search", PlaceList.as_view(), name="place_search"),
# Place views
path(
"place/map",
login_required(TemplateView.as_view(template_name="sights/place_map.html")),
name="place_map",
),
path(
"place/tiledmap",
login_required(
TemplateView.as_view(template_name="sights/place_map_tiled.html")
),
name="place_tiled_map",
),
path(
"place/tilemap",
login_required(TemplateView.as_view(template_name="sights/place_tilemap.html")),
name='place_tilemap',
),
path("place/add", PlaceCreate.as_view(), name="place_create"),
path("metaplace/<int:pk>/place/add", PlaceCreate.as_view(), name="metaplace_place_create"),
path("place/<int:pk>/detail", PlaceDetail.as_view(), name="place_detail"),
path("place/<int:pk>/update", PlaceUpdate.as_view(), name="place_update"),
path("place/<int:pk>/delete", PlaceDelete.as_view(), name="place_delete"),
# Place management relative URLS
path(
"place/<int:pk>/management/add",
PlaceManagementCreate.as_view(),
name="management_create",
),
path(
"management/<int:pk>/update",
PlaceManagementUpdate.as_view(),
name="management_update",
),
path(
"management/<int:pk>/delete",
PlaceManagementDelete.as_view(),
name="management_delete",
),
# Build views
path("place/<int:pk>/build/add", BuildCreate.as_view(), name="build_create"),
path("build/<int:pk>/update", BuildUpdate.as_view(), name="build_update"),
path("build/<int:pk>/delete", BuildDelete.as_view(), name="build_delete"),
# Tree views
path("place/<int:pk>/tree/add", TreeCreate.as_view(), name="tree_create"),
path("tree/<int:pk>/update", TreeUpdate.as_view(), name="tree_update"),
path("tree/<int:pk>/delete", TreeDelete.as_view(), name="tree_delete"),
path("tree/<int:pk>/detail", TreeDetail.as_view(), name="tree_detail"),
# TreeGite views
path(
"tree/<int:pk>/treegite/add", TreeGiteCreate.as_view(), name="treegite_create"
),
path("treegite/<int:pk>/update", TreeGiteUpdate.as_view(), name="treegite_update"),
path("treegite/<int:pk>/delete", TreeGiteDelete.as_view(), name="treegite_delete"),
# Cave views
path("place/<int:pk>/cave/add", CaveCreate.as_view(), name="cave_create"),
path("cave/<int:pk>/update", CaveUpdate.as_view(), name="cave_update"),
path("cave/<int:pk>/delete", CaveDelete.as_view(), name="cave_delete"),
# Bridge views
path("place/<int:pk>/bridge/add", BridgeCreate.as_view(), name="bridge_create"),
path("bridge/<int:pk>/update", BridgeUpdate.as_view(), name="bridge_update"),
path("bridge/<int:pk>/delete", BridgeDelete.as_view(), name="bridge_delete"),
]
from django.urls import include, path
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from sights.session.views import (
SessionCreate,
SessionDetail,
SessionUpdate,
SessionDelete,
SessionMyList,
SessionChangePlaceUpdate,
DeviceCreate,
DeviceUpdate,
DeviceDelete,
)
urlpatterns = [
# Session relative URLS
path(
"place/<int:pk>/session/add",
SessionCreate.as_view(),
name="session_create",
),
path(
"session/<int:pk>/detail",
SessionDetail.as_view(),
name="session_detail",
),
path(
"session/<int:pk>/update",
SessionUpdate.as_view(),
name="session_update",
),
path(
"session/<int:pk>/change_place",
SessionChangePlaceUpdate.as_view(),
name="sessionchangeplace_update",
),
path(
"session/<int:pk>/delete",
SessionDelete.as_view(),
name="session_delete",
),
# Device relative URLS
path(
"session/<int:pk>/device/add",
DeviceCreate.as_view(),
name="device_create",
),
path(
"device/<int:pk>/update", DeviceUpdate.as_view(), name="device_update"
),
path(
"device/<int:pk>/delete", DeviceDelete.as_view(), name="device_delete"
),
]
\ No newline at end of file
from django.conf.urls import url
from django.urls import include, path
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from sights.views.countdetail import (
CountDetailCreate,
CountDetailUpdate,
CountDetailDelete,
)
from sights.views.metaplace import MetaPlaceCreate, MetaPlaceList, MetaPlaceUpdate, MetaPlaceDelete, MetaPlaceDetail
from sights.views.place import (
PlaceCreate,
PlaceUpdate,
PlaceDelete,
PlaceList,
PlaceDetail,
from sights.place.views import (
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,
from sights.session.views import (
SessionMyList,
SessionChangePlaceUpdate,
DeviceCreate,
DeviceUpdate,
DeviceDelete,
)
from sights.views.sighting import (
SightingCreate,
SightingUpdate,
SightingDelete,
SightingDetail,
SightingList,
SightingUserList,
from sights.observation.views import (
SightingMyList,
SightingUserList,
)
from sights.metaplace import urls as metaplace_urls
from sights.place import urls as place_urls
from sights.session import urls as session_urls
from sights.observation import urls as observation_urls
from sights.countdetail import urls as countdetail_urls
app_name='sights'
urlpatterns = [
# url de recherches de localités
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",
path("user/place/list", PlaceMyList.as_view(), name="place_mylist"),
path("user/session/list", SessionMyList.as_view(), name="session_mylist"),
path("user/sighting/list", SightingMyList.as_view(), name="sighting_mylist"),
path(
"user/<int:pk>/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"^metaplace/add$", MetaPlaceCreate.as_view(), name="metaplace_create"),
url(r"^metaplace/search$", MetaPlaceList.as_view(), name="metaplace_search"),
url(r"^metaplace/(?P<pk>\d+)/detail$", MetaPlaceDetail.as_view(), name="metaplace_detail"),
url(r"^metaplace/(?P<pk>[0-9]+)/update$", MetaPlaceUpdate.as_view(), name="metaplace_update"),
url(r"^metaplace/(?P<pk>[0-9]+)/delete$", MetaPlaceDelete.as_view(), name="metaplace_delete"),
url(r"^metaplace/(?P<pk>[0-9]+)/place/add$", PlaceCreate.as_view(), name="metaplace_place_create"),
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",
),
# 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"),
# 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"),
# 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",
),
# 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"),
# 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"
),
# 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",
),
# 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"
),
# 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"),
# 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",
),
path("", include(metaplace_urls)),
path("", include(place_urls)),
path("", include(session_urls)),
path("", include(observation_urls)),
path("", include(countdetail_urls))
]
"""
Vues de l'application Sights
"""
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db import IntegrityError
from django.http import HttpResponseRedirect
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 ..forms import (
BridgeForm,
)
from ..mixins import (