Skip to content

Commit

Permalink
fix case wrapping
Browse files Browse the repository at this point in the history
loading settings.CASE_WRAPPER at module import caused a circular import.
Lesson: always use failhard=True with to_function to avoid masking
errors when things get changed.
  • Loading branch information
Mike White committed Aug 5, 2013
1 parent 1609533 commit 39fe1bc
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions casexml/apps/case/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import re
from django.core.cache import cache
from django.conf import settings
from django.utils.translation import ugettext_noop, ugettext as _

from django.utils.translation import ugettext as _
from casexml.apps.phone.xml import get_case_element
from casexml.apps.case.signals import case_post_save
from casexml.apps.case.util import get_close_case_xml, get_close_referral_xml,\
Expand Down Expand Up @@ -37,10 +36,6 @@

INDEX_ID_PARENT = 'parent'

if getattr(settings, 'CASE_WRAPPER', None):
CASE_WRAPPER = to_function(getattr(settings, 'CASE_WRAPPER'))
else:
CASE_WRAPPER = None

class CaseBase(SafeSaveDocument):
"""
Expand Down Expand Up @@ -273,13 +268,6 @@ class CommCareCase(CaseBase, IndexHoldingMixIn, ComputedDocumentMixin, CaseQuery

server_modified_on = DateTimeProperty()

def __repr__(self):
return u"Case: {id} ({type}: {name})".format(
id=self._id,
type=self.type,
name=self.name,
).encode('utf-8')

def __unicode__(self):
return "CommCareCase: %s (%s)" % (self.case_id, self.get_id)

Expand All @@ -300,12 +288,12 @@ def __get_case_id(self):
def __set_case_id(self, id):
self._id = id

case_id = property(__get_case_id, __set_case_id)

def __repr__(self):
return "%s(name=%r, type=%r, id=%r)" % (
self.__class__.__name__, self.name, self.type, self._id)

case_id = property(__get_case_id, __set_case_id)

@property
@memoized
def parent(self):
Expand Down Expand Up @@ -397,6 +385,13 @@ def get_lite(cls, id):

@classmethod
def get_wrap_class(cls, data):
try:
settings.CASE_WRAPPER
except AttributeError:
cls._case_wrapper = None
else:
CASE_WRAPPER = to_function(settings.CASE_WRAPPER, failhard=True)

if CASE_WRAPPER:
return CASE_WRAPPER(data) or cls
return cls
Expand Down

0 comments on commit 39fe1bc

Please sign in to comment.