Refactor the accesors to behave like methods instead of properties. This means all accesors will be prepended with the string "get_" and will include a set of parenthesis. Improve the ModeAttribute class to use the method's short_description. This commit also adds support for a new method .help_text attribute has been added. Move accessors to their own module, named "methods.py". Remove the PropertyHelper class as the accessors no longer need it. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
28 lines
839 B
Python
28 lines
839 B
Python
from __future__ import unicode_literals
|
|
|
|
from django.apps import apps
|
|
from django.contrib.auth import get_user_model
|
|
from django.contrib.contenttypes.fields import GenericRelation
|
|
from django.db import models
|
|
|
|
|
|
class ErrorLogEntryManager(models.Manager):
|
|
def register(self, model):
|
|
ErrorLogEntry = apps.get_model(
|
|
app_label='common', model_name='ErrorLogEntry'
|
|
)
|
|
model.add_to_class(
|
|
name='error_logs', value=GenericRelation(to=ErrorLogEntry)
|
|
)
|
|
|
|
|
|
class UserLocaleProfileManager(models.Manager):
|
|
def get_by_natural_key(self, user_natural_key):
|
|
User = get_user_model()
|
|
try:
|
|
user = User.objects.get_by_natural_key(user_natural_key)
|
|
except User.DoesNotExist:
|
|
raise self.model.DoesNotExist
|
|
|
|
return self.get(user__pk=user.pk)
|