def edit_photo(photo_id): photo = Photo.query.filter_by(id=photo_id).first() if not photo: flash(BAD_KITTY, 'danger') return redirect(url_for('index')) slide = Slide.query.filter_by(id=photo.slide_id).first() if not slide: flash(BAD_KITTY, 'danger') return redirect(url_for('index')) journey = Journey.query.filter_by(id=slide.journey_id, user_id=current_user.id).first() if not journey: flash(BAD_KITTY, 'danger') return redirect(url_for('index')) form = EditPhotoForm(photo_id=photo_id, title=photo.title, description=photo.description) if form.validate_on_submit(): photo.title = form.data['title'] photo.description = form.data['description'] db.session.commit() flash('Photo successfully updated.', 'success') return redirect(url_for('edit_photo', photo_id=photo_id)) flash_errors(form) return render_template('edit-photo.html', form=form, title='Edit photo %s' % photo.title, photo=photo)
def photo_edit(request, photo_id): print "POST: %s" % request.POST photo = Photo.objects.get(id=photo_id) form = EditPhotoForm() errmsg = "" succ = False if request.method == "POST": form = EditPhotoForm(request.POST, request.FILES) if form.is_valid(): p = photo p.title = form.cleaned_data['title'] p.description = form.cleaned_data['description'] p.datetime = datetime.datetime.now() p.uuid = str(uuid.uuid4()) p.license = form.cleaned_data['license'] p.published = form.cleaned_data['published'] p.featured = form.cleaned_data['featured'] p.notes = form.cleaned_data['notes'] p.postcard = form.cleaned_data['postcard'] p.save() p.set_tags(request.POST.getlist('tags')) if 'photo' in request.FILES.keys(): p.extension = os.path.splitext(form.cleaned_data['photo'].name)[1][1:] create_new_photo_storage(photo=p, f=request.FILES['photo']) succ = p.id else: errmsg = form.errors else: form.fields["title"].initial = photo.title form.fields["description"].initial = photo.description form.fields["license"].initial = photo.license form.fields["published"].initial = photo.published form.fields["featured"].initial = photo.featured form.fields["notes"].initial = photo.notes form.fields["postcard"].initial = photo.postcard return render(request, 'manage/photo-edit.html', { 'NAV_PHOTO_CLASS': 'active', 'form': form, 'errmsg': errmsg, 'succ': succ, 'tags': photo.tags.all(), 'all_tags': get_all_tags(), } )
def edit_photo_view(request, photo_id): # try: # photo = Photo.objects.get(pk=photo_id) # except Photo.DoesNotExist: # raise Http404 photo = get_object_or_404(Photo, pk=photo_id) if photo.owner_id == request.user.id: if request.method == 'POST': form = EditPhotoForm(request.user, data=request.POST or None, instance=photo) if form.is_valid(): photo = form.save() if form.cleaned_data['tag']: tag = Tag(name=form.cleaned_data['tag']) tag.save() photo.tags.add(tag) photo.save() else: form.save() return redirect('photorizer.views.photo_view', photo.id) else: form = EditPhotoForm(instance=photo, current_user=request.user) context = {'form': form, 'photo': photo} # return render(request, 'photorizer/edit_photo.html', # {'form': form, 'photo': photo}) return render(request, 'photorizer/edit_photo.html', context) else: return render(request, 'photorizer/permission_denied.html')