summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-06-30 16:50:58 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-06-30 16:50:58 +0200
commit72b0a0276e70194666ff9110522f49f4e3f1476e (patch)
tree6a41f63eabed5f6f3f7537585d5ae3f3a00e4d00 /ishtar_common
parent9fe30e305e1a114277e8473df415588bfacd188d (diff)
parent483fcd46fb60a597959bfde9d00bde4cc1822cd2 (diff)
downloadIshtar-72b0a0276e70194666ff9110522f49f4e3f1476e.tar.bz2
Ishtar-72b0a0276e70194666ff9110522f49f4e3f1476e.zip
Merge branch 'master' into v0.9
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/data_importer.py41
-rw-r--r--ishtar_common/forms_common.py1
-rw-r--r--ishtar_common/locale/django.pot14
-rw-r--r--ishtar_common/models.py2
-rw-r--r--ishtar_common/templates/blocks/form_snippet.html5
-rw-r--r--ishtar_common/tests.py19
6 files changed, 54 insertions, 28 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 10957e74d..e11e72449 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1400,20 +1400,35 @@ class Importer(object):
# get all related fields
new_created = {}
- for attribute in list(data.keys()):
- c_c_path = c_path[:]
- if not attribute:
- data.pop(attribute)
- continue
- if not data[attribute]:
- field_object, model, direct, m2m = \
- cls._meta.get_field_by_name(attribute)
- if m2m:
+ try:
+ for attribute in list(data.keys()):
+ c_c_path = c_path[:]
+ if not attribute:
data.pop(attribute)
- continue
- if attribute != '__force_new':
- self.get_field(cls, attribute, data, m2ms, c_c_path,
- new_created)
+ continue
+ if not data[attribute]:
+ field_object, model, direct, m2m = \
+ cls._meta.get_field_by_name(attribute)
+ if m2m:
+ data.pop(attribute)
+ continue
+ if attribute != '__force_new':
+ self.get_field(cls, attribute, data, m2ms, c_c_path,
+ new_created)
+ except (ValueError, IntegrityError) as e:
+ message = e.message
+ try:
+ message = e.message.decode('utf-8')
+ except (UnicodeDecodeError, UnicodeDecodeError):
+ message = ''
+ try:
+ data = unicode(data)
+ except UnicodeDecodeError:
+ data = ''
+ raise ImporterError(
+ "Erreur d'import %s %s, contexte : %s, erreur : %s"
+ % (unicode(cls), unicode("__".join(path)),
+ unicode(data), message))
create_dict = copy.deepcopy(data)
for k in create_dict.keys():
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index b317f77e3..61e9f1a88 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -884,6 +884,7 @@ class AuthorFormSelection(forms.Form):
base_model = 'author'
associated_models = {'author': models.Author}
author = forms.IntegerField(
+ required=False,
widget=widgets.JQueryAutoComplete(
"/" + settings.URL_PATH + 'autocomplete-author',
associated_model=models.Author, new=True),
diff --git a/ishtar_common/locale/django.pot b/ishtar_common/locale/django.pot
index 4d9e2d575..4a7e66801 100644
--- a/ishtar_common/locale/django.pot
+++ b/ishtar_common/locale/django.pot
@@ -120,31 +120,31 @@ msgstr ""
msgid "Importer configuration error: field \"{}\" does not exist for {}."
msgstr ""
-#: data_importer.py:1559
+#: data_importer.py:1574
msgid "line"
msgstr ""
-#: data_importer.py:1559
+#: data_importer.py:1574
msgid "col"
msgstr ""
-#: data_importer.py:1559
+#: data_importer.py:1574
msgid "error"
msgstr ""
-#: data_importer.py:1565
+#: data_importer.py:1580
msgid "field"
msgstr ""
-#: data_importer.py:1565
+#: data_importer.py:1580
msgid "source"
msgstr ""
-#: data_importer.py:1565
+#: data_importer.py:1580
msgid "result"
msgstr ""
-#: data_importer.py:1581
+#: data_importer.py:1596
#, python-format
msgid "\"%(value)s\" not in %(values)s"
msgstr ""
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 59d1f9ebc..639e44af3 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3003,7 +3003,7 @@ post_delete.connect(post_save_cache, sender=Format)
class Source(OwnPerms, ImageModel, models.Model):
title = models.CharField(_(u"Title"), max_length=300)
- external_id = models.CharField(_(u"External ID"), max_length=12, null=True,
+ external_id = models.TextField(_(u"External ID"), max_length=300, null=True,
blank=True)
source_type = models.ForeignKey(SourceType, verbose_name=_(u"Type"))
support_type = models.ForeignKey(SupportType, verbose_name=_(u"Support"),
diff --git a/ishtar_common/templates/blocks/form_snippet.html b/ishtar_common/templates/blocks/form_snippet.html
index 2f841e078..5ee88e25f 100644
--- a/ishtar_common/templates/blocks/form_snippet.html
+++ b/ishtar_common/templates/blocks/form_snippet.html
@@ -10,4 +10,7 @@
</tr>
<tr class="help_text" id="{{field.auto_id}}_help">
<td colspan="3"><div>{{field.help_text}}</div></td>
- {%endif%}</tr>{% else %}{{field}}{% endif %}{% endfor %}
+ {%endif%}</tr>{% else %}{{field}}{% if field.errors %}
+ <tr class='errors'>
+ <td colspan='3'>{{field.name}} - {{ field.errors }}</td>
+ </tr>{% endif %}{{field|safe}}{% endif %}{% endfor %}
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index a91a0ba58..174918dd4 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -222,9 +222,11 @@ class WizardTest(object):
self.wizard_name):
[current_step],
}
+
+ # reconstruct a POST request
if current_step in form_data:
d = form_data[current_step]
- if type(d) in (list, tuple): # formset
+ if type(d) in (list, tuple): # is a formset
for d_idx, item in enumerate(d):
for k in item:
data['{}-{}-{}'.format(
@@ -239,16 +241,21 @@ class WizardTest(object):
response = self.client.post(url, data,
follow=not next_form_is_checked)
except ValidationError as e:
- # on ManagementForm data is missing or has been tampered
- # error verify the wizard_name or step name
- raise ValidationError(u"Errors: {} on {}.".format(
- u" - ".join(e.messages), current_step))
+ msg = u"Errors: {} on {}. On \"ManagementForm data is " \
+ u"missing or...\" error verify the wizard_name or " \
+ u"step name".format(u" - ".join(e.messages),
+ current_step)
+ raise ValidationError(msg)
self.check_response(response, current_step)
if next_form_is_checked:
next_form = self.steps[idx + 1][0]
self.assertRedirects(
response,
- '/{}/{}'.format(self.url_name, next_form))
+ '/{}/{}'.format(self.url_name, next_form),
+ msg_prefix="Redirection to {} has failed - "
+ "Error on previous form ({})?".format(
+ next_form, current_step)
+ )
if idx == len(self.steps) - 1:
# last form
self.assertRedirects(