def upload(request): """ 上传图片 """ user = request.user form = PhotoForm() context_map=get_base_context_map(request) if request.POST: form = PhotoForm(request.POST, request.FILES, user) if form.is_valid(): photo=form.save() if photo==None: context_map['form']=form return render_to_response('photos/upload.html', context_map) return HttpResponseRedirect('/photos/check/%s/' % photo.id) context_map['form']=form return render_to_response('photos/upload.html', context_map)
def edit(request, id): photo=get_object_or_404(Photo, pk=id) user = request.user if photo.user!=user: return HttpResponseRedirect('/photos/check/%s/' % photo.id) context_map=get_base_context_map(request) data=photo.__dict__ from oldphoto.utils.html2text import html2text data['descn']=html2text(photo.descn) data['txt_tags']=photo.get_txt_tags() form = PhotoForm(data=data) if request.POST: form = PhotoForm(request.POST, request.FILES, user, photo) if form.is_valid(): photo=form.save() if photo==None: context_map['form']=form return render_to_response('photos/edit.html', context_map) return HttpResponseRedirect('/photos/check/%s/' % photo.id) context_map['form']=form context_map['photo']=photo return render_to_response('photos/edit.html', context_map)
def upload(request): """ 上传图片 """ user = request.user form = PhotoForm() context_map = get_base_context_map(request) if request.POST: form = PhotoForm(request.POST, request.FILES, user) if form.is_valid(): photo = form.save() if photo == None: context_map['form'] = form return render_to_response('photos/upload.html', context_map) return HttpResponseRedirect('/photos/check/%s/' % photo.id) context_map['form'] = form return render_to_response('photos/upload.html', context_map)
def edit(request, id): photo = get_object_or_404(Photo, pk=id) user = request.user if photo.user != user: return HttpResponseRedirect('/photos/check/%s/' % photo.id) context_map = get_base_context_map(request) data = photo.__dict__ from oldphoto.utils.html2text import html2text data['descn'] = html2text(photo.descn) data['txt_tags'] = photo.get_txt_tags() form = PhotoForm(data=data) if request.POST: form = PhotoForm(request.POST, request.FILES, user, photo) if form.is_valid(): photo = form.save() if photo == None: context_map['form'] = form return render_to_response('photos/edit.html', context_map) return HttpResponseRedirect('/photos/check/%s/' % photo.id) context_map['form'] = form context_map['photo'] = photo return render_to_response('photos/edit.html', context_map)