Esempio n. 1
0
def edit_user(user_id=-1):
    user_form = EditUserForm()
    if user_form.validate_on_submit():
        user = Users.get(user_form.user_id.data)
        if user.id == session.get('user_id') or user.admin:
            user.first_name = user_form.first_name.data
            user.last_name = user_form.last_name.data
            user.email = user_form.email.data
            user.alias = user_form.alias.data
            user.last_modified = datetime.now()
            try:
                avatar = list(Image.select(Image.q.url==user_form.avatar.data))[0]
            except (SQLObjectNotFound, IndexError):
                pass
            else:
                user.avatar = avatar
            flash("%s %s has been updated" % (user.first_name, user.last_name))
            return redirect(url_for('list_users'))
        else:
            flash("Sorry, you're not allowed to do that")
            return redirect(url_for('edit_user', user_id=user.id))

    else:
        try:
            user = Users.get(user_id)
        except SQLObjectNotFound:
            user = {'first_name': '',
                    'last_name': '',
                    'email': '',
                    'password': '',
                    'avatar': ''}
        finally:
            return render_template('edit_user.html', data={'form': user_form,
                                                           'user': user})
Esempio n. 2
0
def list_images():
    images = list(Image.select())
    return render_template('show_images.html', data={'images': images})
Esempio n. 3
0
def list_images():
    images = list(Image.select())
    return render_template('show_images.html', data={'images': images})