Ejemplo n.º 1
0
class PublicProfileSerializer(serializers.Serializer):
    phones = PublicPhoneSerializer(many=True, read_only=True)
    albums = AlbumSerializer(many=True, read_only=True)
    profile_photo = PhotoSerializer(read_only=True)
    cover_photo = PhotoSerializer(read_only=True)
    username = serializers.CharField(max_length=32)
    first_name = serializers.CharField(max_length=32)
    last_name = serializers.CharField(max_length=32)
    gender = GenderSerializer(read_only=True)
    user_type = serializers.IntegerField()
Ejemplo n.º 2
0
 def get(self, request, *args, **kwargs):
     profile = request.user.base_profile()
     album = profile.get_profile_album()
     if album:
         serializer = PhotoSerializer(album.album_photos.all(), many=True)
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(None, status=status.HTTP_404_NOT_FOUND)
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        try:
            photo = get_object_or_404(Photo, pk=request.GET.get('photo', None))
        except AttributeError:
            return Response("Not found", status=status.HTTP_404_NOT_FOUND)

        # auth check
        if not photo.album.verify_ownership(request.user):
            return Response("Unauthorized access", status=status.HTTP_401_UNAUTHORIZED)
        # /auth check

        result = photo.set_primary_photo()
        if result:
            retstatus = status.HTTP_200_OK
            result = PhotoSerializer(result).data
        else:
            retstatus = status.HTTP_500_INTERNAL_SERVER_ERROR
        retval = photo_save_template(**{
            'as_json': False,
            'status': retstatus,
            'result': result,
            'request': request
        })

        return Response(retval, status=retstatus)
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        photo = request.user.base_profile().get_profile_photo(return_null=True)

        if photo:
            # auth check
            if not photo.album.verify_ownership(request.user):
                return Response("Unauthorized access", status=status.HTTP_401_UNAUTHORIZED)
            # /auth check

            result = photo.unset_primary_photo()
            if result:
                retstatus = status.HTTP_200_OK
                result = PhotoSerializer(result).data
            else:
                retstatus = status.HTTP_500_INTERNAL_SERVER_ERROR
            retval = photo_save_template(**{
                'as_json': False,
                'status': retstatus,
                'result': "Primary photo unset",
                'request': request
            })

            return Response(retval, status=retstatus)

        return Response(photo_save_template(**{
            'as_json': False,
            'status': status.HTTP_404_NOT_FOUND,
            'result': "No photo set",
            'request': request
        }))
Ejemplo n.º 5
0
 def get(self, request, name):
     album = self.get_object(name)
     try:
         photos = Photo.objects.filter(album=album).order_by('tweet_id')
         serializer = PhotoSerializer(photos, many=True)
         return Response(serializer.data)
     except:
         raise Http404
Ejemplo n.º 6
0
    def save_tweets(self, tweets, album, data):
        for idx, item in enumerate(tweets["statuses"]):
            print "==> Fetching Tweet", idx

            if item["entities"].get("media"):
                try:
                    user = User.objects.get(twitter_id=item["user"]["id"])
                    print "Load User:"******"twitter_id": item["user"]["id"],
                            "username": item["user"]["screen_name"],
                            "profile_image_url": item["user"]
                            ["profile_image_url"]
                        })
                    if user.is_valid():
                        user = user.save()
                        print "User saved successfully!", user
                    else:
                        print "Error Saving User", user.errors
                        pass

                photo = PhotoSerializer(
                    data={
                        "tweet_id": item["id"],
                        "tweet_text": item["text"],
                        "tweet_likes": item["favorite_count"],
                        "image_url": item["entities"]["media"][0]["media_url"],
                        "user": user.id,
                        "album": album.id
                    })
                if photo.is_valid():
                    photo = photo.save()
                    if (data['photo_count'] + idx + 1) == data['photo_limit']:
                        # TODO: Send Email w/ worker job
                        print "!!!! ======= SEND EMAIL ========= !!!!"

                    print "Photo saved successfully!", photo.image_url
                else:
                    print "Error saving Photo -> ", photo.errors
                    pass
            else:
                print "MEDIA NOT FOUND! WTF?"
                print item["entities"]
Ejemplo n.º 7
0
def album_with_photos_template(album, photos, as_json=False):
    obj = {
        'pk': album.pk,
        'slug': album.slug,
        'name': album.name,
        'description': album.description,
        'is_public': album.is_public,
        'album_type': album.album_type,
        'photos': list(PhotoSerializer(photos, many=True).data)
    }

    if as_json:
        return json.dumps(obj)
    return obj
Ejemplo n.º 8
0
    def post(self, request, *args, **kwargs):

        album = get_object_or_404(Album,
                                  pk=request.GET.get('album', None),
                                  profile=request.user.base_profile())

        # auth check
        if not album.verify_ownership(request.user):
            return Response("Unauthorized access",
                            status=status.HTTP_401_UNAUTHORIZED)
        # /auth check

        serializer = PhotoUploadSerializer(data=request.data)

        if serializer.is_valid():
            photo = serializer.save()
            photo.album = album
            photo.save()
            photo.set_primary_photo()

            response_data = save_template(
                **{
                    'as_json': False,
                    'status': status.HTTP_200_OK,
                    'request': request,
                    'result': PhotoSerializer(photo).data
                })
            return Response(response_data, status=status.HTTP_200_OK)
        else:
            response_data = save_template(
                **{
                    'as_json': False,
                    'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
                    'request': request,
                    'result': serializer.errors
                })
            return Response(response_data,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 9
0
    def get(self, request, *args, **kwargs):
        album = get_object_or_404(Album, id=request.GET.get('id', None))

        serializer = PhotoSerializer(album.get_public_photos(), many=True)

        return Response(serializer.data, status=status.HTTP_200_OK)