Пример #1
0
def upload(request, form_class=PhotoUploadForm, template_name="photos/upload.html"):
    """
    upload form for photos
    """

    group, bridge = group_and_bridge(request)

    photo_form = form_class()
    if request.method == "POST":
        if request.POST.get("action") == "upload":
            photo_form = form_class(request.user, request.POST, request.FILES)
            if photo_form.is_valid():
                photo = photo_form.save(commit=False)
                photo.member = request.user
                photo.save()

                # in group context we create a Pool object for it
                if group:
                    pool = Pool()
                    pool.photo = photo
                    group.associate(pool, gfk_field="content_object")
                    pool.save()

                messages.add_message(
                    request, messages.SUCCESS,
                    ugettext("Successfully uploaded photo '%s'") % photo.title
                )

                if notification:
                    # Fixed TypeError: can't pickle function objects
                    # photo = Image.objects.get(pk=photo.pk)
                    if group:
                        notify_list = group.member_queryset().exclude(id__exact=photo.member.id)
                    else:
                        notify_list = [x['friend'] for x in Friendship.objects.friends_for_user(photo.member)]

                    notification.send(notify_list, "photos_image_new", {
                        "creator": photo.member,
                        "image": photo,
                        "group": photo.group,
                        "context_object": photo,
                    })

                include_kwargs = {"id": photo.id}
                if group:
                    redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs)
                else:
                    redirect_to = reverse("photo_details", kwargs=include_kwargs)

                return HttpResponseRedirect(redirect_to)

    ctx = group_context(group, bridge)
    ctx.update({
        "photo_form": photo_form,
    })

    return render_to_response(template_name, RequestContext(request, ctx))
Пример #2
0
def upload(request, form_class=PhotoUploadForm,
        template_name="photos/upload.html", group_slug=None, bridge=None):
    """
    upload form for photos
    """
    
    if bridge:
        try:
            group = bridge.get_group(group_slug)
        except ObjectDoesNotExist:
            raise Http404
    else:
        group = None
    
    photo_form = form_class()
    if request.method == "POST":
        if request.POST.get("action") == "upload":
            photo_form = form_class(request.user, request.POST, request.FILES)
            if photo_form.is_valid():
                photo = photo_form.save(commit=False)
                photo.member = request.user
                photo.save()
                
                # in group context we create a Pool object for it
                if group:
                    pool = Pool()
                    pool.photo = photo
                    group.associate(pool)
                    pool.save()
                
                messages.add_message(request, messages.SUCCESS,
                    ugettext("Successfully uploaded photo '%s'") % photo.title
                )
                
                include_kwargs = {"id": photo.id}
                if group:
                    redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs)
                else:
                    redirect_to = reverse("photo_details", kwargs=include_kwargs)
                
                return HttpResponseRedirect(redirect_to)
    
    return render_to_response(template_name, {
        "group": group,
        "photo_form": photo_form,
    }, context_instance=RequestContext(request))
Пример #3
0
def upload(request,
           form_class=PhotoUploadForm,
           template_name="photos/upload.html"):
    """
    upload form for photos
    """

    group, bridge = group_and_bridge(request)

    photo_form = form_class()
    if request.method == "POST":
        if request.POST.get("action") == "upload":
            photo_form = form_class(request.user, request.POST, request.FILES)
            if photo_form.is_valid():
                photo = photo_form.save(commit=False)
                photo.member = request.user
                photo.save()

                # in group context we create a Pool object for it
                if group:
                    pool = Pool()
                    pool.photo = photo
                    group.associate(pool, gfk_field="content_object")
                    pool.save()

                messages.add_message(
                    request, messages.SUCCESS,
                    ugettext("Successfully uploaded photo '%s'") % photo.title)

                include_kwargs = {"id": photo.id}
                if group:
                    redirect_to = bridge.reverse(
                        "photo_details", group, kwargs=include_kwargs)
                else:
                    redirect_to = reverse(
                        "photo_details", kwargs=include_kwargs)

                return HttpResponseRedirect(redirect_to)

    ctx = group_context(group, bridge)
    ctx.update({
        "photo_form": photo_form,
    })

    return render_to_response(template_name, RequestContext(request, ctx))
Пример #4
0
def upload(request, form_class=PhotoUploadForm, template_name="photos/upload.html"):
    """
    upload form for photos
    """
    
    group, bridge = group_and_bridge(request)
    
    photo_form = form_class()
    if request.method == "POST":
        if request.POST.get("action") == "upload":
            photo_form = form_class(request.user, request.POST, request.FILES)
            if photo_form.is_valid():
                photo = photo_form.save(commit=False)
                photo.member = request.user
                photo.save()
                
                # in group context we create a Pool object for it
                if group:
                    pool = Pool()
                    pool.photo = photo
                    group.associate(pool, gfk_field="content_object")
                    pool.save()
                
                messages.add_message(request, messages.SUCCESS,
                    ugettext("Successfully uploaded photo '%s'") % photo.title
                )
                
                include_kwargs = {"id": photo.id}
                if group:
                    redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs)
                else:
                    redirect_to = reverse("photo_details", kwargs=include_kwargs)
                
                return HttpResponseRedirect(redirect_to)
    
    ctx = group_context(group, bridge)
    ctx.update({
        "photo_form": photo_form,
    })
    
    return render_to_response(template_name, RequestContext(request, ctx))