Exemplo n.º 1
0
    def handle(self, *args, **options):
        from picupwebapp.picture.models  import Picture
        from picupwebapp.picprofile.models  import PicupProfile, get_or_create_profile
        from django.contrib.auth.models import User

        users = User.objects.all()

        karma_all = {}
        for user in users:
            picup_profile = get_or_create_profile(user)
            karma = 0
            number_of_pictures = Picture.objects.filter(user=user).count()
            karma += number_of_pictures * 5
            number_of_pictures_galleries = Picture.objects.filter(user=user).exclude(gallery=None).count()
            karma += number_of_pictures_galleries * 1

            if user.id < 10:
                karma += 200
            elif user.id < 20:
                karma += 100
            elif user.id < 100:
                karma += 50
            elif user.id < 1000:
                karma += 25

            print user.email, number_of_pictures, number_of_pictures_galleries
            karma_all[user.id]  = {'username':user.email, 'points':karma}
            picup_profile.karma = karma
            picup_profile.save()
        print karma_all
Exemplo n.º 2
0
    def mobile_persona_int(request, backend="persona", *args, **kwargs):
        assertion = request.POST["assertion"]
        errors = []
        api_key = None
        user_id = 0
        try:
            do_complete(request.social_strategy, _do_login, request.user, redirect_name="", *args, **kwargs)
            picup_profile = get_or_create_profile(request.user)
            api_key = picup_profile.api_key
            user_id = picup_profile.user.id
        except Exception as e:
            import traceback

            traceback.print_exc()
            errors.append(["auth_failed"])
        response = requests.post("https://browserid.org/verify", data={"assertion": assertion, "audience": "picup.it"})
        response_json = json.loads(response.text)
        response_json["errors"] = errors

        if api_key:
            response_json["api_key"] = api_key

        if user_id > 0:
            response_json["user_id"] = user_id

        response_json = json.dumps(response_json)
        my_response = MyResponse()
        my_response.text = response_json

        return my_response
Exemplo n.º 3
0
def accounts_profile(request):
    """User's profile edit view.
    """

    if request.GET.has_key("next"):
        if request.GET["next"] == "ffos":
            return redirect("/mobile/ffoslogged/")
        elif request.GET["next"] == "ffosdata":
            return redirect("/mobile/data/")

    pictures_all = Picture.objects.filter(user=request.user, gallery=None)
    gravatar_url = get_gravatar_url(request.user.email)
    galleries = get_user_galleries(request.user, False)

    picup_profile = get_or_create_profile(request.user)

    return render(
        request,
        "profile.html",
        {
            "pictures_all": pictures_all,
            "gravatar_url": gravatar_url,
            "galleries": galleries,
            "picup_profile": picup_profile,
        },
    )
Exemplo n.º 4
0
    def handle(self, *args, **options):
        from picupwebapp.picture.models import Picture
        from picupwebapp.picprofile.models import PicupProfile, get_or_create_profile
        from django.contrib.auth.models import User

        users = User.objects.all()

        karma_all = {}
        for user in users:
            picup_profile = get_or_create_profile(user)
            karma = 0
            number_of_pictures = Picture.objects.filter(user=user).count()
            karma += number_of_pictures * 5
            number_of_pictures_galleries = Picture.objects.filter(
                user=user).exclude(gallery=None).count()
            karma += number_of_pictures_galleries * 1

            if user.id < 10:
                karma += 200
            elif user.id < 20:
                karma += 100
            elif user.id < 100:
                karma += 50
            elif user.id < 1000:
                karma += 25

            print user.email, number_of_pictures, number_of_pictures_galleries
            karma_all[user.id] = {'username': user.email, 'points': karma}
            picup_profile.karma = karma
            picup_profile.save()
        print karma_all
Exemplo n.º 5
0
def mobile_data(request):
    """Mobile data view.
    """
    picup_profile = get_or_create_profile(request.user)
    data = {}
    data["email"] = request.user.email
    data["api_key"] = picup_profile.api_key
    return HttpResponse(json.dumps(data), content_type="application/json")
Exemplo n.º 6
0
def mobile_data(request):
    """Mobile data view.
    """
    picup_profile = get_or_create_profile(request.user)
    data = {}
    data['email'] = request.user.email
    data['api_key'] = picup_profile.api_key
    return HttpResponse(json.dumps(data), content_type='application/json')
Exemplo n.º 7
0
def picup_profile(request):
	"""Picup profile context processor.
	
	Note
	----
	Adds gravatar url and few other other variables.
	"""
	user = request.user
	result = {}
	if user.is_authenticated():
		result['gravatar_url'] = get_gravatar_url(user.email)
		result['auth_picup_profile'] = get_or_create_profile(user)
	else:
		result['auth_picup_profile'] = None
	return result
Exemplo n.º 8
0
def picup_profile(request):
    """Picup profile context processor.
	
	Note
	----
	Adds gravatar url and few other other variables.
	"""
    user = request.user
    result = {}
    if user.is_authenticated():
        result['gravatar_url'] = get_gravatar_url(user.email)
        result['auth_picup_profile'] = get_or_create_profile(user)
    else:
        result['auth_picup_profile'] = None
    return result
Exemplo n.º 9
0
    def mobile_persona_int(request, backend='persona', *args, **kwargs):
        assertion = request.POST['assertion']
        errors = []
        api_key = None
        user_id = 0
        try:
            do_complete(request.social_strategy,
                        _do_login,
                        request.user,
                        redirect_name='',
                        *args,
                        **kwargs)
            picup_profile = get_or_create_profile(request.user)
            api_key = picup_profile.api_key
            user_id = picup_profile.user.id
        except Exception as e:
            import traceback
            traceback.print_exc()
            errors.append(['auth_failed'])
        response = requests.post('https://browserid.org/verify',
                                 data={
                                     'assertion': assertion,
                                     'audience': 'picup.it'
                                 })
        response_json = json.loads(response.text)
        response_json['errors'] = errors

        if api_key:
            response_json['api_key'] = api_key

        if user_id > 0:
            response_json['user_id'] = user_id

        response_json = json.dumps(response_json)
        my_response = MyResponse()
        my_response.text = response_json

        return my_response
Exemplo n.º 10
0
def accounts_profile(request):
    """User's profile edit view.
    """

    if request.GET.has_key('next'):
        if request.GET['next'] == 'ffos':
            return redirect('/mobile/ffoslogged/')
        elif request.GET['next'] == 'ffosdata':
            return redirect('/mobile/data/')

    pictures_all = Picture.objects.filter(user=request.user, gallery=None)
    gravatar_url = get_gravatar_url(request.user.email)
    galleries = get_user_galleries(request.user, False)

    picup_profile = get_or_create_profile(request.user)

    return render(
        request, 'profile.html', {
            'pictures_all': pictures_all,
            'gravatar_url': gravatar_url,
            'galleries': galleries,
            'picup_profile': picup_profile
        })
Exemplo n.º 11
0
def picture_view(request, picture_id, oembed=False):
    """Single picture view.
    
    Parameters
    ----------
    picture_id : int
    oembed : bool
    """
    try:
        picture = Picture.objects.get(id=picture_id)
    except Picture.DoesNotExist:
        raise Http404

    user_gravatar_url = get_gravatar_url(picture.user.email)
    picup_profile = get_or_create_profile(picture.user)
    gallery = None

    picture_next = picture_previous = picture_first = picture_last = None

    # To show the background below top bar
    if not picup_profile.profile_picture:
        galleries = (
            Gallery.objects.filter(user=picture.user)
            .order_by("title")
            .annotate(num_pictures=Count("picture"))
            .filter(num_pictures__gt=0)[0:1]
        )
    else:
        galleries = None
    gallery_pictures = []
    metadata_dict = {}
    if picture.gallery:
        if picture.gallery.exif:
            metadata = get_metadata(picture.picture.file.name)
            metadata_dict = {}
            for mkey in metadata.exif_keys:
                try:
                    if mkey.find("Thumbnail") < 0:
                        if len(metadata[mkey].value.__str__()) < 32:
                            new_mkey = mkey.replace("Exif.", "")
                            metadata_dict[new_mkey] = metadata[mkey].value
                except UnicodeEncodeError:
                    pass
                except ValueError:
                    pass
            metadata_dict = collections.OrderedDict(sorted(metadata_dict.items()))

        gallery = picture.gallery
        gallery_pictures = gallery.picture_set.all()
        pictures_ids = [x.id for x in gallery_pictures]
        picture_pos = pictures_ids.index(int(picture_id))
        # TODO: Optimize
        picture_first = Picture.objects.get(id=pictures_ids[0])
        picture_last = Picture.objects.get(id=pictures_ids[len(pictures_ids) - 1])
        if picture_pos < len(pictures_ids) - 1:
            picture_next = Picture.objects.get(id=pictures_ids[picture_pos + 1])
        if picture_pos > 0:
            picture_previous = Picture.objects.get(id=pictures_ids[picture_pos - 1])

    others_pictures = []

    if picture.gallery:
        others_pictures = Picture.objects.filter(user=picture.user, gallery=picture.gallery).exclude(id=picture.id)
        if picture_next:
            others_pictures = others_pictures.exclude(id=picture_next.id)
        if picture_previous:
            others_pictures = others_pictures.exclude(id=picture_previous.id)
        others_pictures = others_pictures[0:4]

    metadata_dict_legacy = metadata_dict
    metadata_dict = {}
    for meta_entity in metadata_dict_legacy.keys():
        try:
            metadata_dict[meta_entity] = metadata_dict_legacy[meta_entity]
        except UnicodeDecodeError:
            pass
        except UnicodeEncodeError:
            pass

    if oembed == False:
        return render(
            request,
            "picture_view.html",
            {
                "picture": picture,
                "picup_profile": picup_profile,
                "picture_next": picture_next,
                "picture_first": picture_first,
                "picture_last": picture_last,
                "picture_previous": picture_previous,
                "galleries": galleries,
                "metadata": metadata_dict,
                "user_gravatar_url": user_gravatar_url,
                "gallery_pictures": gallery_pictures,
                "others_pictures": others_pictures,
            },
        )
    else:
        result = {}
        result["version"] = "1.0"
        result["type"] = "photo"
        result["title"] = "PicUp - Pictures Sharing"
        result["url"] = "https://picup.it/p/%s/" % picture_id
        result["author_name"] = "PicUp user"
        result["provider_name"] = "PicUp"
        result["provider_url"] = "https://picup.it/"
        result["width"] = "516"
        result["height"] = "320"
        result["html"] = (
            "<iframe src='https://picup.it/p/%s/' width='516px' height='315px' frameBorder='0'></iframe>" % picture_id
        )
        return HttpResponse(json.dumps(result), content_type="application/json")
Exemplo n.º 12
0
def user_gallery(request, user_id, gallery_id=None):
    """User's public user.
    
    Parameters
    ----------
    user_id : int
    gallery_id : int
    
    Note
    -----
    When gallery_id is None it servers user'r public profile page.
    """
    try:
        if int(user_id) == 1:
            raise Http404
    except ValueError:
        raise Http404
    try:
        picup_user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        raise Http404

    picup_profile = get_or_create_profile(picup_user)

    pictures_all = Picture.objects.filter(user=picup_user).order_by("-created")
    if gallery_id:
        try:
            gallery = Gallery.objects.get(id=gallery_id)
            pictures_all = pictures_all.filter(gallery=gallery).order_by("-created")
        except Gallery.DoesNotExist:
            raise Http404
    else:
        pictures_all = pictures_all.filter(gallery_id=None).order_by("-created")
        gallery = None
    pictures_clearing = pictures_all
    galleries = (
        Gallery.objects.filter(user=picup_user)
        .order_by("title")
        .annotate(num_pictures=Count("picture"))
        .filter(num_pictures__gt=0)
    )
    user_gravatar_url = get_gravatar_url(picup_user.email)
    pictures_all_3 = pictures_all_2 = pictures_all_1 = None
    pictures_count = pictures_all.count()
    if pictures_all.count() < RECOMMENDED_ROWS:
        spare = pictures_all.count()
    else:
        spare = pictures_all.count() % RECOMMENDED_ROWS
    number_rows = pictures_all.count() / RECOMMENDED_ROWS

    if spare == 3:
        pictures_all_3 = reversed(pictures_all[:3])
        pictures_all = pictures_all[3 : number_rows * RECOMMENDED_ROWS + 3]
    elif spare == 2:
        pictures_all_2 = reversed(pictures_all[:2])
        pictures_all = pictures_all[2 : number_rows * RECOMMENDED_ROWS + 2]
    elif spare == 1:
        pictures_all_1 = reversed(pictures_all[:1])
        pictures_all = pictures_all[1 : number_rows * RECOMMENDED_ROWS + 1]

    galleries_thumbs = galleries
    galleries_thumbs_3 = galleries_thumbs_2 = galleries_thumbs_1 = None

    if galleries.count() < RECOMMENDED_ROWS:
        spare = galleries.count()
    else:
        spare = galleries.count() % RECOMMENDED_ROWS
    number_rows = galleries.count() / RECOMMENDED_ROWS

    if spare == 3:
        galleries_thumbs_3 = reversed(galleries_thumbs[:3])
        galleries_thumbs = galleries_thumbs[3 : number_rows * RECOMMENDED_ROWS + 3]
    elif spare == 2:
        galleries_thumbs_2 = reversed(galleries_thumbs[:2])
        galleries_thumbs = galleries_thumbs[2 : number_rows * RECOMMENDED_ROWS + 2]
    elif spare == 1:
        galleries_thumbs_1 = reversed(galleries_thumbs[:1])
        galleries_thumbs = galleries_thumbs[1 : number_rows * RECOMMENDED_ROWS + 1]

    number_pictures_all = (pictures_all.count() / RECOMMENDED_ROWS) * RECOMMENDED_ROWS
    if pictures_all:
        main_picture = pictures_all[0]
        twitter_gallery = pictures_all[0:4]
    else:
        main_picture = None
        if galleries:
            twitter_gallery = [x.picture_set.first() for x in galleries[0:4]]
            main_picture = twitter_gallery[0]
        else:
            twitter_gallery = None

    galleries_odd = False

    if galleries:
        if galleries.count() % 2 == 1:
            galleries_odd = True

    return render(
        request,
        "user_gallery.html",
        {
            "pictures_all": pictures_all,
            "pictures_clearing": pictures_clearing,
            "pictures_all_3": pictures_all_3,
            "pictures_all_2": pictures_all_2,
            "pictures_all_1": pictures_all_1,
            "pictures_count": pictures_count,
            "galleries_thumbs": galleries_thumbs,
            "galleries_thumbs_3": galleries_thumbs_3,
            "galleries_thumbs_2": galleries_thumbs_2,
            "galleries_thumbs_1": galleries_thumbs_1,
            "twitter_gallery": twitter_gallery,
            "user_gravatar_url": user_gravatar_url,
            "picup_user": picup_user,
            "galleries": galleries,
            "gallery": gallery,
            "picup_profile": picup_profile,
            "main_picture": main_picture,
            "picture": main_picture,
            "galleries_odd": galleries_odd,
        },
    )
Exemplo n.º 13
0
def picture_view(request, picture_id, oembed=False):
    """Single picture view.
    
    Parameters
    ----------
    picture_id : int
    oembed : bool
    """
    try:
        picture = Picture.objects.get(id=picture_id)
    except Picture.DoesNotExist:
        raise Http404

    user_gravatar_url = get_gravatar_url(picture.user.email)
    picup_profile = get_or_create_profile(picture.user)
    gallery = None

    picture_next = picture_previous = picture_first = picture_last = None

    # To show the background below top bar
    if not picup_profile.profile_picture:
        galleries = Gallery.objects.filter(
            user=picture.user).order_by('title').annotate(
                num_pictures=Count('picture')).filter(num_pictures__gt=0)[0:1]
    else:
        galleries = None
    gallery_pictures = []
    metadata_dict = {}
    if picture.gallery:
        if picture.gallery.exif:
            metadata = get_metadata(picture.picture.file.name)
            metadata_dict = {}
            for mkey in metadata.exif_keys:
                try:
                    if mkey.find('Thumbnail') < 0:
                        if len(metadata[mkey].value.__str__()) < 32:
                            new_mkey = mkey.replace('Exif.', '')
                            metadata_dict[new_mkey] = metadata[mkey].value
                except UnicodeEncodeError:
                    pass
                except ValueError:
                    pass
            metadata_dict = collections.OrderedDict(
                sorted(metadata_dict.items()))

        gallery = picture.gallery
        gallery_pictures = gallery.picture_set.all()
        pictures_ids = [x.id for x in gallery_pictures]
        picture_pos = pictures_ids.index(int(picture_id))
        #TODO: Optimize
        picture_first = Picture.objects.get(id=pictures_ids[0])
        picture_last = Picture.objects.get(id=pictures_ids[len(pictures_ids) -
                                                           1])
        if picture_pos < len(pictures_ids) - 1:
            picture_next = Picture.objects.get(id=pictures_ids[picture_pos +
                                                               1])
        if picture_pos > 0:
            picture_previous = Picture.objects.get(
                id=pictures_ids[picture_pos - 1])

    others_pictures = []

    if picture.gallery:
        others_pictures = Picture.objects.filter(
            user=picture.user, gallery=picture.gallery).exclude(id=picture.id)
        if picture_next:
            others_pictures = others_pictures.exclude(id=picture_next.id)
        if picture_previous:
            others_pictures = others_pictures.exclude(id=picture_previous.id)
        others_pictures = others_pictures[0:4]

    metadata_dict_legacy = metadata_dict
    metadata_dict = {}
    for meta_entity in metadata_dict_legacy.keys():
        try:
            metadata_dict[meta_entity] = metadata_dict_legacy[meta_entity]
        except UnicodeDecodeError:
            pass
        except UnicodeEncodeError:
            pass

    if oembed == False:
        return render(
            request, "picture_view.html", {
                'picture': picture,
                'picup_profile': picup_profile,
                'picture_next': picture_next,
                'picture_first': picture_first,
                'picture_last': picture_last,
                'picture_previous': picture_previous,
                'galleries': galleries,
                'metadata': metadata_dict,
                'user_gravatar_url': user_gravatar_url,
                'gallery_pictures': gallery_pictures,
                'others_pictures': others_pictures
            })
    else:
        result = {}
        result['version'] = "1.0"
        result['type'] = 'photo'
        result['title'] = 'PicUp - Pictures Sharing'
        result['url'] = 'https://picup.it/p/%s/' % picture_id
        result['author_name'] = 'PicUp user'
        result['provider_name'] = 'PicUp'
        result['provider_url'] = 'https://picup.it/'
        result["width"] = "516"
        result["height"] = "320"
        result[
            "html"] = "<iframe src='https://picup.it/p/%s/' width='516px' height='315px' frameBorder='0'></iframe>" % picture_id
        return HttpResponse(json.dumps(result),
                            content_type='application/json')
Exemplo n.º 14
0
def user_gallery(request, user_id, gallery_id=None):
    """User's public user.
    
    Parameters
    ----------
    user_id : int
    gallery_id : int
    
    Note
    -----
    When gallery_id is None it servers user'r public profile page.
    """
    try:
        if int(user_id) == 1:
            raise Http404
    except ValueError:
        raise Http404
    try:
        picup_user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        raise Http404

    picup_profile = get_or_create_profile(picup_user)

    pictures_all = Picture.objects.filter(user=picup_user).order_by('-created')
    if gallery_id:
        try:
            gallery = Gallery.objects.get(id=gallery_id)
            pictures_all = pictures_all.filter(
                gallery=gallery).order_by('-created')
        except Gallery.DoesNotExist:
            raise Http404
    else:
        pictures_all = pictures_all.filter(
            gallery_id=None).order_by('-created')
        gallery = None
    pictures_clearing = pictures_all
    galleries = Gallery.objects.filter(
        user=picup_user).order_by('title').annotate(
            num_pictures=Count('picture')).filter(num_pictures__gt=0)
    user_gravatar_url = get_gravatar_url(picup_user.email)
    pictures_all_3 = pictures_all_2 = pictures_all_1 = None
    pictures_count = pictures_all.count()
    if pictures_all.count() < RECOMMENDED_ROWS:
        spare = pictures_all.count()
    else:
        spare = pictures_all.count() % RECOMMENDED_ROWS
    number_rows = pictures_all.count() / RECOMMENDED_ROWS

    if spare == 3:
        pictures_all_3 = reversed(pictures_all[:3])
        pictures_all = pictures_all[3:number_rows * RECOMMENDED_ROWS + 3]
    elif spare == 2:
        pictures_all_2 = reversed(pictures_all[:2])
        pictures_all = pictures_all[2:number_rows * RECOMMENDED_ROWS + 2]
    elif spare == 1:
        pictures_all_1 = reversed(pictures_all[:1])
        pictures_all = pictures_all[1:number_rows * RECOMMENDED_ROWS + 1]

    galleries_thumbs = galleries
    galleries_thumbs_3 = galleries_thumbs_2 = galleries_thumbs_1 = None

    if galleries.count() < RECOMMENDED_ROWS:
        spare = galleries.count()
    else:
        spare = galleries.count() % RECOMMENDED_ROWS
    number_rows = galleries.count() / RECOMMENDED_ROWS

    if spare == 3:
        galleries_thumbs_3 = reversed(galleries_thumbs[:3])
        galleries_thumbs = galleries_thumbs[3:number_rows * RECOMMENDED_ROWS +
                                            3]
    elif spare == 2:
        galleries_thumbs_2 = reversed(galleries_thumbs[:2])
        galleries_thumbs = galleries_thumbs[2:number_rows * RECOMMENDED_ROWS +
                                            2]
    elif spare == 1:
        galleries_thumbs_1 = reversed(galleries_thumbs[:1])
        galleries_thumbs = galleries_thumbs[1:number_rows * RECOMMENDED_ROWS +
                                            1]

    number_pictures_all = ((pictures_all.count() / RECOMMENDED_ROWS) *
                           RECOMMENDED_ROWS)
    if pictures_all:
        main_picture = pictures_all[0]
        twitter_gallery = pictures_all[0:4]
    else:
        main_picture = None
        if galleries:
            twitter_gallery = [x.picture_set.first() for x in galleries[0:4]]
            main_picture = twitter_gallery[0]
        else:
            twitter_gallery = None

    galleries_odd = False

    if galleries:
        if galleries.count() % 2 == 1:
            galleries_odd = True

    return render(
        request, 'user_gallery.html', {
            'pictures_all': pictures_all,
            'pictures_clearing': pictures_clearing,
            'pictures_all_3': pictures_all_3,
            'pictures_all_2': pictures_all_2,
            'pictures_all_1': pictures_all_1,
            'pictures_count': pictures_count,
            'galleries_thumbs': galleries_thumbs,
            'galleries_thumbs_3': galleries_thumbs_3,
            'galleries_thumbs_2': galleries_thumbs_2,
            'galleries_thumbs_1': galleries_thumbs_1,
            'twitter_gallery': twitter_gallery,
            'user_gravatar_url': user_gravatar_url,
            'picup_user': picup_user,
            'galleries': galleries,
            'gallery': gallery,
            'picup_profile': picup_profile,
            'main_picture': main_picture,
            'picture': main_picture,
            'galleries_odd': galleries_odd
        })