Commit ac2fa9fd84c62b6c4eaccb8148205cd8b66acc8e
1 parent
687ef08f
Exists in
master
and in
4 other branches
Use select_options for list fields
Showing
4 changed files
with
43 additions
and
17 deletions
Show diff stats
app/main/routes.py
... | ... | @@ -3,7 +3,7 @@ from flask_login import login_required, current_user |
3 | 3 | |
4 | 4 | from . import bp |
5 | 5 | |
6 | -from app.models import Agent, Project, Service, Capacity, Period, db | |
6 | +from app.models import Agent, Project, Service, Capacity, Period, db, Company, AgentGrade, AgentStatus, AgentBap | |
7 | 7 | from app import db_mgr |
8 | 8 | from app.auth.routes import role_required |
9 | 9 | |
... | ... | @@ -121,13 +121,21 @@ def agent_edit(agent_id=None): |
121 | 121 | # Make the form, filled with existing agent if updating |
122 | 122 | # |
123 | 123 | if request.method == 'GET': |
124 | + companies = Company.query.all() | |
125 | + grades = AgentGrade.query.all() | |
126 | + statuses = AgentStatus.query.all() | |
127 | + baps = AgentBap.query.all() | |
124 | 128 | if agent_id: |
125 | 129 | this_agent = Agent.query.get(int(agent_id)) |
126 | 130 | else: |
127 | 131 | this_agent = Agent() |
128 | 132 | # export to structure for jinja display |
129 | 133 | agent_struct = this_agent.to_struct() |
130 | - return render_template('agent_edit.html', agent=agent_struct) | |
134 | + return render_template('agent_edit.html', agent=agent_struct, | |
135 | + companies=companies, | |
136 | + statuses=statuses, | |
137 | + baps=baps, | |
138 | + grades=grades) | |
131 | 139 | # Or submit for db writing |
132 | 140 | # |
133 | 141 | elif request.method == 'POST': |
... | ... | @@ -145,7 +153,7 @@ def agent_edit(agent_id=None): |
145 | 153 | db.session.add(this_agent) |
146 | 154 | db.session.commit() |
147 | 155 | # we're done |
148 | - flash(f"Agent {this_agent.fullname} "+done_string) | |
156 | + flash(f"Agent {this_agent.fullname} " + done_string) | |
149 | 157 | return redirect(url_for('main.agent', agent_id=this_agent.id)) |
150 | 158 | |
151 | 159 | ... | ... |
app/main/templates/agent.html
... | ... | @@ -33,6 +33,8 @@ |
33 | 33 | <dd class="col-sm-10 text-left">{{agent.company.name}}</dd> |
34 | 34 | <dt class="col-sm-2 text-right">Corps :</dt> |
35 | 35 | <dd class="col-sm-10 text-left"></dd> |
36 | + <dt class="col-sm-2 text-right">Grade :</dt> | |
37 | + <dd class="col-sm-10 text-left">{{agent.grade.name}}</dd> | |
36 | 38 | <dt class="col-sm-2 text-right">BAP :</dt> |
37 | 39 | <dd class="col-sm-10 text-left">{{agent.bap.name}}</dd> |
38 | 40 | {# TODO: puth different spacing #} | ... | ... |
app/main/templates/agent_edit.html
1 | 1 | {% extends "base_page.html" %} |
2 | 2 | {# Set the title that will be used in base_page #} |
3 | 3 | {% if agent['agent_id'] != '' %} |
4 | - {% set subtitle = "Modifier l'agent"+ agent['fullname'] +":" %} | |
4 | + {% set subtitle = "Modifier l'agent "+ agent['fullname'] +":" %} | |
5 | 5 | {% else %} |
6 | 6 | {% set subtitle = "Ajouter un nouvel agent:" %} |
7 | 7 | {% endif %} |
... | ... | @@ -29,20 +29,40 @@ |
29 | 29 | {{ 'checked' if agent['permanent'] == 1 }} value="1"> |
30 | 30 | </div> |
31 | 31 | <div class="form-group"> |
32 | - <label for="company">Structure</label> | |
33 | - <input class="form-control" id="company_id" name="company_id" type="text" value="{{ agent['company_id'] }}"> | |
32 | + <label for="company_id">Structure</label> | |
33 | + <select id="company_id" name="company_id" class="form-select"> | |
34 | + <option selected>---</option> | |
35 | + {% for c in companies %} | |
36 | + <option value="{{ c.id }}" {{ "selected" if c.id == agent['company_id'] }}>{{ c.name }}</option> | |
37 | + {% endfor %} | |
38 | + </select> | |
34 | 39 | </div> |
35 | 40 | <div class="form-group"> |
36 | - <label for="grade">Grade</label> | |
37 | - <input class="form-control" id="grade_id" name="grade_id" type="text" value="{{ agent['grade_id'] }}"> | |
41 | + <label for="grade_id">Grade</label> | |
42 | + <select id="grade_id" name="grade_id" class="form-select"> | |
43 | + <option selected>---</option> | |
44 | + {% for g in grades %} | |
45 | + <option value="{{ g.id }}" {{ "selected" if g.id == agent['grade_id'] }}>{{ g.name }}</option> | |
46 | + {% endfor %} | |
47 | + </select> | |
38 | 48 | </div> |
39 | 49 | <div class="form-group"> |
40 | - <label for="status">Statut</label> | |
41 | - <input class="form-control" id="status_id" name="status_id" type="text" value="{{ agent['status_id'] }}"> | |
50 | + <label for="status_id">Statut</label> | |
51 | + <select id="status_id" name="status_id" class="form-select"> | |
52 | + <option selected>---</option> | |
53 | + {% for s in statuses %} | |
54 | + <option value="{{ s.id }}" {{ "selected" if s.id == agent['status_id'] }}>{{ s.name }}</option> | |
55 | + {% endfor %} | |
56 | + </select> | |
42 | 57 | </div> |
43 | 58 | <div class="form-group"> |
44 | - <label for="bap">Bap</label> | |
45 | - <input class="form-control" id="bap_id" name="bap_id" type="text" value="{{ agent['bap_id'] }}"> | |
59 | + <label for="bap_id">Bap</label> | |
60 | + <select id="bap_id" name="bap_id" class="form-select"> | |
61 | + <option selected>---</option> | |
62 | + {% for b in baps %} | |
63 | + <option value="{{ b.id }}" {{ "selected" if b.id == agent['bap_id'] }}>{{ b.name }}</option> | |
64 | + {% endfor %} | |
65 | + </select> | |
46 | 66 | </div> |
47 | 67 | <input class="btn btn-dark" type="submit" value="Valider"> |
48 | 68 | </form> | ... | ... |
app/models.py
... | ... | @@ -111,11 +111,7 @@ class Agent(db.Model): |
111 | 111 | :return: |
112 | 112 | """ |
113 | 113 | for key in self.export_keys: |
114 | - # deal with checked value | |
115 | - if key in ['permanent', 'virtual']: | |
116 | - setattr(self, key, form_request.form.get(key)) | |
117 | - else: | |
118 | - setattr(self, key, form_request.form[key]) | |
114 | + setattr(self, key, form_request.form.get(key)) | |
119 | 115 | |
120 | 116 | |
121 | 117 | class Service(db.Model): | ... | ... |