Ejemplo n.º 1
0
 def _get_queryset_query_string(self, queryset):
     if isinstance(queryset, EmptyQuerySet):
         return None
     else:
         try:
             return force_text(queryset.query.__str__())
         except EmptyResultSet:
             return None
Ejemplo n.º 2
0
 def _get_queryset_query_string(self, queryset):
     if isinstance(queryset, EmptyQuerySet):
         return None
     else:
         try:
             return force_text(queryset.query.__str__())
         except EmptyResultSet:
             return None
Ejemplo n.º 3
0
 def get_data(self, params, view_instance, view_method, request, args,
              kwargs):
     if hasattr(
             request,
             'user') and request.user and request.user.is_authenticated():
         return force_text(self._get_id_from_user(request.user))
     else:
         return u'anonymous'
Ejemplo n.º 4
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     lookup_value = view_instance.kwargs[view_instance.lookup_field]
     try:
         queryset = view_instance.filter_queryset(view_instance.get_queryset()).filter(
             **{view_instance.lookup_field: lookup_value}
         )
         if isinstance(queryset, EmptyQuerySet):
             return None
         else:
             return force_text(queryset.query.__str__())
     except ValueError:
         return None
Ejemplo n.º 5
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     data = {}
     source_dict = self.get_source_dict(
         params=params,
         view_instance=view_instance,
         view_method=view_method,
         request=request,
         args=args,
         kwargs=kwargs
     )
     for key in params:
         value = source_dict.get(self.prepare_key_for_value_retrieving(key))
         if value is not None:
             data[self.prepare_key_for_value_assignment(key)] = force_text(value)
     return data
Ejemplo n.º 6
0
 def partial_update_bulk(self, request, *args, **kwargs):
     is_valid, errors = self.is_valid_bulk_operation()
     if is_valid:
         queryset = self.filter_queryset(self.get_queryset())
         update_bulk_dict = self.get_update_bulk_dict(serializer=self.get_serializer_class()(), data=request.data)
         self.pre_save_bulk(queryset, update_bulk_dict)  # todo: test and document me
         try:
             queryset.update(**update_bulk_dict)
         except ValueError as e:
             errors = {"detail": force_text(e)}
             return Response(errors, status=status.HTTP_400_BAD_REQUEST)
         self.post_save_bulk(queryset, update_bulk_dict)  # todo: test and document me
         return Response(status=status.HTTP_204_NO_CONTENT)
     else:
         return Response(errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 7
0
 def partial_update_bulk(self, request, *args, **kwargs):
     is_valid, errors = self.is_valid_bulk_operation()
     if is_valid:
         queryset = self.filter_queryset(self.get_queryset())
         update_bulk_dict = self.get_update_bulk_dict(
             serializer=self.get_serializer_class()(), data=request.DATA)
         self.pre_save_bulk(queryset,
                            update_bulk_dict)  # todo: test and document me
         try:
             queryset.update(**update_bulk_dict)
         except ValueError as e:
             errors = {'detail': force_text(e)}
             return Response(errors, status=status.HTTP_400_BAD_REQUEST)
         self.post_save_bulk(queryset,
                             update_bulk_dict)  # todo: test and document me
         return Response(status=status.HTTP_204_NO_CONTENT)
     else:
         return Response(errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 8
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     return force_text(get_language())
Ejemplo n.º 9
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     if hasattr(request, 'user') and request.user and request.user.is_authenticated():
         return force_text(self._get_id_from_user(request.user))
     else:
         return u'anonymous'
Ejemplo n.º 10
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     return force_text(request.accepted_renderer.format)
Ejemplo n.º 11
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     return force_text(request.accepted_renderer.format)
Ejemplo n.º 12
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     return force_text(get_language())
Ejemplo n.º 13
0
 def get_data(self, params, view_instance, view_method, request, args, kwargs):
     queryset = view_instance.filter_queryset(view_instance.get_queryset())
     if isinstance(queryset, EmptyQuerySet):
         return None
     else:
         return force_text(queryset.query.__str__())
Ejemplo n.º 14
0
 def test_should_return_response(self):
     resp = self.client.get('/hello/')
     self.assertEqual(force_text(resp.content), '"Hello world"')