

@login_required
def edit(request, id, form_class=PhotoEditForm, template_name='photos/edit.html'):
    (group, bridge) = group_and_bridge(request)
    photos = Image.objects.all()
    if group:
        photos = group.content_objects(photos, join='pool', gfk_field='content_object')
    else:
        photos = photos.filter(pool__object_id=None)
    photo = get_object_or_404(photos, id=id)
    photo_url = photo.get_display_url()
    if (request.method == 'POST'):
        if (photo.member != request.user):
            message.add_message(request, messages.ERROR, ugettext("You can't edit photos that aren't yours"))
            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(reverse('photo_details', args=(photo.id,)))
        if (request.POST['action'] == 'update'):
            photo_form = form_class(request.user, request.POST, instance=photo)
            if photo_form.is_valid():
                photoobj = photo_form.save(commit=False)
                photoobj.save()
                messages.add_message(request, messages.SUCCESS, (ugettext("Successfully updated 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)
        else:
            photo_form = form_class(instance=photo)
    else:
        photo_form = form_class(instance=photo)
    ctx = group_context(group, bridge)
    ctx.update({
        'photo_form': photo_form,
        'photo': photo,
        'photo_url': photo_url,
    })
    return render_to_response(template_name, RequestContext(request, ctx))

dataset/ETHPy150Open amarandon/smeuhsocial/apps/photos/views.py edit/original