summaryrefslogtreecommitdiff
path: root/ishtar_common/wizards.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-20 12:03:22 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-20 12:03:22 +0100
commit13af48e053bfd0c90c3d558417768c7449bad5de (patch)
tree08f867c0fa37ec5640c0ce275b38b3f5e5ff7514 /ishtar_common/wizards.py
parent3c9de5b6c5b257a8cf0ed4118892fb1135e81957 (diff)
downloadIshtar-13af48e053bfd0c90c3d558417768c7449bad5de.tar.bz2
Ishtar-13af48e053bfd0c90c3d558417768c7449bad5de.zip
Warehouse: fix warehouse creation with no divisions (refs #3481)
Diffstat (limited to 'ishtar_common/wizards.py')
-rw-r--r--ishtar_common/wizards.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index c2cd54d03..5c4e1d3f9 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -31,6 +31,7 @@ from django.core.files.storage import default_storage
from django.core.mail import send_mail
from django.db.models.fields.files import FileField
from django.db.models.fields.related import ManyToManyField
+from django.db.models.fields import NOT_PROVIDED
from django.http import HttpResponseRedirect
from django.forms import ValidationError
@@ -665,11 +666,34 @@ class Wizard(NamedUrlWizardView):
else:
if issubclass(model, models.BaseHistorizedItem):
value['history_modifier'] = self.request.user
+
+ get_or_create = False
if hasattr(model, 'RELATIVE_MODELS') and \
self.get_saved_model() in \
model.RELATIVE_MODELS:
value[model.RELATIVE_MODELS[
self.get_saved_model()]] = obj
+ get_or_create = True
+
+ # check if there is no missing fields
+ # should be managed normally in forms but...
+ if hasattr(model._meta, 'get_fields'): # django 1.8
+ fields = model._meta.get_field()
+ else:
+ fields = model._meta.fields
+
+ has_problemetic_null = [
+ (field.name, field.default == NOT_PROVIDED)
+ for field in fields
+ if (field.name not in value
+ or not value[field.name])
+ and not field.null and not field.blank
+ and (not field.default
+ or field.default == NOT_PROVIDED)]
+ if has_problemetic_null:
+ continue
+
+ if get_or_create:
value, created = model.objects.get_or_create(
**value)
else: