From ac2fa9fd84c62b6c4eaccb8148205cd8b66acc8e Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Thu, 6 May 2021 16:08:20 +0200 Subject: [PATCH] Use select_options for list fields --- app/main/routes.py | 14 +++++++++++--- app/main/templates/agent.html | 2 ++ app/main/templates/agent_edit.html | 38 +++++++++++++++++++++++++++++--------- app/models.py | 6 +----- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/app/main/routes.py b/app/main/routes.py index 805bcc4..18281e5 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -3,7 +3,7 @@ from flask_login import login_required, current_user from . import bp -from app.models import Agent, Project, Service, Capacity, Period, db +from app.models import Agent, Project, Service, Capacity, Period, db, Company, AgentGrade, AgentStatus, AgentBap from app import db_mgr from app.auth.routes import role_required @@ -121,13 +121,21 @@ def agent_edit(agent_id=None): # Make the form, filled with existing agent if updating # if request.method == 'GET': + companies = Company.query.all() + grades = AgentGrade.query.all() + statuses = AgentStatus.query.all() + baps = AgentBap.query.all() if agent_id: this_agent = Agent.query.get(int(agent_id)) else: this_agent = Agent() # export to structure for jinja display agent_struct = this_agent.to_struct() - return render_template('agent_edit.html', agent=agent_struct) + return render_template('agent_edit.html', agent=agent_struct, + companies=companies, + statuses=statuses, + baps=baps, + grades=grades) # Or submit for db writing # elif request.method == 'POST': @@ -145,7 +153,7 @@ def agent_edit(agent_id=None): db.session.add(this_agent) db.session.commit() # we're done - flash(f"Agent {this_agent.fullname} "+done_string) + flash(f"Agent {this_agent.fullname} " + done_string) return redirect(url_for('main.agent', agent_id=this_agent.id)) diff --git a/app/main/templates/agent.html b/app/main/templates/agent.html index 362e9ad..52c4354 100644 --- a/app/main/templates/agent.html +++ b/app/main/templates/agent.html @@ -33,6 +33,8 @@
{{agent.company.name}}
Corps :
+
Grade :
+
{{agent.grade.name}}
BAP :
{{agent.bap.name}}
{# TODO: puth different spacing #} diff --git a/app/main/templates/agent_edit.html b/app/main/templates/agent_edit.html index bbf541b..10861b1 100644 --- a/app/main/templates/agent_edit.html +++ b/app/main/templates/agent_edit.html @@ -1,7 +1,7 @@ {% extends "base_page.html" %} {# Set the title that will be used in base_page #} {% if agent['agent_id'] != '' %} - {% set subtitle = "Modifier l'agent"+ agent['fullname'] +":" %} + {% set subtitle = "Modifier l'agent "+ agent['fullname'] +":" %} {% else %} {% set subtitle = "Ajouter un nouvel agent:" %} {% endif %} @@ -29,20 +29,40 @@ {{ 'checked' if agent['permanent'] == 1 }} value="1">
- - + +
- - + +
- - + +
- - + +
diff --git a/app/models.py b/app/models.py index 5d2a612..eb26dbf 100644 --- a/app/models.py +++ b/app/models.py @@ -111,11 +111,7 @@ class Agent(db.Model): :return: """ for key in self.export_keys: - # deal with checked value - if key in ['permanent', 'virtual']: - setattr(self, key, form_request.form.get(key)) - else: - setattr(self, key, form_request.form[key]) + setattr(self, key, form_request.form.get(key)) class Service(db.Model): -- libgit2 0.21.2