Commit 287b6757 authored by hypsug0's avatar hypsug0
Browse files

fix: Edit sighting permissions

parent 7bdca784
......@@ -566,7 +566,8 @@ class SightingFilteringMixin:
"""Mixin used for Sighting lists filtering"""
def get_queryset(self, *args, **kwargs):
qs = Sighting.objects
qs = super().get_queryset()
# qs = Sighting.objects
municipality = self.request.query_params.get("municipality", None)
name = self.request.query_params.get("name", None)
......@@ -693,7 +694,7 @@ class SightingListPermissionsMixin(object):
"""Mixin used for Sighting lists permissions"""
def get_queryset(self, *args, **kwargs):
qs = super(SightingListPermissionsMixin, self).get_queryset()
qs = super().get_queryset()
logged_user = self.request.user
user = get_user_model().objects.get(id=logged_user.id)
......@@ -776,7 +777,7 @@ class SightingListPermissionsMixin(object):
class SightingFilteredListWithPermissions(
SightingListPermissionsMixin,
SightingFilteringMixin,
SightingListPermissionsMixin,
):
pass
......@@ -18,6 +18,7 @@ from sights.observation.serializers import (
GeoSightingSerializer,
)
from ..mixins import SightingListPermissionsMixin
from .permissions import SightingEditPermission
# from rest_framework.permissions import IsAuthenticated
......@@ -32,11 +33,12 @@ class GeoJSONSighting(
SightingFilteredListWithPermissions,
ListAPIView,
):
queryset = Sighting.objects.all()
serializer_class = GeoSightingSerializer
pagination_class = LargeGeoJsonPageNumberPagination
def get_queryset(self, *args, **kwargs):
qs = super(GeoJSONSighting, self).get_queryset()
qs = super().get_queryset()
qs = qs.select_related("created_by", "codesp", "session",).prefetch_related(
Prefetch("session__contact"),
......@@ -48,19 +50,22 @@ class GeoJSONSighting(
return qs.distinct().order_by("-timestamp_update")
class EditSighting(ModelViewSet):
class EditSighting(SightingListPermissionsMixin, ModelViewSet):
serializer_class = EditSightingSerializerTest
permission_classes = [
IsAuthenticated,
SightingEditPermission,
]
def get_queryset(self):
queryset = Sighting.objects.all()
def get_queryset(self, *args, **kwargs):
qs = super().get_queryset()
if self.action in ("list", "create"):
session = self.kwargs["session"]
qs = Sighting.objects.filter(session=session)
qs = qs.filter(session=session)
else:
qs = Sighting.objects.all()
qs = qs.all()
return qs
def perform_create(self, serializer):
......@@ -76,72 +81,72 @@ class DeleteSighting(mixins.DestroyModelMixin, GenericViewSet):
# permission_class = [IsAuthenticated]
class SessionCountDetailsListView(ModelViewSet):
permission_classes = (AllowAny,)
serializer_class = CountDetailSerializer
def get_queryset(self):
logger.debug(f"CALL QUERY {self}")
print(f"CALL QUERY {self}")
if self.action == "list":
session = self.kwargs["session"]
return CountDetail.objects.filter(sighting__session=session)
else:
return CountDetail.objects.all()
def perform_create(self, serializer):
logger.debug(f"USERRRR {self.request.user} {type(self.request.user)}")
serializer.save(created_by=self.request.user)
def perform_update(self, serializer):
logger.debug(f"USERRRR {self.request.user} {type(self.request.user)}")
serializer.save(updated_by=self.request.user)
# def get_serializer_class(self):
# return CountDetailSerializer
# def list(self, request, session):
# # session = self.kwargs["session"]
# logger.debug(f"<SessionCountDetailsListView.list>")
# q = CountDetail.objects.filter(sighting__session=session)
# serializer = CountDeta(q, many=True)
# logger.debug(f"A {CountDetailBaseSerializer.Meta.fields}")
# logger.debug(f"B {serializer.data}")
# logger.debug(f"C {q.all()}")
# return Response(serializer.data)
# def create(self, request, session):
# logger.debug(f"<SessionCountDetailsListView.create>")
# logger.debug(f"request {request.data}")
# for cd in request.data:
# taxa = cd.pop("taxa")
# cd.pop("sighting")
# cd.pop("session")
# obj, created = Sighting.objects.get_or_create(codesp=taxa, session=session)
# logger.debug(f"sighting {type(obj)}")
# cd["sighting"] = obj.id_sighting
# s = CountDetailSerializer(data=cd)
# s.is_valid()
# logger.debug(s.data)
# logger.debug(s.errors)
# CountDetail.save(**s.data)
# serializer = CountDetailSerializer(self.get_queryset(), many=True)
# return Response(serializer.data)
# # def retrieve(self, request, pk=None):
# # logger.debug(f"<SessionCountDetailsListView.retrieve>")
# # pass
# def update(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.update>")
# pass
# def partial_update(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.partial_update>")
# pass
# def destroy(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.destroy>")
# pass
# class SessionCountDetailsListView(ModelViewSet):
# permission_classes = (AllowAny,)
# serializer_class = CountDetailSerializer
# def get_queryset(self):
# logger.debug(f"CALL QUERY {self}")
# print(f"CALL QUERY {self}")
# if self.action == "list":
# session = self.kwargs["session"]
# return CountDetail.objects.filter(sighting__session=session)
# else:
# return CountDetail.objects.all()
# def perform_create(self, serializer):
# logger.debug(f"USERRRR {self.request.user} {type(self.request.user)}")
# serializer.save(created_by=self.request.user)
# def perform_update(self, serializer):
# logger.debug(f"USERRRR {self.request.user} {type(self.request.user)}")
# serializer.save(updated_by=self.request.user)
# def get_serializer_class(self):
# return CountDetailSerializer
# def list(self, request, session):
# # session = self.kwargs["session"]
# logger.debug(f"<SessionCountDetailsListView.list>")
# q = CountDetail.objects.filter(sighting__session=session)
# serializer = CountDeta(q, many=True)
# logger.debug(f"A {CountDetailBaseSerializer.Meta.fields}")
# logger.debug(f"B {serializer.data}")
# logger.debug(f"C {q.all()}")
# return Response(serializer.data)
# def create(self, request, session):
# logger.debug(f"<SessionCountDetailsListView.create>")
# logger.debug(f"request {request.data}")
# for cd in request.data:
# taxa = cd.pop("taxa")
# cd.pop("sighting")
# cd.pop("session")
# obj, created = Sighting.objects.get_or_create(codesp=taxa, session=session)
# logger.debug(f"sighting {type(obj)}")
# cd["sighting"] = obj.id_sighting
# s = CountDetailSerializer(data=cd)
# s.is_valid()
# logger.debug(s.data)
# logger.debug(s.errors)
# CountDetail.save(**s.data)
# serializer = CountDetailSerializer(self.get_queryset(), many=True)
# return Response(serializer.data)
# # def retrieve(self, request, pk=None):
# # logger.debug(f"<SessionCountDetailsListView.retrieve>")
# # pass
# def update(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.update>")
# pass
# def partial_update(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.partial_update>")
# pass
# def destroy(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.destroy>")
# pass
from django.urls import path
from sights.observation.api import EditSighting, GeoJSONSighting, SessionCountDetailsListView
from sights.observation.api import EditSighting, GeoJSONSighting
from sights.observation.views import (
SightingCreate,
SightingDelete,
......@@ -46,10 +46,10 @@ urlpatterns = [
EditSighting.as_view({"delete": "destroy"}),
name="delete_observation_api",
),
path(
"api/v1/countdetails/<int:pk>",
SessionCountDetailsListView.as_view({"get": "retrieve"}),
name="count_detail_retrieve_api",
),
# path(
# "api/v1/countdetails/<int:pk>",
# SessionCountDetailsListView.as_view({"get": "retrieve"}),
# name="count_detail_retrieve_api",
# ),
path("sighting/search", SightingSearch.as_view(), name="sighting_search"),
]
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