Exemple #1
0
def photos(username):
    if request.method == "GET":
        return render_template("photos.html", profile_user=User.get_user(username), photo_form=PhotoForm())

    else:
        if not (g.user and g.user.username == username):
            flash("You are not authorized for that action.")
            return redirect("views.profiles")

        photo_form = PhotoForm()

        if photo_form.validate_on_submit():
            filename = PHOTO_UPLOAD_SET.save(photo_form.photo.file)
            photo = Photo(filename, g.user.id)
            db.session.add(photo)
            db.session.commit()
            flash("Photo saved.")
            return redirect(url_for("views.photos", username=g.user.username))
        return render_template("photos.html", profile_user=g.user, username=g.user.username, photo_form=photo_form)
Exemple #2
0
def photos(username):
    if request.method == 'GET':
        return render_template('photos.html',
                               profile_user=User.get_user(username),
                               photo_form=PhotoForm())

    else:
        if not (g.user and g.user.username == username):
            flash("You are not authorized for that action.")
            return redirect('views.profiles')

        photo_form = PhotoForm()

        if photo_form.validate_on_submit():
            filename = PHOTO_UPLOAD_SET.save(photo_form.photo.file)
            photo = Photo(filename, g.user.id)
            db.session.add(photo)
            db.session.commit()
            flash("Photo saved.")
            return redirect(url_for('views.photos', username=g.user.username))
        return render_template('photos.html',
                               profile_user=g.user,
                               username=g.user.username,
                               photo_form=photo_form)
Exemple #3
0
 def path(self):
     return PHOTO_UPLOAD_SET.path(self.filename)
Exemple #4
0
 def url(self):
     return PHOTO_UPLOAD_SET.url(self.filename)