You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
7.0 KiB

from flask import render_template, url_for, flash, redirect, request, Blueprint
from minibase import db
from minibase.config import themeMinibase
from minibase.database.models import Company, Company_legal_entity, Company_relation
from minibase.database.models import Industry
from minibase.database.models import Person_role, Person_competence
from minibase.admin.forms import compLegalEntityForm, compRelationForm, compIndustryForm,personRoleForm, personCompetenceForm, statusRegisterForm
# Declaring a blueprint
admin = Blueprint('admin', __name__)
@admin.route("/company_register_legal_entity", methods=['GET', 'POST'])
def company_register_legal_entity():
form = compLegalEntityForm()
legal_entities = Company_legal_entity.query.order_by(Company_legal_entity.name.asc())
if form.validate_on_submit():
companyLegal = Company_legal_entity(
name=form.name.data,
description=form.description.data)
# Here we need to give the id of thr role as this is a foreign key
db.session.add(companyLegal)
db.session.commit()
flash(f'{"Company Legal Entity registered!"}', 'success')
return render_template('admin/company_register_legal_entity.html',
title='Register Company Legal Entity',
legal_entities=legal_entities,
theme=themeMinibase,
form=form)
return render_template('admin/company_register_legal_entity.html',
title='Register Company Legal Entity',
legal_entities=legal_entities,
theme=themeMinibase,
form=form)
@admin.route("/company_register_relation", methods=['GET', 'POST'])
def company_register_relation():
form = compRelationForm()
relations = Company_relation.query.order_by(Company_relation.name.asc())
if form.validate_on_submit():
companyRelation = Company_relation(
name=form.name.data,
description=form.description.data)
# Here we need to give the id of thr role as this is a foreign key
db.session.add(companyRelation)
db.session.commit()
flash(f'{"Company Relation registered!"}', 'success')
return render_template('admin/company_register_relation.html',
title='Register Company Relation',
relations=relations,
theme=themeMinibase,
form=form)
return render_template('admin/company_register_relation.html',
title='Register Company Relation',
theme=themeMinibase,
relations=relations,
form=form)
@admin.route("/company_register_industry", methods=['GET', 'POST'])
def company_register_industry():
form = compIndustryForm()
industries = Industry.query.order_by(Industry.name.asc())
if form.validate_on_submit():
companyIndustry = Industry(
name=form.name.data,
description=form.description.data)
# Here we need to give the id of thr role as this is a foreign key
db.session.add(companyIndustry)
db.session.commit()
flash(f'{"Company Idustry registered!"}', 'success')
return render_template('admin/company_register_industry.html',
title='Register Company Industry',
industries=industries,
theme=themeMinibase,
form=form)
return render_template('admin/company_register_industry.html',
title='Register Company Industry',
industries=industries,
theme=themeMinibase,
form=form)
@admin.route("/person_register_role", methods=['GET', 'POST'])
def person_register_role():
form = personRoleForm()
roles = Person_role.query.order_by(Person_role.name.asc())
if form.validate_on_submit():
personRole = Person_role(
name=form.name.data,
description=form.description.data)
# Here we need to give the id of thr role as this is a foreign key
db.session.add(personRole)
db.session.commit()
flash(f'{"Person Role registered!"}', 'success')
return render_template('admin/person_register_role.html',
title='Register Person_role',
theme=themeMinibase,
roles=roles,
form=form)
return render_template('admin/person_register_role.html',
title='Register Person Role',
theme=themeMinibase,
roles=roles,
form=form)
@admin.route("/person_register_competence", methods=['GET', 'POST'])
def person_register_competence():
form = personCompetenceForm()
competences = Person_competence.query.order_by(Person_competence.name.asc())
if form.validate_on_submit():
personCompetence = Person_competence(
name=form.name.data,
description=form.description.data)
# Here we need to give the id of thr role as this is a foreign key
db.session.add(personCompetence)
db.session.commit()
flash(f'{"Person Competence registered!"}', 'success')
return render_template('admin/person_register_competence.html',
title='Register Person Competence',
competences=competences,
theme=themeMinibase,
form=form)
return render_template('admin/person_register_competence.html',
title='Register Person Competence',
theme=themeMinibase,
competences=competences,
form=form)
@admin.route("/status_register", methods=['GET', 'POST'])
def status_register():
form = statusRegisterForm()
statuses = Status.query.order_by(Status.name.asc())
if form.validate_on_submit():
statusRegister = Status(
name=form.name.data,
description=form.description.data)
# Here we need to give the id of thr role as this is a foreign key
db.session.add(statusRegister)
db.session.commit()
flash(f'{"New Status registered!"}', 'success')
return render_template('admin/status_register.html',
title='Register Status',
statuses=statuses,
theme=themeMinibase,
form=form)
return render_template('admin/status_register.html',
title='Register Status',
statuses=statuses,
theme=themeMinibase,
form=form)