Commit 1f54a207e4d1df9225abb19c33aa450e26e4c7f0
1 parent
8bcfce10
Exists in
master
and in
4 other branches
New routes and tpl: Capacity view, edit, delete
Showing
7 changed files
with
122 additions
and
12 deletions
Show diff stats
app/main/routes.py
... | ... | @@ -333,6 +333,38 @@ def capacities(): |
333 | 333 | capacities=all_capacities) |
334 | 334 | |
335 | 335 | |
336 | +@bp.route('/capacity/<capacity_id>') | |
337 | +@role_required('admin') | |
338 | +def capacity(capacity_id): | |
339 | + # get capacity | |
340 | + this_capacity = Capacity.query.get(int(capacity_id)) | |
341 | + # pass to template | |
342 | + return render_template('capacity.html', subtitle=f"{this_capacity.name}", | |
343 | + capacity=this_capacity) | |
344 | + | |
345 | + | |
346 | +@bp.route('/capacity/create', methods=('POST', 'GET')) | |
347 | +@bp.route('/capacity/<capacity_id>/edit', methods=('POST', 'GET')) | |
348 | +@role_required('admin') | |
349 | +def capacity_edit(capacity_id=None): | |
350 | + return form_manager(object_class=Capacity, | |
351 | + object_id_key='capacity_id', | |
352 | + object_id=capacity_id, | |
353 | + form_template='capacity_form.html', | |
354 | + form_struct={}, | |
355 | + urlfor_exist_dict={'endpoint': 'main.capacity_edit'}, | |
356 | + urlfor_done_dict={'endpoint': 'main.capacity', 'capacity_id': None}) | |
357 | + | |
358 | + | |
359 | +@bp.route('/capacity/<capacity_id>/delete', methods=('POST', 'GET')) | |
360 | +@role_required('admin') | |
361 | +def capacity_delete(capacity_id=None): | |
362 | + flash("Suppression du Capacity pas encore implémentée", 'warning') | |
363 | + # this_label = Label.query.get(int(label_id)) | |
364 | + # flash(f"Label {this_label.name} effacé") | |
365 | + return redirect(url_for('main.capacities')) | |
366 | + | |
367 | + | |
336 | 368 | @bp.route('/labels') |
337 | 369 | @login_required |
338 | 370 | def labels(): | ... | ... |
app/main/templates/capacities.html
... | ... | @@ -8,12 +8,19 @@ |
8 | 8 | <thead> |
9 | 9 | <tr> |
10 | 10 | <th scope="col">Fonction</th> |
11 | + <th scope="col" class="col-1">Actions</th> | |
11 | 12 | </tr> |
12 | 13 | </thead> |
13 | 14 | <tbody> |
14 | 15 | {% for capacity in capacities %} |
15 | 16 | <tr> |
16 | - <td>{{ capacity.name }}</td> | |
17 | + <td><a href="{{ url_for('main.capacity', capacity_id=capacity.id) }}"> | |
18 | + {{ capacity.name }}</a> | |
19 | + </td> | |
20 | + <td> | |
21 | + {{ commons.edit_link(url_for('main.capacity_edit', capacity_id=capacity.id)) }} | |
22 | + {{ commons.delete_link( url_for('main.capacity_delete', capacity_id=capacity.id)) }} | |
23 | + </td> | |
17 | 24 | </tr> |
18 | 25 | {% endfor %} |
19 | 26 | </tbody> | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +{% extends "base_page.html" %} | |
2 | +{% block content %} | |
3 | + | |
4 | + <!-- Invisible span to definte wich ul and a in the navbar are actived --> | |
5 | + <span id="nav_actived" style="display: none">agent,capacities</span> | |
6 | + | |
7 | + <div class="card"> | |
8 | + <div class="card-header"> | |
9 | + Fiche Fonction | |
10 | + </div> | |
11 | + <div class="card-body"> | |
12 | + <dl class="row agent"> | |
13 | + <dt class="col-sm-2 text-right">ID :</dt> | |
14 | + <dd class="col-sm-10 text-left">{{ capacity.id }}</dd> | |
15 | + <dt class="col-sm-2 text-right">Nom :</dt> | |
16 | + <dd class="col-sm-10 text-left">{{ capacity.name }}</dd> | |
17 | + <dt class="col-sm-2 text-right"></dt> | |
18 | + </dl> | |
19 | + {{ commons.edit_link(url_for('main.capacity_edit', capacity_id=capacity.id), 25) }} | |
20 | + {{ commons.delete_link( url_for('main.capacity_delete', capacity_id=capacity.id), 25) }} | |
21 | + </div> | |
22 | + </div> | |
23 | + | |
24 | +{% endblock %} | ... | ... |
... | ... | @@ -0,0 +1,29 @@ |
1 | +{% extends "base_page.html" %} | |
2 | + | |
3 | +{# Make link with form_manager #} | |
4 | +{% set capacity = object_struct %} | |
5 | + | |
6 | +{# Set the title that will be used in base_page #} | |
7 | +{% if capacity['id'] and capacity['id'] != '' %} | |
8 | + {% set subtitle = "Modifier la fonction "+ capacity['name'] %} | |
9 | +{% else %} | |
10 | + {% set subtitle = "Ajouter une nouvelle fonction" %} | |
11 | +{% endif %} | |
12 | + | |
13 | +{% block content %} | |
14 | + | |
15 | + <!-- Invisible span to define wich ul and a in the navbar are actived --> | |
16 | + <span id="nav_actived" style="display: none">admin,capacity_edit</span> | |
17 | + | |
18 | + <form id="capacity_form" class="pdc-form" action="{{ url_for('main.capacity_edit', | |
19 | + capacity_id=capacity['id']) }}" method="post"> | |
20 | + {% if capacity['id'] and capacity['id'] != '' %} | |
21 | + <input class="form-control" id="capacity_id" name="capacity_id" type="hidden" value="{{ capacity['id'] }}"> | |
22 | + {% endif %} | |
23 | + <div class="form-group"> | |
24 | + <label for="name">Nom</label> | |
25 | + <input class="form-control" id="name" name="name" type="text" value="{{ capacity['name'] }}"> | |
26 | + </div> | |
27 | + <input class="pdc-form-submit" type="submit" value="Valider"> | |
28 | + </form> | |
29 | +{% endblock %} | ... | ... |
app/models.py
... | ... | @@ -292,7 +292,7 @@ class Agent(db.Model, Formable): |
292 | 292 | bap = relationship("AgentBap", back_populates="agents") |
293 | 293 | status = relationship("AgentStatus", back_populates="agents") |
294 | 294 | company = relationship("Company", back_populates="agents") |
295 | - name = column_property(firstname+" "+secondname) | |
295 | + name = column_property(firstname + " " + secondname) | |
296 | 296 | |
297 | 297 | @property |
298 | 298 | def fullname(self): |
... | ... | @@ -322,10 +322,12 @@ class Service(db.Model): |
322 | 322 | abbr = db.Column(db.String(50), unique=True) |
323 | 323 | |
324 | 324 | |
325 | -class Capacity(db.Model): | |
325 | +class Capacity(db.Model, Formable): | |
326 | 326 | id = db.Column(db.Integer, primary_key=True) |
327 | 327 | name = db.Column(db.String(100), unique=True) |
328 | 328 | |
329 | + export_keys = ['name'] | |
330 | + | |
329 | 331 | |
330 | 332 | class Period(db.Model): |
331 | 333 | id = db.Column(db.Integer, primary_key=True) | ... | ... |
app/templates/base_page.html
... | ... | @@ -50,8 +50,6 @@ |
50 | 50 | href="{{ url_for('main.agents') }}">Liste des |
51 | 51 | agents</a> |
52 | 52 | </li> |
53 | - <li class="nav-item"><a id="agents_stats" class="sub_link nav-link" | |
54 | - href="{{ url_for('main.agents_stats') }}">Statistiques</a></li> | |
55 | 53 | <li class="nav-item"><a id="responsabilities" class="sub_link nav-link" |
56 | 54 | href="{{ url_for('main.responsabilities') }}">Liste des responsabilités</a></li> |
57 | 55 | <li class="nav-item"><a id="capacities" class="sub_link nav-link " |
... | ... | @@ -63,6 +61,8 @@ |
63 | 61 | <li class="nav-item"><a class="sub_link nav-link disabled" href="#">Liste des pôles</a></li> |
64 | 62 | <li class="nav-item"><a id="employments" class="sub_link nav-link" |
65 | 63 | href="{{ url_for('main.employments') }}">Liste des emplois types</a></li> |
64 | + <li class="nav-item"><a id="agents_stats" class="sub_link nav-link" | |
65 | + href="{{ url_for('main.agents_stats') }}">Statistiques</a></li> | |
66 | 66 | </ul> |
67 | 67 | </li> |
68 | 68 | <li class="nav-item"> |
... | ... | @@ -134,10 +134,12 @@ |
134 | 134 | href="{{ url_for('main.label_edit') }}">Ajouter un label</a></li> |
135 | 135 | <li class="nav-item"><a class="sub_link nav-link disabled" href="#">Ajouter une compétence</a> |
136 | 136 | </li> |
137 | - <li class="nav-item"><a class="sub_link nav-link disabled" href="#">Ajouter une fonction</a> | |
137 | + <li class="nav-item"><a id="capacity_edit" class="sub_link nav-link" | |
138 | + href="{{ url_for('main.capacity_edit') }}">Ajouter une fonction</a> | |
138 | 139 | </li> |
139 | 140 | <li class="nav-item"><a id="responsability_edit" class="sub_link nav-link" |
140 | - href="{{ url_for('main.responsability_edit') }}">Ajouter une responsabilité</a></li> | |
141 | + href="{{ url_for('main.responsability_edit') }}">Ajouter une responsabilité</a> | |
142 | + </li> | |
141 | 143 | <li class="nav-item"><a class="sub_link nav-link disabled" href="#">Affecter un responsable de |
142 | 144 | projet</a></li> |
143 | 145 | <li class="nav-item"><a class="sub_link nav-link disabled" href="#">Affecter un responsable de | ... | ... |
tests/frontend_tests.py
... | ... | @@ -9,7 +9,7 @@ from selenium.webdriver.common.keys import Keys |
9 | 9 | from selenium.webdriver.support.select import Select |
10 | 10 | |
11 | 11 | from app import create_app |
12 | -from app.models import Agent, Charge, Project, AgentResponsability, ProjectStatus, Label, Category | |
12 | +from app.models import Agent, Charge, Project, AgentResponsability, ProjectStatus, Label, Category, Capacity | |
13 | 13 | from pdc_config import TestConfig |
14 | 14 | from tests.common_db_feed import resources_to_instancedb |
15 | 15 | |
... | ... | @@ -163,13 +163,12 @@ class AccessTestCase(BaseFrontTestCase): |
163 | 163 | def test_responsability_page(self): |
164 | 164 | self.check_page_h2('projet', url_for('main.responsability', responsability_id=1)) |
165 | 165 | |
166 | - @unittest.skip("to be implemented") | |
167 | - def test_capacity_page(self): | |
168 | - pass | |
169 | - | |
170 | 166 | def test_capacities(self): |
171 | 167 | self.check_num_trs(59, url_for('main.capacities')) |
172 | 168 | |
169 | + def test_capacity_page(self): | |
170 | + self.check_page_h2('Acousticien', url_for('main.capacity', capacity_id=1)) | |
171 | + | |
173 | 172 | def test_project_status_page(self): |
174 | 173 | self.check_page_h2('Abandonné', url_for('main.project_status', status_id=1)) |
175 | 174 | |
... | ... | @@ -240,6 +239,21 @@ class FormsTestCase(BaseFrontTestCase): |
240 | 239 | def test_responsability_delete(self): |
241 | 240 | self.check_delete(url_for('main.responsability_delete', responsability_id=1)) |
242 | 241 | |
242 | + def test_capacity_add(self): | |
243 | + resp_dict = {'name': 'Ma Fonction'} | |
244 | + resp_add_url = url_for('main.capacity_edit') | |
245 | + self.check_edit(Capacity, resp_add_url, resp_dict) | |
246 | + | |
247 | + # Test capacity form | |
248 | + def test_capacity_edit(self): | |
249 | + init_dict = {'name': 'Acousticien'} | |
250 | + resp_dict = {'name': 'Ma Fonction'} | |
251 | + resp_add_url = url_for('main.capacity_edit', capacity_id=1) | |
252 | + self.check_edit(Capacity, resp_add_url, resp_dict, init_dict) | |
253 | + | |
254 | + def test_capacity_delete(self): | |
255 | + self.check_delete(url_for('main.capacity_delete', capacity_id=1)) | |
256 | + | |
243 | 257 | def test_agent_add(self): |
244 | 258 | agent_dict = {'firstname': 'Hitier', 'secondname': 'Richard'} |
245 | 259 | agent_add_url = url_for('main.agent_edit') | ... | ... |