from flask import render_template, url_for, flash, redirect, request, Blueprint from minibase import db from minibase.config import themeMinibase from minibase.models import Company, Company_industry, Company_legal_entity, Company_relation, Person_role, Person_competence from minibase.admin.forms import compLegalEntityForm, compRelationForm, compIndustryForm,personRoleForm, personCompetenceForm # Declaring a blueprint admin = Blueprint('admin', __name__) @admin.route("/company_register_legal_entity", methods=['GET', 'POST']) def company_register_legal_entity(): form = compLegalEntityForm() 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', theme=themeMinibase, form=form) return render_template('admin/company_register_legal_entity.html', title='Register Company Legal Entity', theme=themeMinibase, form=form) @admin.route("/company_register_relation", methods=['GET', 'POST']) def company_register_relation(): form = compRelationForm() 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', theme=themeMinibase, form=form) return render_template('admin/company_register_relation.html', title='Register Company Relation', theme=themeMinibase, form=form) @admin.route("/company_register_industry", methods=['GET', 'POST']) def company_register_industry(): form = compIndustryForm() if form.validate_on_submit(): companyIndustry = Company_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', theme=themeMinibase, form=form) return render_template('admin/company_register_industry.html', title='Register Company Industry', theme=themeMinibase, form=form) @admin.route("/person_register_role", methods=['GET', 'POST']) def person_register_role(): form = personRoleForm() 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, form=form) return render_template('admin/person_register_role.html', title='Register Person Role', theme=themeMinibase, form=form) @admin.route("/person_register_competence", methods=['GET', 'POST']) def person_register_competence(): form = personCompetenceForm() 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', theme=themeMinibase, form=form) return render_template('admin/person_register_competence.html', title='Register Person Competence', theme=themeMinibase, form=form)