From 481c75133987a510db34b0950b6861962aa2aaab Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 20 Nov 2018 15:39:37 +0100 Subject: [PATCH] fix field order in mail managers --- src/contact/models.py | 11 +++++++++++ src/contact/templates/contact/mail_managers_body.txt | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/contact/models.py b/src/contact/models.py index adffafa38..0ab8201f4 100644 --- a/src/contact/models.py +++ b/src/contact/models.py @@ -36,6 +36,17 @@ class Contact(models.Model): data = '%s%s%s%s%s' % (self.id, self.contact, serialized_body, self.ip, self.form_tag) return sha1(data).hexdigest() + def keys(self): + try: + from .views import contact_forms + orig_fields = contact_forms[self.form_tag]().fields + except KeyError: + orig_fields = {} + return list(orig_fields.keys()) + + def items(self): + return [(key, self.body[key]) for key in self.keys() if key in self.body] + class Attachment(models.Model): contact = models.ForeignKey(Contact) diff --git a/src/contact/templates/contact/mail_managers_body.txt b/src/contact/templates/contact/mail_managers_body.txt index b65ebd853..3a4297c95 100644 --- a/src/contact/templates/contact/mail_managers_body.txt +++ b/src/contact/templates/contact/mail_managers_body.txt @@ -2,7 +2,7 @@ https://{{site_domain}}{% url 'admin:contact_contact_change' contact.pk %} -{% for k, v in contact.body.items %} +{% for k, v in contact.items %} {{ k }}: {{ v|pretty_print }} {% endfor %} -- 2.20.1