Skip to content

Commit

Permalink
Cache classes and fix modal size.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkuty committed Mar 23, 2016
1 parent 1d63044 commit 787d9da
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
48 changes: 30 additions & 18 deletions horizon_contrib/common/content_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,35 @@ def _is_contenttypes_enabled():
return False


def get_class(name):
"""this method return model class from CT or our registry
all generic features depends on this method
"""
cls = None
# if CT enabled search in
if _is_contenttypes_enabled():
try:
cls = get_class_from_ct(name)
except exceptions.ImproperlyConfigured:
LOG.warning("""
class Registry(object):

_classes = {}

def get_class(self, name):
"""this method return model class from CT or our registry
all generic features depends on this method
"""

if name not in self._classes:

# if CT enabled search in
if _is_contenttypes_enabled():
try:
self._classes[name] = get_class_from_ct(name)
except exceptions.ImproperlyConfigured:
LOG.warning("""
If you want fix this log message set ``WITHOUT_CT`` in you settings.py\
you have enabled CT fw but DATABASES = {} is ImproperlyConfigured
""")
# try to find in our registry
cls = get_model(name)
else:
# in our registry
cls = get_model(name)
return cls
""")
# try to find in our registry
self._classes[name] = get_model(name)
else:
# in our registry
self._classes[name] = get_model(name)

return self._classes[name]

registry = Registry()

# just a proxy
get_class = registry.get_class
10 changes: 6 additions & 4 deletions horizon_contrib/forms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ def get_context_data(self, **kwargs):

def _get_moda_size(self):
'''try get form_size attribute form form or widget'''
form_class = self.get_form_class()
return getattr(form_class,
'form_size',
getattr(self.model, 'form_size', 'md'))
if hasattr(self, 'model'):
form_class = self.get_form_class()
return getattr(form_class,
'form_size',
getattr(self.model, 'form_size', 'md'))
return 'md'


class ModelModalView(ModalFormView):
Expand Down

0 comments on commit 787d9da

Please sign in to comment.