Exemplo n.º 1
0
def picture_add(request):
    context = {}
    if request.GET.get('event'):
        event = get_object_or_404(Event, id=request.GET.get('event'))
        result = can_edit_event(event,
                                request.user,
                                default='manage:picturegallery')
        if isinstance(result, http.HttpResponse):
            return result

        context['event'] = event
    if request.method == 'POST':
        if request.POST.get('remove'):
            # this is for when you change your mind
            size = request.POST['size']
            filename = request.POST['name']
            notes = filename_to_notes(filename)
            matches = Picture.objects.filter(notes=notes,
                                             size=int(size),
                                             modified_user=request.user)
            for picture in matches.order_by('-created')[:1]:
                picture.delete()
                return True
            return False

        form = forms.PictureForm(request.POST, request.FILES)
        if form.is_valid():
            picture = form.save(commit=False)
            picture.modified_user = request.user
            picture.save()
            return redirect('manage:picturegallery')
    else:
        form = forms.PictureForm()
    context['form'] = form
    return render(request, 'manage/picture_add.html', context)
Exemplo n.º 2
0
def picture_edit(request, id):
    picture = get_object_or_404(Picture, id=id)
    context = {'picture': picture}

    if request.method == 'POST':
        form = forms.PictureForm(request.POST, request.FILES, instance=picture)
        if form.is_valid():
            picture = form.save()
            return redirect('manage:picturegallery')
    else:
        form = forms.PictureForm(instance=picture)
    context['form'] = form
    return render(request, 'manage/picture_edit.html', context)
Exemplo n.º 3
0
def picture_edit(request, id):
    picture = get_object_or_404(Picture, id=id)
    context = {'picture': picture}

    if request.method == 'POST':
        form = forms.PictureForm(request.POST, request.FILES, instance=picture)
        if form.is_valid():
            picture = form.save()
            if picture.default_placeholder:
                # make all others NOT-default
                qs = (Picture.objects.exclude(id=picture.id).filter(
                    default_placeholder=True))
                for other in qs:
                    other.default_placeholder = False
                    other.save()
            return redirect('manage:picturegallery')
    else:
        form = forms.PictureForm(instance=picture)
    context['form'] = form
    return render(request, 'manage/picture_edit.html', context)