diff --git a/webinterface/minibase/__init__.py b/webinterface/minibase/__init__.py index 21548bdf..16b9eb04 100644 --- a/webinterface/minibase/__init__.py +++ b/webinterface/minibase/__init__.py @@ -30,17 +30,20 @@ def create_minibase(config_class=Config): # (EMAIL AGENT) Initialisation mail.init_app(app) # (FLASK) Importing and then registering Blueprints (Wievs) + from minibase.users.routes import users from minibase.posts.routes import posts from minibase.main.routes import main - from minibase.errors.handlers import errors from minibase.company.routes import company - from minibase.administration.routes import administration + from minibase.admin.routes import admin + from minibase.person.routes import person + from minibase.errors.handlers import errors app.register_blueprint(users) app.register_blueprint(posts) app.register_blueprint(main) - app.register_blueprint(errors) app.register_blueprint(company) - app.register_blueprint(administration) + app.register_blueprint(admin) + app.register_blueprint(person) + app.register_blueprint(errors) # Returnr The created app return app diff --git a/webinterface/minibase/__pycache__/__init__.cpython-311.pyc b/webinterface/minibase/__pycache__/__init__.cpython-311.pyc index 030a66aa..61e43c24 100644 Binary files a/webinterface/minibase/__pycache__/__init__.cpython-311.pyc and b/webinterface/minibase/__pycache__/__init__.cpython-311.pyc differ diff --git a/webinterface/minibase/__pycache__/models.cpython-311.pyc b/webinterface/minibase/__pycache__/models.cpython-311.pyc index 331d6468..c2734476 100644 Binary files a/webinterface/minibase/__pycache__/models.cpython-311.pyc and b/webinterface/minibase/__pycache__/models.cpython-311.pyc differ diff --git a/webinterface/minibase/administration/__init.py__ b/webinterface/minibase/admin/__init.py__ similarity index 100% rename from webinterface/minibase/administration/__init.py__ rename to webinterface/minibase/admin/__init.py__ diff --git a/webinterface/minibase/admin/__pycache__/forms.cpython-311.pyc b/webinterface/minibase/admin/__pycache__/forms.cpython-311.pyc new file mode 100644 index 00000000..d7c91408 Binary files /dev/null and b/webinterface/minibase/admin/__pycache__/forms.cpython-311.pyc differ diff --git a/webinterface/minibase/admin/__pycache__/routes.cpython-311.pyc b/webinterface/minibase/admin/__pycache__/routes.cpython-311.pyc new file mode 100644 index 00000000..2bbeefee Binary files /dev/null and b/webinterface/minibase/admin/__pycache__/routes.cpython-311.pyc differ diff --git a/webinterface/minibase/admin/__pycache__/utils.cpython-311.pyc b/webinterface/minibase/admin/__pycache__/utils.cpython-311.pyc new file mode 100644 index 00000000..e54c2662 Binary files /dev/null and b/webinterface/minibase/admin/__pycache__/utils.cpython-311.pyc differ diff --git a/webinterface/minibase/admin/forms.py b/webinterface/minibase/admin/forms.py new file mode 100644 index 00000000..bda9d929 --- /dev/null +++ b/webinterface/minibase/admin/forms.py @@ -0,0 +1,69 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField +from wtforms.validators import DataRequired, ValidationError +from minibase.models import Company_legal_entity, Company_industry, Company_relation, Person_role, Person_competence + + +class compIndustryForm(FlaskForm): # Defines the form class to be used for the user registretion + # Decalarion of the fields for the form and it's propereties + name = StringField('Name', validators=[DataRequired()]) + description = StringField('Description', validators=[DataRequired()]) + submit = SubmitField('Register Industry') + + # Queries to be made in order to validate the form : If Relation Type exitst # Case Insensistive + def validate_name(self, name): + industry_query = Company_industry.query.filter(Company_industry.name.ilike(name.data)).first() # Database Querry ilike means case insessitive + if industry_query: + raise ValidationError('That Industry Type is already registered') + + +class compRelationForm(FlaskForm): # Defines the form class to be used for the user registretion + # Decalarion of the fields for the form and it's propereties + name = StringField('Name', validators=[DataRequired()]) + description = StringField('Description', validators=[DataRequired()]) + submit = SubmitField('Register Relation') + + # Queries to be made in order to validate the form : If Relation Type exitst # Case Insensistive + def validate_name(self, name): + relation_query = Company_relation.query.filter(Company_relation.name.ilike(name.data)).first() # Database Querry ilike means case insessitive + if relation_query: + raise ValidationError('That Relation Type is already registered') + + +class compLegalEntityForm(FlaskForm): # Defines the form class to be used for the user registretion + # Decalarion of the fields for the form and it's propereties + name = StringField('Name', validators=[DataRequired()]) + description = StringField('Description', validators=[DataRequired()]) + submit = SubmitField('Register Legal Entity') + + # Queries to be made in order to validate the form : If Legal Entity exitst # Case Insensistive + def validate_name(self, name): + legal_entity_query = Company_legal_entity.query.filter(Company_legal_entity.name.ilike(name.data)).first() # Database Querry ilike means case insessitive + if legal_entity_query: + raise ValidationError('That Legal Entity is already registered') + + +class personRoleForm(FlaskForm): # Defines the form class to be used for the user registretion + # Decalarion of the fields for the form and it's propereties + name = StringField('Name', validators=[DataRequired()]) + description = StringField('Description', validators=[DataRequired()]) + submit = SubmitField('Register Role') + + # Queries to be made in order to validate the form : If Person Role exitst # Case Insensistive + def validate_name(self, name): + person_role_query = Person_role.query.filter(Person_role.name.ilike(name.data)).first() # Database Querry ilike means case insessitive + if person_role_query: + raise ValidationError('That Person Role is already registered') + + +class personCompetenceForm(FlaskForm): # Defines the form class to be used for the user registretion + # Decalarion of the fields for the form and it's propereties + name = StringField('Name', validators=[DataRequired()]) + description = StringField('Description', validators=[DataRequired()]) + submit = SubmitField('Register Role') + + # Queries to be made in order to validate the form : If Person Role exitst # Case Insensistive + def validate_name(self, name): + person_competence_query = Person_role.query.filter(Person_role.name.ilike(name.data)).first() # Database Querry ilike means case insessitive + if person_competence_query: + raise ValidationError('That Person Conpewtence is already registered') diff --git a/webinterface/minibase/admin/routes.py b/webinterface/minibase/admin/routes.py new file mode 100644 index 00000000..3f698c28 --- /dev/null +++ b/webinterface/minibase/admin/routes.py @@ -0,0 +1,123 @@ +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) diff --git a/webinterface/minibase/admin/utils.py b/webinterface/minibase/admin/utils.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/webinterface/minibase/admin/utils.py @@ -0,0 +1 @@ + diff --git a/webinterface/minibase/administration/__pycache__/forms.cpython-311.pyc b/webinterface/minibase/administration/__pycache__/forms.cpython-311.pyc deleted file mode 100644 index c2457b52..00000000 Binary files a/webinterface/minibase/administration/__pycache__/forms.cpython-311.pyc and /dev/null differ diff --git a/webinterface/minibase/administration/__pycache__/routes.cpython-311.pyc b/webinterface/minibase/administration/__pycache__/routes.cpython-311.pyc deleted file mode 100644 index 27540679..00000000 Binary files a/webinterface/minibase/administration/__pycache__/routes.cpython-311.pyc and /dev/null differ diff --git a/webinterface/minibase/administration/__pycache__/utils.cpython-311.pyc b/webinterface/minibase/administration/__pycache__/utils.cpython-311.pyc deleted file mode 100644 index 18f26334..00000000 Binary files a/webinterface/minibase/administration/__pycache__/utils.cpython-311.pyc and /dev/null differ diff --git a/webinterface/minibase/administration/forms.py b/webinterface/minibase/administration/forms.py deleted file mode 100644 index 8c3484d9..00000000 --- a/webinterface/minibase/administration/forms.py +++ /dev/null @@ -1,31 +0,0 @@ -from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField -from wtforms.validators import DataRequired - - -class compIndustryForm(FlaskForm): # Defines the form class to be used for the user registretion - # Decalarion of the fields for the form and it's propereties - name = StringField('Name', validators=[DataRequired()]) - description = StringField('Description', validators=[DataRequired()]) - submit = SubmitField('Register Industry') - - -class compRelationForm(FlaskForm): # Defines the form class to be used for the user registretion - # Decalarion of the fields for the form and it's propereties - name = StringField('Name', validators=[DataRequired()]) - description = StringField('Description', validators=[DataRequired()]) - submit = SubmitField('Register Relation') - - -class compLegalEntityForm(FlaskForm): # Defines the form class to be used for the user registretion - # Decalarion of the fields for the form and it's propereties - name = StringField('Name', validators=[DataRequired()]) - description = StringField('Description', validators=[DataRequired()]) - submit = SubmitField('Register Legal Entity') - - -class personRole(FlaskForm): # Defines the form class to be used for the user registretion - # Decalarion of the fields for the form and it's propereties - name = StringField('Name', validators=[DataRequired()]) - description = StringField('Description', validators=[DataRequired()]) - submit = SubmitField('Register Role') diff --git a/webinterface/minibase/administration/routes.py b/webinterface/minibase/administration/routes.py deleted file mode 100644 index 93cacaf2..00000000 --- a/webinterface/minibase/administration/routes.py +++ /dev/null @@ -1,77 +0,0 @@ -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 -from minibase.administration.forms import compLegalEntityForm, compRelationForm, compIndustryForm - -# Declaring a blueprint -administration = Blueprint('administration', __name__) - - -@administration.route("/administration_company_legal_entity", methods=['GET', 'POST']) -def administration_company_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('administration_company_legal_entity.html', - title='Register Company Legal Entity', - theme=themeMinibase, - form=form) - - return render_template('administration_company_legal_entity.html', - title='Register Company Legal Entity', - theme=themeMinibase, - form=form) - - -@administration.route("/administration_company_relation", methods=['GET', 'POST']) -def administration_company_relation(): - form = compRelationForm() - if form.validate_on_submit(): - companyLegal = 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(companyLegal) - db.session.commit() - - flash(f'{"Company Relation registered!"}', 'success') - return render_template('administration_company_relation.html', - title='Register Company Relation', - theme=themeMinibase, - form=form) - - return render_template('administration_company_relation.html', - title='Register Company Relation', - theme=themeMinibase, - form=form) - - -@administration.route("/administration_company_industry", methods=['GET', 'POST']) -def administration_company_industry(): - form = compIndustryForm() - if form.validate_on_submit(): - companyLegal = 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(companyLegal) - db.session.commit() - - flash(f'{"Company Idustry registered!"}', 'success') - return render_template('administration_company_industry.html', - title='Register Company Industry', - theme=themeMinibase, - form=form) - - return render_template('administration_company_industry.html', - title='Register Company Industry', - theme=themeMinibase, - form=form) diff --git a/webinterface/minibase/administration/utils.py b/webinterface/minibase/administration/utils.py deleted file mode 100644 index 94e89257..00000000 --- a/webinterface/minibase/administration/utils.py +++ /dev/null @@ -1,11 +0,0 @@ -from minibase.models import Countries - -# Retunrs the query of all awailable Country names on the table named Countries -# Note that the formating is done during the SQLAlchemy Table declaration. -# Important note This table is ImporteD externally from a modifier SQL version of -# Github : https://github.com/dr5hn/countries-states-cities-database -def country_choices(): - choices = Countries.query.all() - return choices - - diff --git a/webinterface/minibase/company/__pycache__/forms.cpython-311.pyc b/webinterface/minibase/company/__pycache__/forms.cpython-311.pyc index 4401a534..f283baf0 100644 Binary files a/webinterface/minibase/company/__pycache__/forms.cpython-311.pyc and b/webinterface/minibase/company/__pycache__/forms.cpython-311.pyc differ diff --git a/webinterface/minibase/company/__pycache__/routes.cpython-311.pyc b/webinterface/minibase/company/__pycache__/routes.cpython-311.pyc index 5d490087..479f15ea 100644 Binary files a/webinterface/minibase/company/__pycache__/routes.cpython-311.pyc and b/webinterface/minibase/company/__pycache__/routes.cpython-311.pyc differ diff --git a/webinterface/minibase/company/forms.py b/webinterface/minibase/company/forms.py index a4028958..7842ccb9 100644 --- a/webinterface/minibase/company/forms.py +++ b/webinterface/minibase/company/forms.py @@ -1,27 +1,31 @@ from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, IntegerField, SelectField -from wtforms.validators import DataRequired, Length, ValidationError -from minibase.models import Company, Company_relation -import minibase.company.utils as utils -import minibase.administration.utils as adminUtils +from wtforms.validators import DataRequired, Length, ValidationError, Optional +from minibase.models import Company +import minibase.database.utils as DbUtils -class companyForm(FlaskForm): # Defines the form class to be used for the user registretion +# Defines the form class to be used for the user registretion +class companyForm(FlaskForm): # Decalarion of the fields for the form and it's propereties - name = StringField('Name', validators=[DataRequired(), Length(min=3, max=100)]) - legal_entity = SelectField('Legal Entity', choices=utils.company_legal_entity_choices, validators=[DataRequired()]) - relation = SelectField('Relation', choices=utils.company_relation_choices, validators=[DataRequired()]) - country = SelectField('Country', choices=adminUtils.country_choices, validators=[DataRequired()]) + company_name = StringField('Name', validators=[DataRequired(), Length(min=3, max=20)]) + legal_entity_id = SelectField('Legal Entity', choices=DbUtils.company_legal_entity_choices, validators=[DataRequired()]) + relation_id = SelectField('Relation', choices=DbUtils.company_relation_choices, validators=[DataRequired()]) + website = StringField('Website', validators=[Optional(), Length(min=3, max=100)]) + country = SelectField('Country', choices=DbUtils.country_choices,validators=[DataRequired()]) state = StringField('State', validators=[DataRequired()]) city = StringField('City', validators=[DataRequired()]) post = IntegerField('Zip', validators=[DataRequired()]) street = StringField('Street', validators=[DataRequired()]) no = IntegerField('No', validators=[DataRequired()]) - industry = SelectField('Area', choices=utils.company_industry_choices, validators=[DataRequired()]) + industry_id = SelectField('Area', choices=DbUtils.company_industry_choices, validators=[DataRequired()]) submit = SubmitField('Register Company') - def validate_company_duplicate(self, name, country, relation): - companyName = Company.query.filter_by(name=name.data).first() - if companyName: - raise ValidationError('That Company Allredy Exitst Please modify it instead') - + # Queries to be made in order to validate the form : If Company name exitst within the same country + # Case Insensistive + def validate_company_name(self, company_name): + company_query = Company.query.filter(Company.name.ilike(self.company_name.data)) # Database Querry ilike means case insessitive + for company in company_query: + if company.name: + if company.country_bill == self.country.data: + raise ValidationError('This company in this contry alredy exist') diff --git a/webinterface/minibase/company/routes.py b/webinterface/minibase/company/routes.py index ea3cc99e..32081747 100644 --- a/webinterface/minibase/company/routes.py +++ b/webinterface/minibase/company/routes.py @@ -14,28 +14,33 @@ def company_register(): form = companyForm() if form.validate_on_submit(): company = Company( - name=form.name.data, + name=form.company_name.data, + website=form.website.data, country_bill=form.country.data, state_bill=form.state.data, city_bill=form.city.data, - postal_code_bill=form.post.data, + post_code_bill=form.post.data, street_bill=form.street.data, street_no_bill=form.no.data, country_ship=form.country.data, state_ship=form.state.data, city_ship=form.city.data, - postal_code_ship=form.post.data, + post_code_ship=form.post.data, street_ship=form.street.data, street_no_ship=form.no.data, - industry=utils.getIndustryId(form.industry.data), - relation=utils.getRelationId(form.relation.data), - legal_entity=utils.getLegalEntityId(form.legal_entity.data)) + industry_id=utils.getIndustryId(form.industry_id.data), + relation_id=utils.getRelationId(form.relation_id.data), + legal_entity_id=utils.getLegalEntityId(form.legal_entity_id.data)) # Here we need to give the id of thr role as this is a foreign key db.session.add(company) db.session.commit() - flash(f'{"Company succesfull registered!"} { company.industry} ', 'success') - return redirect(url_for('company.company_register')) + flash(f'{"Company succesfull registered!"}', 'success') + return render_template('company_register.html', + title='Register Company', + theme=themeMinibase, + form=form) +# return redirect(url_for('company.company_register')) return render_template('company_register.html', title='Register Company', diff --git a/webinterface/minibase/database/__pycache__/utils.cpython-311.pyc b/webinterface/minibase/database/__pycache__/utils.cpython-311.pyc new file mode 100644 index 00000000..137541b7 Binary files /dev/null and b/webinterface/minibase/database/__pycache__/utils.cpython-311.pyc differ diff --git a/webinterface/minibase/database/utils.py b/webinterface/minibase/database/utils.py new file mode 100644 index 00000000..19d783a8 --- /dev/null +++ b/webinterface/minibase/database/utils.py @@ -0,0 +1,133 @@ +from minibase.models import Company, Company_industry, Company_relation, Company_legal_entity +from minibase.models import Countries, Person, Person_role, Person_competence + + +# Gets the id of company from the formated output defined at models.py for the Company Model +# The argument formatedCompanySelection is formated by SQLAlchemy in models.py files +# Please look there before changing anything here. +def getCompanyId(formatedCompanySelection): + text = formatedCompanySelection.split(",") + return text[2] # Corresponds to the ID of the Company + + +# Gets the id of Person's role +def getPersonRoleId(nameForId): + selection = Person_role.query.filter_by(name=nameForId).first() + return selection.id + +# Gets the id of Person's competence +def getPersonCompetenceId(nameForId): + selection = Person_competence.query.filter_by(name=nameForId).first() + return selection.id + + +# Gets the country of the company based on it's id +def getCompanyCountry(companyId): + selection = Company.query.filter_by(id=companyId).first() + return selection.country_bill + + +# Gets the state of the company based on it's id +def getCompanyState(companyId): + selection = Company.query.filter_by(id=companyId).first() + return selection.street_bill + + +# Gets the city of the company based on it's id +def getCompanyCity(companyId): + selection = Company.query.filter_by(id=companyId).first() + return selection.city_bill + + +# Gets the Postal Code of the company based on it's id +def getCompanyPostCode(companyId): + selection = Company.query.filter_by(id=companyId).first() + return selection.post_code_bill + + +# Gets the Name of the street of the company based on it's id +def getCompanyStreetName(companyId): + selection = Company.query.filter_by(id=companyId).first() + return selection.street_bill + + +# Gets the Number of the street of the company based on it's id +def getCompanyStreetNo(companyId): + selection = Company.query.filter_by(id=companyId).first() + return selection.street_no_bill + + +# Returns the query of all awailable companie names on the table named Company +# Note that the formating is done during the SQLAlchemy Table declaration. +def person_role_choices(): + choices = Person_role.query.all() + return choices + + +# Returns the query of all awailable companie names on the table named Company +# Note that the formating is done during the SQLAlchemy Table declaration. +def person_competence_choices(): + choices = Person_competence.query.all() + return choices + + +# Returns the query of all awailable companie names on the table named Company +# Note that the formating is done during the SQLAlchemy Table declaration. +def company_choices(): + choices = Company.query.all() + return choices + + +# Retunrs the qurry of all awailable industrie names on the table named Company_industry +# Note that the formating is done during the SQLAlchemy Table declaration. +def company_industry_choices(): + choices = Company_industry.query.all() + return choices + + +# Retunrs the query of all awailable legal entity names on the table named Company_legal_entity +# Note that the formating is done during the SQLAlchemy Table declaration. +def company_legal_entity_choices(): + choices = Company_legal_entity.query.all() + return choices + + +# Retunrs the query of all awailable Relation names on the table named Company_relation +# Note that the formating is done during the SQLAlchemy Table declaration. +def company_relation_choices(): + choices = Company_relation.query.all() + return choices + + +# The Company Model has Industry Column as a foreign key and it requires the Industry's ID +# And not the name. so this function returns the right ID of the name shown at the +# Register Company Form +def getIndustryId(nameForId): + selection = Company_industry.query.filter_by(name=nameForId).first() # Gets the id of Role + return selection.id + + +# The Company Model has Relation Column as a foreign key and it requires the Industry's ID +# And not the name. so this function returns the right ID of the name shown at the +# Register Company Form +def getRelationId(nameForId): + selection = Company_relation.query.filter_by(name=nameForId).first() # Gets the id of Role + return selection.id + + +# The Company Model has Legal Entity Column as a foreign key and it requires the Industry's ID +# And not the name. so this function returns the right ID of the name shown at the +# Register Company Form +def getLegalEntityId(nameForId): + selection = Company_legal_entity.query.filter_by(name=nameForId).first() # Gets the id of Role + return selection.id + + +# Retunrs the query of all awailable Country names on the table named Countries +# Note that the formating is done during the SQLAlchemy Table declaration. +# Important note This table is ImporteD externally from a modifier SQL version of +# Github : https://github.com/dr5hn/countries-states-cities-database +def country_choices(): + choices = Countries.query.all() + return choices + diff --git a/webinterface/minibase/main/__pycache__/routes.cpython-311.pyc b/webinterface/minibase/main/__pycache__/routes.cpython-311.pyc index 4db2afeb..d427e3c5 100644 Binary files a/webinterface/minibase/main/__pycache__/routes.cpython-311.pyc and b/webinterface/minibase/main/__pycache__/routes.cpython-311.pyc differ diff --git a/webinterface/minibase/main/routes.py b/webinterface/minibase/main/routes.py index 97bf14c8..bb881731 100644 --- a/webinterface/minibase/main/routes.py +++ b/webinterface/minibase/main/routes.py @@ -1,6 +1,7 @@ from flask import render_template, request, Blueprint from minibase.models import Post from minibase.config import themeMinibase +from minibase import db # Declaring a blueprint main = Blueprint('main', __name__) @@ -25,3 +26,12 @@ def about(): @main.route("/customer") def customer(): return render_template('customer.html', theme=themeMinibase, title='About') + + +@main.cli.command("initdb") +def reset_db(): + """Drops and Creates fresh database""" + db.drop_all() + db.create_all() + + print("Initialized default DB") diff --git a/webinterface/minibase/models.py b/webinterface/minibase/models.py index 0eb15068..7571c931 100644 --- a/webinterface/minibase/models.py +++ b/webinterface/minibase/models.py @@ -48,50 +48,75 @@ class Countries(db.Model): class Company(db.Model): id = db.Column(db.Integer, nullable=False, primary_key=True) name = db.Column(db.String(100), nullable=False) - country_bill = db.Column(db.String(100), nullable=False) - state_bill = db.Column(db.String(100), nullable=False) - city_bill = db.Column(db.String(100), nullable=False) - postal_code_bill = db.Column(db.Integer, nullable=False) + legal_entity_id = db.Column(db.Integer, db.ForeignKey('company_legal_entity.id'), nullable=False) + relation_id = db.Column(db.Integer, db.ForeignKey('company_relation.id'), nullable=False) + industry_id = db.Column(db.Integer, db.ForeignKey('company_industry.id'), nullable=False) + + main_company = db.Column(db.Integer, nullable=False, default=1) + subsidiary_of = db.Column(db.Integer, nullable=True, default='') + website = db.Column(db.String(100), nullable=True, default='') + street_bill = db.Column(db.String(100), nullable=False) street_no_bill = db.Column(db.Integer, nullable=False) - country_ship = db.Column(db.String(100), nullable=False) - state_ship = db.Column(db.String(100), nullable=False) - city_ship = db.Column(db.String(100), nullable=False) - postal_code_ship = db.Column(db.Integer, nullable=False) + city_bill = db.Column(db.String(100), nullable=False) + post_code_bill = db.Column(db.Integer, nullable=False) + state_bill = db.Column(db.String(100), nullable=False) + country_bill = db.Column(db.String(100), nullable=False) + street_ship = db.Column(db.String(100), nullable=False) street_no_ship = db.Column(db.Integer, nullable=False) - main_company = db.Column(db.Integer, nullable=False, default=1) - subsidiary_of = db.Column(db.Integer, nullable=True, default='') + city_ship = db.Column(db.String(100), nullable=False) + post_code_ship = db.Column(db.Integer, nullable=False) + state_ship = db.Column(db.String(100), nullable=False) + country_ship = db.Column(db.String(100), nullable=False) + classification = db.Column(db.Integer, nullable=False, default=0) comment = db.Column(db.String(300), nullable=True) + image_file = db.Column(db.String(20), nullable=False, default='default_company.jpg') + + employees = db.relationship('Person', backref='company', lazy=True) + notes = db.relationship('Company_note', backref='concerns', lazy=True) + upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) - industry = db.Column(db.Integer, db.ForeignKey('company_industry.id'), nullable=False) - relation = db.Column(db.Integer, db.ForeignKey('company_relation.id'), nullable=False) - legal_entity = db.Column(db.Integer, db.ForeignKey('company_legal_entity.id'), nullable=False) + + # returns a more information-rich, or official, string representation of an object + # >>> company.query.all() + # [1, ComanyName, CompanyCounntry] (Do not change this presentation + # it will corrupt: the getCompanyId function in minibase.dabase.utils + def __repr__(self): + return f"{self.name}, {self.country_bill}, {self.id}" class Person(db.Model): id = db.Column(db.Integer, nullable=False, primary_key=True) name = db.Column(db.String(50), nullable=False) last_name = db.Column(db.String(50), nullable=False) - date_of_birth = db.Column(db.Date, nullable=False) + date_of_birth = db.Column(db.Date, nullable=True, default='') + + company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False) + role_id = db.Column(db.Integer, db.ForeignKey('person_role.id'), nullable=False) + competence_id = db.Column(db.Integer, db.ForeignKey('person_competence.id'), nullable=False) + + mail_prof = db.Column(db.String(320), nullable=False) + mail_priv = db.Column(db.String(320), nullable=True, default='') tel_prof_fix = db.Column(db.String(30), nullable=True, default='') tel_prof_mobile = db.Column(db.String(30), nullable=True, default='') tel_priv_fix = db.Column(db.String(30), nullable=True, default='') tel_priv_mobile = db.Column(db.String(30), nullable=True, default='') - mail_prof = db.Column(db.String(320), nullable=False) - mail_priv = db.Column(db.String(320), nullable=True, default='') - country = db.Column(db.String(75), nullable=False) - state = db.Column(db.String(75), nullable=True, default='') - city = db.Column(db.String(75), nullable=True, default='') - post_code = db.Column(db.String(10), nullable=True, default='') + street_name = db.Column(db.String(150), nullable=True, default='') street_no = db.Column(db.Integer, nullable=True, default='') + city = db.Column(db.String(75), nullable=True, default='') + post_code = db.Column(db.String(10), nullable=True, default='') + state = db.Column(db.String(75), nullable=True, default='') + country = db.Column(db.String(75), nullable=True, default='') + + notes = db.relationship('Person_note', backref='concerns', lazy=True) + + image_file = db.Column(db.String(20), nullable=False, default='default_person.jpg') upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) - company = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False) - role = db.Column(db.Integer, db.ForeignKey('person_role.id'), nullable=False) class Person_role(db.Model): @@ -100,6 +125,7 @@ class Person_role(db.Model): description = db.Column(db.String(300), nullable=False) upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) + # returns a more information-rich, or official, string representation of an object # >>> Company_industry.query.all() # >>> [('1', 'Indsutrial'), ('2', 'Consumer')] @@ -107,6 +133,19 @@ class Person_role(db.Model): return f"{self.name}" +class Person_competence(db.Model): + id = db.Column(db.Integer, nullable=False, primary_key=True) + name = db.Column(db.String(50), nullable=False) + description = db.Column(db.String(300), nullable=False) + upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) + + # returns a more information-rich, or official, string representation of an object + # >>> Company_industry.query.all() + # >>> [('1', 'Indsutrial'), ('2', 'Consumer')] + def __repr__(self): + return f"{self.name}" + class Company_industry(db.Model): id = db.Column(db.Integer, nullable=False, primary_key=True) @@ -114,6 +153,8 @@ class Company_industry(db.Model): description = db.Column(db.String(300), nullable=False) upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) + companies = db.relationship('Company', backref='companies', lazy=True) + # returns a more information-rich, or official, string representation of an object # >>> Company_industry.query.all() # >>> [('1', 'Indsutrial'), ('2', 'Consumer')] @@ -127,6 +168,7 @@ class Company_relation(db.Model): description = db.Column(db.String(300), nullable=False) upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) + # returns a more information-rich, or official, string representation of an object # >>> Company_industry.query.all() # >>> [('1', 'Indsutrial'), ('2', 'Consumer')] @@ -140,6 +182,21 @@ class Company_legal_entity(db.Model): description = db.Column(db.String(300), nullable=False) upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) + + # returns a more information-rich, or official, string representation of an object + # >>> Company_industry.query.all() + # >>> [('1', 'Indsutrial'), ('2', 'Consumer')] + def __repr__(self): + return f"{self.name}" + + +class Status(db.Model): + id = db.Column(db.Integer, nullable=False, primary_key=True) + name = db.Column(db.String(50), nullable=False) + description = db.Column(db.String(300), nullable=False) + upload_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + last_update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) + # returns a more information-rich, or official, string representation of an object # >>> Company_industry.query.all() # >>> [('1', 'Indsutrial'), ('2', 'Consumer')] @@ -177,6 +234,7 @@ class User(db.Model, UserMixin): class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) + date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) @@ -184,3 +242,31 @@ class Post(db.Model): # returns a more information-rich, or official, string representation of an object def __repr__(self): return f"User('{self.title}', '{self.date_posted}')" + + +class Person_note(db.Model): + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(100), nullable=False) + content = db.Column(db.Text, nullable=False) + status = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + date_due = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + person_id = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=False) + + # returns a more information-rich, or official, string representation of an object + def __repr__(self): + return f"{self.title}, {self.status}, {self.content}" + + +class Company_note(db.Model): + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(100), nullable=False) + content = db.Column(db.Text, nullable=False) + status = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + date_due = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False) + + # returns a more information-rich, or official, string representation of an object + def __repr__(self): + return f"{self.title}, {self.status}, {self.content}" diff --git a/webinterface/minibase/person/__pycache__/forms.cpython-311.pyc b/webinterface/minibase/person/__pycache__/forms.cpython-311.pyc new file mode 100644 index 00000000..cee55a9b Binary files /dev/null and b/webinterface/minibase/person/__pycache__/forms.cpython-311.pyc differ diff --git a/webinterface/minibase/person/__pycache__/routes.cpython-311.pyc b/webinterface/minibase/person/__pycache__/routes.cpython-311.pyc new file mode 100644 index 00000000..6cfebc2a Binary files /dev/null and b/webinterface/minibase/person/__pycache__/routes.cpython-311.pyc differ diff --git a/webinterface/minibase/person/forms.py b/webinterface/minibase/person/forms.py new file mode 100644 index 00000000..2277c8fb --- /dev/null +++ b/webinterface/minibase/person/forms.py @@ -0,0 +1,33 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, SelectField, DateField +from wtforms.validators import DataRequired, Length, ValidationError, Email, Optional +from minibase.models import Person +import minibase.database.utils as DbUtils + + +# Defines the form class to be used for the user registretion +class personForm(FlaskForm): + # Decalarion of the fields for the form and it's propereties + name = StringField('Name', validators=[DataRequired(), Length(min=3, max=20)]) + last_name = StringField('Last Name', validators=[DataRequired(), Length(min=3, max=20)]) + date_of_birth = DateField('Birth Date') + mail_prof = StringField('Email Professional', validators=[DataRequired(), Email()]) + mail_priv = StringField('Email Private', validators=[Optional(), Email()]) + tel_prof_fix = StringField('Tel Professional Fix', validators=[Optional()]) + tel_prof_mobile = StringField('Tel Professional Mob', validators=[Optional()]) + tel_priv_fix = StringField('Tel Private Fix', validators=[Optional()]) + tel_priv_mobile = StringField('Tel Private Mob', validators=[Optional()]) + company_id = SelectField('Company', choices=DbUtils.company_choices, validators=[DataRequired()]) + competence_id = SelectField('Competence', choices=DbUtils.person_competence_choices, validators=[DataRequired()]) + role_id = SelectField('Role', choices=DbUtils.person_role_choices, validators=[DataRequired()]) + submit = SubmitField('Register Person') + + # Queries to be made in order to validate the form : If person with this name exitst within the same company + # Case Insensistive + def validate_person(self): + person_query = Person.query.filter(Person.name.ilike(self.name.data)) # Database Querry ilike means case insessitive + for person in person_query: + if person.name: + if person.last_name.lower() == self.last_name.data.lower(): + if person.company == self.company.data: + raise ValidationError('This person working in this company alredy exist') diff --git a/webinterface/minibase/person/routes.py b/webinterface/minibase/person/routes.py new file mode 100644 index 00000000..7a292be2 --- /dev/null +++ b/webinterface/minibase/person/routes.py @@ -0,0 +1,50 @@ +from flask import render_template, url_for, flash, redirect, request, Blueprint +from minibase import db +from minibase.config import themeMinibase +from minibase.models import Person +from minibase.person.forms import personForm +import minibase.database.utils as DbUtils + +# Declaring a blueprint +person = Blueprint('person', __name__) + + +@person.route("/person_register", methods=['GET', 'POST']) +def person_register(): + form = personForm() + if form.validate_on_submit(): + companyID = DbUtils.getCompanyId(form.company_id.data) + person = Person( + name=form.name.data, + last_name=form.last_name.data, + date_of_birth=form.date_of_birth.data, + tel_prof_fix=form.tel_prof_fix.data, + tel_prof_mobile=form.tel_prof_mobile.data, + tel_priv_fix=form.tel_priv_fix.data, + tel_priv_mobile=form.tel_priv_mobile.data, + mail_prof=form.mail_prof.data, + mail_priv=form.mail_priv.data, + company_id=companyID, + country=DbUtils.getCompanyCountry(companyID), + state=DbUtils.getCompanyState(companyID), + city=DbUtils.getCompanyCity(companyID), + post_code=DbUtils.getCompanyPostCode(companyID), + street_name=DbUtils.getCompanyStreetName(companyID), + street_no=DbUtils.getCompanyStreetNo(companyID), + role_id=DbUtils.getPersonRoleId(form.role_id.data), + competence_id=DbUtils.getPersonCompetenceId(form.competence_id.data)) + + db.session.add(person) + db.session.commit() + + flash(f'{"Company succesfull registered!"}', 'success') + return render_template('person_register.html', + title='Register Person', + theme=themeMinibase, + form=form) +# return redirect(url_for('company.company_register')) + + return render_template('person_register.html', + title='Register Person', + theme=themeMinibase, + form=form) diff --git a/webinterface/minibase/person/utils.py b/webinterface/minibase/person/utils.py new file mode 100644 index 00000000..e69de29b diff --git a/webinterface/minibase/site.db b/webinterface/minibase/site.db index 22214425..93e44643 100644 Binary files a/webinterface/minibase/site.db and b/webinterface/minibase/site.db differ diff --git a/webinterface/minibase/static/pics/default_company.jpg b/webinterface/minibase/static/pics/default_company.jpg new file mode 100644 index 00000000..38f286f6 Binary files /dev/null and b/webinterface/minibase/static/pics/default_company.jpg differ diff --git a/webinterface/minibase/static/pics/default_person.jpg b/webinterface/minibase/static/pics/default_person.jpg new file mode 100644 index 00000000..38f286f6 Binary files /dev/null and b/webinterface/minibase/static/pics/default_person.jpg differ diff --git a/webinterface/minibase/templates/administration_company_industry.html b/webinterface/minibase/templates/admin/company_register_industry.html similarity index 100% rename from webinterface/minibase/templates/administration_company_industry.html rename to webinterface/minibase/templates/admin/company_register_industry.html diff --git a/webinterface/minibase/templates/administration_company_legal_entity.html b/webinterface/minibase/templates/admin/company_register_legal_entity.html similarity index 100% rename from webinterface/minibase/templates/administration_company_legal_entity.html rename to webinterface/minibase/templates/admin/company_register_legal_entity.html diff --git a/webinterface/minibase/templates/administration_company_relation.html b/webinterface/minibase/templates/admin/company_register_relation.html similarity index 99% rename from webinterface/minibase/templates/administration_company_relation.html rename to webinterface/minibase/templates/admin/company_register_relation.html index 460f58a3..0065e310 100644 --- a/webinterface/minibase/templates/administration_company_relation.html +++ b/webinterface/minibase/templates/admin/company_register_relation.html @@ -1,4 +1,6 @@ {% extends "layout.html" %} + + {% block content %}