From e20cd5d4d9f77a44ee0e7d9c942f6b97a8720a95 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Mon, 10 May 2021 17:02:49 +0200 Subject: [PATCH] Now import/export Class.id not 'class_id' --- app/main/routes.py | 5 ++++- app/main/templates/agent_form.html | 6 +++--- app/models.py | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/main/routes.py b/app/main/routes.py index 6d1e7df..1431089 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -143,7 +143,10 @@ def agent_edit(agent_id=None): # Or submit for db writing # elif request.method == 'POST': - agent_id = request.form['agent_id'] + try: + agent_id = request.form['agent_id'] + except KeyError: + agent_id = None if agent_id: # then update existing this_agent = Agent.query.get(int(agent_id)) diff --git a/app/main/templates/agent_form.html b/app/main/templates/agent_form.html index c4121b3..315b618 100644 --- a/app/main/templates/agent_form.html +++ b/app/main/templates/agent_form.html @@ -1,7 +1,7 @@ {% extends "base_page.html" %} {# Set the title that will be used in base_page #} -{% if agent['agent_id'] != '' %} +{% if agent and agent['id'] not in ['', None] %} {% set subtitle = "Modifier l'agent "+ agent['fullname'] %} {% else %} {% set subtitle = "Ajouter un nouvel agent" %} @@ -13,8 +13,8 @@
- {% if agent %} - + {% if agent and agent['id'] not in ['', None] %} + {% endif %}
diff --git a/app/models.py b/app/models.py index 70ce918..848888c 100644 --- a/app/models.py +++ b/app/models.py @@ -31,7 +31,7 @@ class Formable: :return: nothing """ - _struct = {} + _struct = {'id': self.id} for key in self.export_keys: _value = getattr(self, key) _struct[key] = '' if _value is None else _value @@ -135,7 +135,6 @@ class Agent(db.Model, Formable): """ _struct = super(Agent, self).to_struct() _struct['fullname'] = self.fullname - _struct['agent_id'] = self.id if self.id else '' return _struct -- libgit2 0.21.2