summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-10-28 19:21:41 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-10-28 19:21:41 +0200
commit6f80a494ceac19d5db0650a591bf112b09ea2eba (patch)
treebd817bec361eff377bdd7b03b3ac2b37631f8c9d /ishtar_common
parent6435791849e9f386dc150d63c06025148698bb2d (diff)
downloadIshtar-6f80a494ceac19d5db0650a591bf112b09ea2eba.tar.bz2
Ishtar-6f80a494ceac19d5db0650a591bf112b09ea2eba.zip
Too many lazy evaluations and nobody do the job! Fixed.
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py23
-rw-r--r--ishtar_common/models.py13
-rw-r--r--ishtar_common/widgets.py1
3 files changed, 25 insertions, 12 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index b0e8cb43c..043b03f61 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -31,6 +31,10 @@ from django.utils import formats
from django.utils.functional import lazy
from django.utils.translation import ugettext_lazy as _
+import models
+import widgets
+
+
# from formwizard.forms import NamedUrlSessionFormWizard
@@ -44,10 +48,23 @@ class NamedUrlSessionFormWizard(forms.Form):
def rindex(self, idx):
return self.url_name.rindex(idx)
-import models
-import widgets
-reverse_lazy = lazy(reverse, unicode)
+def my_reverse(*args, **kwargs):
+ """
+ Custom reverse method in order to evaluate lazy args
+ """
+ if 'args' in kwargs:
+ my_args = []
+ for arg in kwargs['args']:
+ if callable(arg):
+ my_args.append(unicode(arg()))
+ else:
+ my_args.append(unicode(arg))
+ kwargs['args'] = my_args
+ return reverse(*args, **kwargs)
+
+
+reverse_lazy = lazy(my_reverse, unicode)
regexp_name = re.compile(r"^[,:/\w\-'\"() \&\[\]@]+$", re.UNICODE)
name_validator = validators.RegexValidator(
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 814387bb4..c0888ec06 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -67,7 +67,6 @@ from ishtar_common.data_importer import Importer, ImportFormater, \
def post_save_user(sender, **kwargs):
user = kwargs['instance']
- ishtaruser = None
try:
q = IshtarUser.objects.filter(username=user.username)
if not q.count():
@@ -360,9 +359,9 @@ class GeneralType(Cached, models.Model):
:param slug: textual id
- :return: the id of the item
+ :return: id of the item (string)
"""
- return cls.get_or_create(slug).pk
+ return unicode(cls.get_or_create(slug).pk)
@classmethod
def get_or_create_pks(cls, slugs):
@@ -377,7 +376,7 @@ class GeneralType(Cached, models.Model):
items = []
for slug in slugs:
items.append(str(cls.get_or_create(slug).pk))
- return "_".join(items)
+ return u"_".join(items)
@classmethod
def get_help(cls, dct={}, exclude=[]):
@@ -1580,8 +1579,7 @@ class OrganizationType(GeneralType):
post_save.connect(post_save_cache, sender=OrganizationType)
post_delete.connect(post_save_cache, sender=OrganizationType)
-organization_type_lazy = lazy(OrganizationType.get_or_create, OrganizationType)
-organization_type_pk_lazy = lazy(OrganizationType.get_or_create_pk, int)
+organization_type_pk_lazy = lazy(OrganizationType.get_or_create_pk, unicode)
organization_type_pks_lazy = lazy(OrganizationType.get_or_create_pks, unicode)
IMPORTER_CLASSES = {}
@@ -2374,8 +2372,7 @@ class PersonType(GeneralType):
post_save.connect(post_save_cache, sender=PersonType)
post_delete.connect(post_save_cache, sender=PersonType)
-person_type_lazy = lazy(PersonType.get_or_create_pk, PersonType)
-person_type_pk_lazy = lazy(PersonType.get_or_create_pk, int)
+person_type_pk_lazy = lazy(PersonType.get_or_create_pk, unicode)
person_type_pks_lazy = lazy(PersonType.get_or_create_pks, unicode)
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index d3a2c975e..1183836bc 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -431,7 +431,6 @@ class JQueryPersonOrganization(forms.TextInput):
@classmethod
def encode_source(cls, source):
- encoded_src = ''
if isinstance(source, list):
encoded_src = JSONEncoder().encode(source)
elif isinstance(source, str) \