Code style cleanups
Add keyword arguments. Sort arguments and models. Move literals to their own module. Prepend handler_ to signal handlers. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -35,6 +35,13 @@ class Collection(object):
|
||||
def __str__(self):
|
||||
return force_text(self.label)
|
||||
|
||||
def _get_children(self):
|
||||
if self._queryset:
|
||||
return self._queryset
|
||||
else:
|
||||
if self._model:
|
||||
return self._model.objects.all()
|
||||
|
||||
def resolve(self):
|
||||
self.children = self._get_children()
|
||||
self.icon = self._icon
|
||||
@@ -45,13 +52,6 @@ class Collection(object):
|
||||
self.url = reverse(viewname=self._link.view, args=self._link.args)
|
||||
return ''
|
||||
|
||||
def _get_children(self):
|
||||
if self._queryset:
|
||||
return self._queryset
|
||||
else:
|
||||
if self._model:
|
||||
return self._model.objects.all()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class ErrorLogNamespace(object):
|
||||
@@ -62,9 +62,6 @@ class ErrorLogNamespace(object):
|
||||
def __str__(self):
|
||||
return force_text(self.label)
|
||||
|
||||
def create(self, obj, result):
|
||||
obj.error_logs.create(namespace=self.name, result=result)
|
||||
|
||||
def all(self):
|
||||
ErrorLogEntry = apps.get_model(
|
||||
app_label='common', model_name='ErrorLogEntry'
|
||||
@@ -72,6 +69,9 @@ class ErrorLogNamespace(object):
|
||||
|
||||
return ErrorLogEntry.objects.filter(namespace=self.name)
|
||||
|
||||
def create(self, obj, result):
|
||||
obj.error_logs.create(namespace=self.name, result=result)
|
||||
|
||||
|
||||
class MissingItem(object):
|
||||
_registry = []
|
||||
@@ -92,6 +92,12 @@ class MissingItem(object):
|
||||
class ModelAttribute(object):
|
||||
_registry = {}
|
||||
|
||||
@classmethod
|
||||
def get_choices_for(cls, model):
|
||||
return [
|
||||
(attribute.name, attribute) for attribute in cls.get_for(model=model)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_for(cls, model):
|
||||
try:
|
||||
@@ -106,12 +112,6 @@ class ModelAttribute(object):
|
||||
|
||||
return cls.get_for(model=type(model))
|
||||
|
||||
@classmethod
|
||||
def get_choices_for(cls, model):
|
||||
return [
|
||||
(attribute.name, attribute) for attribute in cls.get_for(model)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_help_text_for(cls, model, show_name=False):
|
||||
result = []
|
||||
@@ -208,15 +208,6 @@ class ModelField(ModelAttribute):
|
||||
class ModelProperty(object):
|
||||
_registry = []
|
||||
|
||||
@classmethod
|
||||
def get_for(cls, model):
|
||||
result = []
|
||||
|
||||
for klass in cls._registry:
|
||||
result.extend(klass.get_for(model=model))
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_choices_for(cls, model):
|
||||
result = []
|
||||
@@ -226,6 +217,15 @@ class ModelProperty(object):
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_for(cls, model):
|
||||
result = []
|
||||
|
||||
for klass in cls._registry:
|
||||
result.extend(klass.get_for(model=model))
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_help_text_for(cls, model, show_name=False):
|
||||
result = []
|
||||
@@ -324,5 +324,5 @@ class Template(object):
|
||||
return self
|
||||
|
||||
|
||||
ModelProperty.register(ModelAttribute)
|
||||
ModelProperty.register(ModelField)
|
||||
ModelProperty.register(klass=ModelAttribute)
|
||||
ModelProperty.register(klass=ModelField)
|
||||
|
||||
Reference in New Issue
Block a user