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)
def handle_exception(self, exc): if isinstance(exc, InvalidRequestException): return sz_api_response.Response(self.request_form_errors, status=status.HTTP_400_BAD_REQUEST) base_response = APIView.handle_exception(self, exc) return sz_api_response.Response(base_response.data, status=base_response.status_code)
def get(self, request, format=None): if not LEBOWSKI_MODE_TEST: return sz_api_response.Response( {'data': 'LEBOWSKI_MODE_TEST is off'}) if shelve.open('generated_place.shelve'): for p in shelve.open('generated_place.shelve')['venues']: model_p.filter(**get_params(p)).delete() del shelve.open('generated_place.shelve')['venues'] list_len = int(request.QUERY_PARAMS.get('count', 100)) data = map(place_serializers, generate_places(list_len=list_len)) shelve.open('generated_place.shelve')['venues'] = data return sz_api_response.Response({'venues': data})
def put(self, request, pk, format=None): message_preview = self.get_object(pk) user = request.user if not LEBOWSKI_MODE_TEST else request.DATA.get( 'email') if message_preview.user != user: return sz_api_response.Response(status=status.HTTP_403_FORBIDDEN) serializer = serializers.MessagePreviewSerializer(message_preview, data=request.DATA, files=request.FILES) if serializer.is_valid(): serializer.save() return sz_api_response.Response(serializer.data) else: return sz_api_response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, pk, format=None): message_preview = self.get_object(pk) user = request.user if not LEBOWSKI_MODE_TEST else request.QUERY_PARAMS.get( 'email') if message_preview.user != user: return sz_api_response.Response(status=status.HTTP_403_FORBIDDEN) serializer = serializers.MessagePreviewSerializer( instance=message_preview) place_serializer = serializers.PlaceSerializer( instance=message_preview.place) data = serializer.data root_url = reverse('client-index', request=request) data['photo'] = message_preview.get_photo_absolute_urls_and_size( root_url) data['place'] = place_serializer.data return sz_api_response.Response(data)
def get(self, request, format=None): params = self.validate_and_get_params(forms.PlaceExploreRequestForm, request.QUERY_PARAMS) params[u'creator'] = request.user.email if not LEBOWSKI_MODE_TEST \ else request.QUERY_PARAMS.get('email') place_response = map(self._serialize_item, place_service.explore_in_venues(**params)) data = dict(places=place_response) if place_response: #@TODO - change it when bl will be answer normal stuff engina_data = lebowski_places.PlacesCreate().create(place_response) if LEBOWSKI_MODE_TEST: data['bl'] = engina_data status = 200 else: status = engina_data['status'] return sz_api_response.Response(data, status=status) return sz_api_response.Response(data)
def get(self, request, format=None): params = self.validate_and_get_params(forms.NewsRequestForm, request.QUERY_PARAMS) news_feed = news_feed_service.get_news(**params) photo_host = reverse('client-index', request=request) response_builder = sz_api_response.NewsFeedResponseBuilder( photo_host, request) serialized_news_feed = response_builder.build(news_feed) return sz_api_response.Response(serialized_news_feed)
def get(self, request, format=None): params = self.validate_and_get_params(forms.PlaceSearchRequestForm, request.QUERY_PARAMS) params['user'] = request.user.email places_list = place_service.search_in_venue(**params) place_response = dict( map( lambda (k, places): (k, map(lambda p: self._serialize_item(p), places)), places_list.items())) return sz_api_response.Response(place_response)
def get(self, request, format=None): return sz_api_response.Response({ 'static': { 'static_categories': reverse('static-categories', request=request), 'static_races': reverse('static-races', request=request), 'static_genders': reverse('static-genders', request=request), 'static_faces': reverse('static-faces', request=request), # 'categories': reverse('category-list', request=request), }, 'test_mode': { 'generate_places': reverse('generate-places', request=request), 'testmode_places': reverse('testmode-places', request=request), }, 'place': { 'places_news': reverse('place-news', request=request), 'places_search_in_venues': reverse('place-search-in-venues', request=request), 'places_explore_in_venues': reverse('place-explore-in-venues', request=request), # 'places-search': reverse('place-search', request=request), }, 'user': { 'login': reverse('auth-login', request=request), 'logout': reverse('auth-logout', request=request), 'current_user': reverse('auth-user', request=request), 'users_registration': reverse('users-registration', request=request), # 'users-resending-activation-key': reverse('users-resending-activation-key', request=request), # 'users-profile': reverse('users-profile', request=request), }, 'message': { 'messages_previews': reverse('message-preview-list', request=request), # 'messages-search': reverse('message-search', request=request), }, # 'city-nearest': reverse('city-nearest', request=request), })
def get(self, request, format=None): places_list = shelve.open('generated_place.shelve')['venues'] data = {'venues': shelve.open('generated_place.shelve')['venues']} return sz_api_response.Response(data)
def get(self, request,format=None): objects = self.get_object() root_url = reverse('client-index', request=request) data = [self.get_data(obj,root_url) for obj in objects] return sz_api_response.Response({'data':data})
def delete(self, request, pk, format=None): return sz_api_response.Response()
def get(self, request, format=None): user = request.user if not LEBOWSKI_MODE_TEST else request.QUERY_PARAMS.get( 'email') previews = models.MessagePreview.objects.filter(user=request.user) serializer = serializers.MessagePreviewSerializer(instance=previews) return sz_api_response.Response(serializer.data)
def post(self, request, pk, format=None): message_preview = self.get_object(pk) user = request.user if not LEBOWSKI_MODE_TEST else models.User.objects.get( email=request.DATA.get('email')) if message_preview.user != user: return sz_api_response.Response(status=status.HTTP_403_FORBIDDEN) serializer = serializers.MessagePreviewForPublicationSerializer( message_preview, data=request.DATA) if serializer.is_valid(): face = self.get_face(request.DATA[u'face']) photo = message_preview.photo if photo: faces_list = request.DATA[ u'photo'] #??!! не уверена нужно это все перепроверять if not faces_list or \ not faces_list.get('list') or \ not faces_list.get('box') or \ not faces_list['box'].get('face'): return sz_api_response.Response( {'faces and box is requered fields'}, status=status.HTTP_400_BAD_REQUEST) photo = message_service.unface_photo(faces_list.get('list'), faces_list.get('box'), message_preview) if not photo: return sz_api_response.Response( {'faces was not added to photo'}, status=status.HTTP_400_BAD_REQUEST) serializer.save() message = models.Message(text=message_preview.text, photo=photo, place=message_preview.place, face=face, user=message_preview.user) message.save() for category in message_preview.categories.all(): message.categories.add(category) message_preview.delete() categorization_service.assert_stems(message) #next string need to change on lebowski answer message_serializer = serializers.MessageSerializer( instance=message) place_serializer = serializers.PlaceSerializer( instance=message.place) user_serializer = serializers.UserSerializer(instance=message.user) user_data = dict( user_serializer.data, **{ "latitude": request.DATA.get('latitude', 0), "longitude": request.DATA.get('longitude', 0) }) # data = message_serializer.data engine_data = lebowski_messages.MessagesCreate().create({ 'message': message_serializer.data, 'place': place_serializer.data, 'creator': user_data }) root_url = reverse('client-index', request=request) data = dict(photo=message.get_photo_absolute_urls(root_url), place=place_serializer.data) if LEBOWSKI_MODE_TEST: data['bl'] = engine_data else: data.update(**engine_data) print data return sz_api_response.Response(data) else: return sz_api_response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)