Ejemplo n.º 1
0
 def get(self, request, occurrence_maincat, pk, version, format=None):
     try:
         (is_writer,
          is_publisher) = get_permissions(request.user, occurrence_maincat)
         instance = get_occurrence_model(occurrence_maincat).objects.get(
             pk=pk)
         serializer = OccurrenceVersionSerializer()
         excude_unreleased = not (is_writer or is_publisher)
         serialized_feature = serializer.get_version(
             instance, int(version), excude_unreleased)
         if serialized_feature.get('released',
                                   False) == False and excude_unreleased:
             return Response(
                 {
                     _("error"):
                     _("You don't have permissions to access the occurrence"
                       )
                 },
                 status=status.HTTP_403_FORBIDDEN)
         if isinstance(serialized_feature, OccurrenceNaturalArea):
             return Response({"error": "not supported yet"})
         serialized_feature['featuretype'] = occurrence_maincat
         serialized_feature['featuresubtype'] = instance.occurrence_cat.code
         return Response(serialized_feature)
     except ObjectDoesNotExist:
         raise
Ejemplo n.º 2
0
 def get_serializer(self,
                    instance=None,
                    data=empty,
                    many=False,
                    partial=False):
     #return super(NfdLayerListNew, self).get_serializer(instance=instance, data=data, many=many, partial=partial)
     (is_writer, is_publisher) = get_permissions(self.request.user,
                                                 self.get_main_cat())
     if self.request.method == 'POST':
         if data is not empty:
             serializer_class = self.get_post_serializer_class()
             return serializer_class(data=data,
                                     is_writer=is_writer,
                                     is_publisher=is_publisher)
         else:
             is_writer_or_publisher = (is_writer or is_publisher)
             return LayerSerializer(
                 data=data,
                 many=many,
                 is_writer_or_publisher=is_writer_or_publisher)
     else:
         is_writer_or_publisher = (is_writer or is_publisher)
         serializer_class = self.get_serializer_class()
         return serializer_class(
             instance,
             many=many,
             is_writer_or_publisher=is_writer_or_publisher)
Ejemplo n.º 3
0
 def get_queryset(self):
     (is_writer, is_publisher) = get_permissions(self.request.user,
                                                 self.get_main_cat())
     queryset = self.get_base_queryset()
     is_writer_or_publisher = (is_writer or is_publisher)
     if not is_writer_or_publisher:
         queryset = queryset.filter(released=True)
     return queryset
Ejemplo n.º 4
0
 def get_serializer(self,
                    instance=None,
                    data=empty,
                    many=False,
                    partial=False):
     (is_writer, is_publisher) = get_permissions(self.request.user,
                                                 self.get_main_cat())
     is_writer_or_publisher = (is_writer or is_publisher)
     serializer_class = self.get_serializer_class()
     return serializer_class(instance,
                             many=many,
                             is_writer_or_publisher=is_writer_or_publisher)
Ejemplo n.º 5
0
def get_feature_type(request, occurrence_subcat, feature_id=None):
    if feature_id:
        if occurrence_subcat[0] == 'n':  # natural areas
            feat = OccurrenceNaturalArea.objects.get(pk=feature_id)
        else:
            feat = OccurrenceTaxon.objects.get(pk=feature_id)
        serializer = FeatureTypeSerializer(feat.occurrence_cat)
    else:
        # in this case we get the category code instead of the main category
        occurrence_cat = OccurrenceCategory.objects.get(code=occurrence_subcat)
        (is_writer, is_publisher) = get_permissions(request.user,
                                                    occurrence_cat.main_cat)
        serializer = FeatureTypeSerializer(occurrence_cat,
                                           is_writer=is_writer,
                                           is_publisher=is_publisher)
    ftdata = serializer.get_feature_type()
    return Response(ftdata)
Ejemplo n.º 6
0
 def put(self, request, occurrence_maincat, pk, format=None):
     (is_writer, is_publisher) = get_permissions(request.user,
                                                 occurrence_maincat)
     feature = self.get_object(occurrence_maincat, pk)
     if isinstance(feature, OccurrenceNaturalArea):
         serializer = NaturalAreaOccurrenceSerializer(
             feature,
             data=request.data,
             is_writer=is_writer,
             is_publisher=is_publisher)
     else:
         serializer = TaxonOccurrenceSerializer(feature,
                                                data=request.data,
                                                is_writer=is_writer,
                                                is_publisher=is_publisher)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 7
0
 def get(self, request, occurrence_maincat, pk, format=None):
     (is_writer, is_publisher) = get_permissions(request.user,
                                                 occurrence_maincat)
     feature = self.get_object(occurrence_maincat, pk)
     if feature.released == False and not (is_writer or is_publisher):
         return Response(
             {
                 _("error"):
                 _("You don't have permissions to access the occurrence")
             },
             status=status.HTTP_403_FORBIDDEN)
     if isinstance(feature, OccurrenceNaturalArea):
         serializer = NaturalAreaOccurrenceSerializer(
             feature, is_writer=is_writer, is_publisher=is_publisher)
     else:
         serializer = TaxonOccurrenceSerializer(feature,
                                                is_writer=is_writer,
                                                is_publisher=is_publisher)
     return Response(serializer.data)