Exemplo n.º 1
0
 def post(self, request, format=None):
     serializer = serializers.MessagePreviewSerializer(data=request.DATA,
                                                       files=request.FILES)
     if serializer.is_valid():
         message_preview = serializer.object
         message_preview.user = request.user if not LEBOWSKI_MODE_TEST else models.User.objects.get(
             email=request.DATA.get('email'))
         message_preview.save()
         if message_preview.text is not None:
             if message_preview.text != '':
                 categories = categorization_service.detect_categories(
                     message_preview.text)
                 message_preview.categories.clear()
                 for category in categories:
                     message_preview.categories.add(category)
             #categorization_service.assert_stems(message_preview)
         #dima, what for next 3strings?
         serialized_preview = serializers.MessagePreviewSerializer(
             instance=message_preview).data
         root_url = reverse('client-index', request=request)
         serialized_preview[
             'photo'] = message_preview.get_photo_absolute_urls(root_url)
         return sz_api_response.Response(serializer.data,
                                         status=status.HTTP_201_CREATED)
     return sz_api_response.Response(serializer.errors,
                                     status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
 def post(self, request, format=None):
     serializer = serializers.MessagePreviewSerializer(data=request.DATA, files=request.FILES)
     if serializer.is_valid():
         message_preview = serializer.object
         message_preview.user = request.user
         message_preview.save()
         if message_preview.text is not None:
             if message_preview.text != '':
                 categories = categorization_service.detect_categories(message_preview.text)
                 message_preview.categories.clear()
                 for category in categories:
                     message_preview.categories.add(category)
             #categorization_service.assert_stems(message_preview)
         serialized_preview = serializers.MessagePreviewSerializer(instance=message_preview).data
         root_url = reverse('client-index', request=request)
         serialized_preview['photo'] = message_preview.get_photo_absolute_urls(root_url)
         return sz_api_response.Response(serializer.data, status=status.HTTP_201_CREATED)
     return sz_api_response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
 def get(self, request, format=None):
     params = self.validate_and_get_params(forms.CategoriesDetectingRequestForm, request.QUERY_PARAMS)
     categories = categorization_service.detect_categories(params['text'])
     serializer = serializers.CategorySerializer(instance=categories)
     return sz_api_response.Response(serializer.data)