You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mailu/admin/freeposte/admin/views/fetches.py

58 lines
1.9 KiB
Python

from freeposte.admin import app, db, models, forms, utils
import os
import flask
import flask_login
import wtforms_components
@app.route('/fetch/list', methods=['GET', 'POST'], defaults={'user_email': None})
@app.route('/fetch/list/<user_email>', methods=['GET'])
@flask_login.login_required
def fetch_list(user_email):
user = utils.get_user(user_email)
return flask.render_template('fetch/list.html', user=user)
@app.route('/fetch/create', methods=['GET', 'POST'], defaults={'user_email': None})
@app.route('/fetch/create/<user_email>', methods=['GET', 'POST'])
@flask_login.login_required
def fetch_create(user_email):
user = utils.get_user(user_email)
form = forms.FetchForm()
if form.validate_on_submit():
fetch = models.Fetch(user=user)
form.populate_obj(fetch)
db.session.add(fetch)
db.session.commit()
flask.flash('Fetch configuration created')
return flask.redirect(
flask.url_for('.fetch_list', user_email=user.email))
return flask.render_template('fetch/create.html', form=form)
@app.route('/fetch/edit/<fetch_id>', methods=['GET', 'POST'])
@flask_login.login_required
def fetch_edit(fetch_id):
fetch = utils.get_fetch(fetch_id)
form = forms.FetchForm(obj=fetch)
if form.validate_on_submit():
form.populate_obj(fetch)
db.session.commit()
flask.flash('Fetch configuration updated')
return flask.redirect(
flask.url_for('.fetch_list', user_email=fetch.user.email))
return flask.render_template('fetch/edit.html',
form=form, fetch=fetch)
@app.route('/fetch/delete/<fetch_id>', methods=['GET'])
@flask_login.login_required
def fetch_delete(fetch_id):
fetch = utils.get_fetch(fetch_id)
db.session.delete(fetch)
db.session.commit()
flask.flash('Fetch configuration delete')
return flask.redirect(
flask.url_for('.fetch_list', user_email=fetch.user.email))