add region in deploy order form

This commit is contained in:
deflax 2018-04-01 16:29:17 +03:00
parent a0382b3aa4
commit 9e52770ccd
4 changed files with 10 additions and 6 deletions

View file

@ -234,6 +234,7 @@ class Order(db.Model):
user_id = db.Column(db.ForeignKey('users.pid')) #FK
status = db.Column(db.String)
recipe_id = db.Column(db.ForeignKey('recipes.pid')) #FK
region_id = db.Column(db.ForeignKey('regions.pid')) #FK
parameter1 = db.Column(db.String)
parameter2 = db.Column(db.String)
parameter3 = db.Column(db.String)
@ -253,6 +254,7 @@ class Region(db.Model):
pid = db.Column(db.Integer, primary_key=True)
inv_servers = db.relationship('Server', backref='region', lazy='dynamic')
inv_addresses = db.relationship('Address', backref='region', lazy='dynamic')
inv_orders = db.relationship('Order', backref='region', lazy='dynamic')
enabled = db.Column(db.Boolean)
name = db.Column(db.String)

View file

@ -7,6 +7,7 @@ from .. import db
class OrderForm(FlaskForm):
region_choices = [(1, 'Plovdiv, Bulgaria')]
region_choices = [(2, 'International Space Station')]
region = SelectField('Region:', choices=region_choices, coerce=int)
vmtype_choices = [(1, 'RootVPS')]

View file

@ -25,8 +25,9 @@ def deploy():
form = OrderForm()
if form.validate_on_submit():
recipe = Recipe.query.filter_by(category='deploy').first()
new_order = Order(user_id=int(current_user.pid), recipe_id=int(recipe.pid), parameter1=str(form.alias.data), parameter2=str(form.cpu.data), parameter3=str(form.memory.data), parameter4=str(form.storage.data), status='new')
region = Region.query.filter_by(pid=int(form.region.data)).first()
recipe = Recipe.query.filter_by(pid=int(form.recipe.data)).first()
new_order = Order(user_id=int(current_user.pid), region_id=int(region.pid), recipe_id=int(recipe.pid), parameter1=str(form.alias.data), parameter2=str(form.cpu.data), parameter3=str(form.memory.data), parameter4=str(form.storage.data), status='new')
db.session.add(new_order)
db.session.commit()
send_email(current_app.config['MAIL_USERNAME'], 'New order from {}'.format(current_user.email),
@ -65,7 +66,7 @@ def dashboard(user_pid):
#warning detector
#current_app.logger.info(str(invcls.machine_alias))
if invcls.warning == True or invcls.enabled == False:
current_app.logger.warning('[{}] Deploy {} triggered a warning'.format(cuser.email, invcls.machine_alias))
#current_app.logger.warning('[{}] Deploy {} triggered a warning'.format(cuser.email, invcls.machine_alias))
warnflag = True
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()

View file

@ -49,12 +49,12 @@ def slavetables():
addrlist['status'] = 'tables_gen_error'
return jsonify(addrlist)
@vmanager.route('/vmcreate', methods=['GET', 'POST'])
@vmanager.route('/vmcreate/<int:orderid>', methods=['GET', 'POST'])
@login_required
@admin_required
def vmcreate():
def vmcreate(orderid):
form = CreateForm()
if current_user.confirmed and form.validate_on_submit():
if form.validate_on_submit():
#selects the chosen region
selected_region = Region.query.filter_by(pid=int(form.region.data)).first()