示例#1
0
def new_gallery(request):
    """Create a new gallery."""
    if request.method == 'GET':
        gal_form = GalleryForm()
        return jingo.render(request, 'portfolio/new_gallery.html',
                            {'gallery_form': gal_form})

    gal_form = GalleryForm(request.POST)

    if gal_form.is_valid():
        gal = gal_form.save(request.user, False)
        return http.HttpResponseRedirect(reverse('portfolio.viewgallery',
                                    args=[gal.id]))

    return jingo.render(request, 'portfolio/new_gallery.html',
                        {'gallery_form': gal_form})
示例#2
0
def edit_gallery(request, gallery_id):
    g = get_object_or_404(Gallery, pk=gallery_id)

    if request.user != g.creator:
        return http.HttpResponseForbidden()

    if request.method == 'GET':
        gal_form = GalleryForm(instance=g)
        return jingo.render(request, 'portfolio/edit_gallery.html',
                            {'gallery_form': gal_form,
                             'id': g.id})

    gal_form = GalleryForm(request.POST, instance=g)

    if gal_form.is_valid():
        gal = gal_form.save(request.user, True)
        return http.HttpResponseRedirect(reverse('portfolio.viewgallery',
                                    args=[gal.id]))

    return jingo.render(request, 'portfolio/edit_gallery.html',
                        {'gallery_form': gal_form,
                         'id': g.id})