Example #1
0
def add_gallery(request):
	form = GalleryForm(request.POST or None)
	if request.method == 'POST':
		if form.is_valid():
			form.save(owner=request.user)
			return HttpResponseRedirect('/photos/')
		
	return render_to_response("photos/add_gallery.html",{
		"form": form,
		}, context_instance=RequestContext(request)
		)
Example #2
0
def gallery_edit(request, pk=0):
	ctx = {}
	gallery = get_object_or_404(Gallery, pk=pk)
	print 'gallery.owner:',gallery.owner
	if gallery.owner != request.user:
		return HttpResponse(u'您没有权限执行该操作')
	form = GalleryForm(instance=gallery)
	if request.method == 'POST':
		form = GalleryForm(request.POST,instance=gallery)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(reverse('manage'))
	return render_to_response("photos/add_gallery.html",{
		"form": form, 'gallery': gallery
		}, context_instance=RequestContext(request)
		)