from flask import Blueprint, render_template, request, redirect, url_for, flash import mg.tasks from mg import application as m from mg import pool as pool from mgweb.decorators import webtask blueprint = Blueprint('store', __name__) @blueprint.route('/') @blueprint.route('//index') def index(store): store = m.magedir.get(store) backups = m.pool.list_local(pool.states, store.name) return render_template('store.html', store=store, backups=backups) @blueprint.route('//backup', methods=['POST']) @webtask def backup(store): store = m.magedir.get(store) store.saveState(m.pool, request.form['backup_name']) flash("Successfully backed up", category='success') return redirect(url_for('store.index', store=store.name) + '#backup') @blueprint.route('//installext', methods=['POST']) def installext(store): store = m.magedir.get(store) mg.tasks.install_extension(request.form['ext'], store.name) flash('Successfully installed %s to %s' % (request.form['ext'], store.name), category='success') return redirect(url_for('store.index', store=store.name) + '#installext') @blueprint.route('//restore_backup') @webtask def restore_backup(store): store = m.magedir.get(store) store.restoreState(m.pool, request.args.get('backup','')) flash("Successfully restored from backup", category='success') return redirect(url_for('store.index', store=store.name) + '#backup') @blueprint.route('//delete_backup') @webtask def delete_backup(store): store = m.magedir.get(store) store.removeState(m.pool, request.args.get('backup','')) flash("Backup %s deleted" % request.args.get('backup',''), category='success') return redirect(url_for('store.index', store=store.name) + '#backup') @blueprint.route('//create_dist', methods=['POST']) @webtask def create_dist(store): mg.tasks.create_dist(store, request.form['dist_name']) flash("Created distributive {name}".format(name=request.form['dist_name']), category='success') return redirect(url_for('store.index', store=store)) @blueprint.route('//set_admin', methods=['POST']) @webtask def set_admin(store): mg.tasks.set_admin(store, request.form['admin_login'], request.form['admin_password']) flash("Password changed for {name}".format(name=store), category='success') return redirect(url_for('store.index', store=store)) @blueprint.route('//heal') @webtask def heal(store): mg.tasks.heal_store(store) flash("Healed store {name}".format(name=store), category='success') return redirect(url_for('store.index', store=store)) @blueprint.route('//set_maintenance/') @webtask def set_maintenance(store, mode): mode = int(mode) mg.tasks.maintenance(store, mode) flash("Store maintenance mode switched {state}".format(state=['off', 'on'][mode]), category='success') return redirect(url_for('store.index', store=store)) @blueprint.route('//delete') @webtask def delete(store): mg.tasks.delete_store(store) flash("Store {store} has been deleted".format(store=store), category='success') return redirect(url_for('stores.index'))