add region in deploy order form
This commit is contained in:
parent
a0382b3aa4
commit
9e52770ccd
4 changed files with 10 additions and 6 deletions
|
@ -234,6 +234,7 @@ class Order(db.Model):
|
||||||
user_id = db.Column(db.ForeignKey('users.pid')) #FK
|
user_id = db.Column(db.ForeignKey('users.pid')) #FK
|
||||||
status = db.Column(db.String)
|
status = db.Column(db.String)
|
||||||
recipe_id = db.Column(db.ForeignKey('recipes.pid')) #FK
|
recipe_id = db.Column(db.ForeignKey('recipes.pid')) #FK
|
||||||
|
region_id = db.Column(db.ForeignKey('regions.pid')) #FK
|
||||||
parameter1 = db.Column(db.String)
|
parameter1 = db.Column(db.String)
|
||||||
parameter2 = db.Column(db.String)
|
parameter2 = db.Column(db.String)
|
||||||
parameter3 = 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)
|
pid = db.Column(db.Integer, primary_key=True)
|
||||||
inv_servers = db.relationship('Server', backref='region', lazy='dynamic')
|
inv_servers = db.relationship('Server', backref='region', lazy='dynamic')
|
||||||
inv_addresses = db.relationship('Address', 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)
|
enabled = db.Column(db.Boolean)
|
||||||
name = db.Column(db.String)
|
name = db.Column(db.String)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .. import db
|
||||||
|
|
||||||
class OrderForm(FlaskForm):
|
class OrderForm(FlaskForm):
|
||||||
region_choices = [(1, 'Plovdiv, Bulgaria')]
|
region_choices = [(1, 'Plovdiv, Bulgaria')]
|
||||||
|
region_choices = [(2, 'International Space Station')]
|
||||||
region = SelectField('Region:', choices=region_choices, coerce=int)
|
region = SelectField('Region:', choices=region_choices, coerce=int)
|
||||||
|
|
||||||
vmtype_choices = [(1, 'RootVPS')]
|
vmtype_choices = [(1, 'RootVPS')]
|
||||||
|
|
|
@ -25,8 +25,9 @@ def deploy():
|
||||||
|
|
||||||
form = OrderForm()
|
form = OrderForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
recipe = Recipe.query.filter_by(category='deploy').first()
|
region = Region.query.filter_by(pid=int(form.region.data)).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')
|
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.add(new_order)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
send_email(current_app.config['MAIL_USERNAME'], 'New order from {}'.format(current_user.email),
|
send_email(current_app.config['MAIL_USERNAME'], 'New order from {}'.format(current_user.email),
|
||||||
|
@ -65,7 +66,7 @@ def dashboard(user_pid):
|
||||||
#warning detector
|
#warning detector
|
||||||
#current_app.logger.info(str(invcls.machine_alias))
|
#current_app.logger.info(str(invcls.machine_alias))
|
||||||
if invcls.warning == True or invcls.enabled == False:
|
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
|
warnflag = True
|
||||||
|
|
||||||
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
|
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
|
||||||
|
|
|
@ -49,12 +49,12 @@ def slavetables():
|
||||||
addrlist['status'] = 'tables_gen_error'
|
addrlist['status'] = 'tables_gen_error'
|
||||||
return jsonify(addrlist)
|
return jsonify(addrlist)
|
||||||
|
|
||||||
@vmanager.route('/vmcreate', methods=['GET', 'POST'])
|
@vmanager.route('/vmcreate/<int:orderid>', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def vmcreate():
|
def vmcreate(orderid):
|
||||||
form = CreateForm()
|
form = CreateForm()
|
||||||
if current_user.confirmed and form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
#selects the chosen region
|
#selects the chosen region
|
||||||
selected_region = Region.query.filter_by(pid=int(form.region.data)).first()
|
selected_region = Region.query.filter_by(pid=int(form.region.data)).first()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue