Commit e20cd5d4d9f77a44ee0e7d9c942f6b97a8720a95

Authored by hitier
1 parent 142e2e9d

Now import/export Class.id not 'class_id'

app/main/routes.py
... ... @@ -143,7 +143,10 @@ def agent_edit(agent_id=None):
143 143 # Or submit for db writing
144 144 #
145 145 elif request.method == 'POST':
146   - agent_id = request.form['agent_id']
  146 + try:
  147 + agent_id = request.form['agent_id']
  148 + except KeyError:
  149 + agent_id = None
147 150 if agent_id:
148 151 # then update existing
149 152 this_agent = Agent.query.get(int(agent_id))
... ...
app/main/templates/agent_form.html
1 1 {% extends "base_page.html" %}
2 2  
3 3 {# Set the title that will be used in base_page #}
4   -{% if agent['agent_id'] != '' %}
  4 +{% if agent and agent['id'] not in ['', None] %}
5 5 {% set subtitle = "Modifier l'agent "+ agent['fullname'] %}
6 6 {% else %}
7 7 {% set subtitle = "Ajouter un nouvel agent" %}
... ... @@ -13,8 +13,8 @@
13 13 <span id="nav_actived" style="display: none">cds,agent/create</span>
14 14  
15 15 <form id="agent_form" class="pdc-form" action="{{ url_for('main.agent_edit') }}" method="post">
16   - {% if agent %}
17   - <input class="form-control" id="agent_id" name="agent_id" type="hidden" value="{{ agent['agent_id'] }}">
  16 + {% if agent and agent['id'] not in ['', None] %}
  17 + <input class="form-control" id="agent_id" name="agent_id" type="hidden" value="{{ agent['id'] }}">
18 18 {% endif %}
19 19 <div class="form-group">
20 20 <label for="firstname">Nom</label>
... ...
app/models.py
... ... @@ -31,7 +31,7 @@ class Formable:
31 31  
32 32 :return: nothing
33 33 """
34   - _struct = {}
  34 + _struct = {'id': self.id}
35 35 for key in self.export_keys:
36 36 _value = getattr(self, key)
37 37 _struct[key] = '' if _value is None else _value
... ... @@ -135,7 +135,6 @@ class Agent(db.Model, Formable):
135 135 """
136 136 _struct = super(Agent, self).to_struct()
137 137 _struct['fullname'] = self.fullname
138   - _struct['agent_id'] = self.id if self.id else ''
139 138 return _struct
140 139  
141 140  
... ...