Skip to content

Commit 2716c59

Browse files
committed
Use _meta.model_name and fall back to _meta.module_name
1 parent a6e5859 commit 2716c59

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

feincms/_internal.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ def get_permission_codename(action, opts):
6363
of Django.
6464
"""
6565
return '%s_%s' % (action, opts.model_name)
66+
67+
68+
def get_model_name(opts):
69+
try:
70+
return opts.model_name
71+
except AttributeError:
72+
return opts.module_name

feincms/content/comments/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from django.utils.translation import ugettext_lazy as _
2424

2525
from feincms.admin.item_editor import ItemEditorForm
26+
from feincms._internal import get_model_name
2627

2728

2829
# ------------------------------------------------------------------------
@@ -59,7 +60,7 @@ def __init__(self, *args, **kwargs):
5960
_('public') if c.is_public
6061
else _('not public')),
6162
'app': comments_model._meta.app_label,
62-
'model': comments_model._meta.module_name,
63+
'model': get_model_name(comments_model._meta),
6364
}
6465
f.help_text = r
6566

feincms/management/checker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from django.core.management.color import color_style
44
from django.db import connection
55

6+
from feincms._internal import get_model_name
67

7-
def check_database_schema(cls, module_name):
8+
9+
def check_database_schema(cls, model_name):
810
"""
911
Returns a function which inspects the database table of the passed class.
1012
It checks whether all fields in the model are available on the database
@@ -23,7 +25,7 @@ def check_database_schema(cls, module_name):
2325
"""
2426

2527
def _fn(sender, **kwargs):
26-
if sender.__name__ != module_name:
28+
if sender.__name__ != model_name:
2729
return
2830

2931
cursor = connection.cursor()

feincms/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from django.utils.translation import ugettext_lazy as _
2626

2727
from feincms import ensure_completely_loaded
28+
from feincms._internal import get_model_name
2829
from feincms.extensions import ExtensionsMixin
2930
from feincms.utils import copy_model_instance
3031

@@ -521,7 +522,7 @@ def fe_identifier(self):
521522

522523
return '%s-%s-%s-%s-%s' % (
523524
cls._meta.app_label,
524-
cls._meta.module_name,
525+
get_model_name(cls._meta),
525526
self.__class__.__name__.lower(),
526527
self.parent_id,
527528
self.id,

feincms/module/mixins.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def app_label(self):
5555
"""
5656
return self._meta.app_label
5757

58+
@property
59+
def model_name(self):
60+
"See app_label"
61+
return self.__class__.__name__.lower()
62+
5863
@property
5964
def module_name(self):
6065
"See app_label"

feincms/module/page/forms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from django.utils.translation import ugettext_lazy as _
1616

1717
from feincms import ensure_completely_loaded
18+
from feincms._internal import get_model_name
1819

1920
from mptt.forms import MPTTAdminForm
2021

@@ -23,12 +24,12 @@ class RedirectToWidget(ForeignKeyRawIdWidget):
2324
def label_for_value(self, value):
2425
match = re.match(
2526
# XXX this regex would be available as .models.REDIRECT_TO_RE
26-
r'^(?P<app_label>\w+).(?P<module_name>\w+):(?P<pk>\d+)$',
27+
r'^(?P<app_label>\w+).(?P<model_name>\w+):(?P<pk>\d+)$',
2728
value)
2829

2930
if match:
3031
matches = match.groupdict()
31-
model = get_model(matches['app_label'], matches['module_name'])
32+
model = get_model(matches['app_label'], matches['model_name'])
3233
try:
3334
instance = model._default_manager.get(pk=int(matches['pk']))
3435
return '&nbsp;<strong>%s (%s)</strong>' % (
@@ -169,7 +170,7 @@ def clean(self):
169170
if redirect_to and re.match(r'^\d+$', redirect_to):
170171
opts = self.page_model._meta
171172
cleaned_data['redirect_to'] = '%s.%s:%s' % (
172-
opts.app_label, opts.module_name, redirect_to)
173+
opts.app_label, get_model_name(opts), redirect_to)
173174

174175
if not cleaned_data['active']:
175176
# If the current item is inactive, we do not need to conduct

feincms/module/page/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
REDIRECT_TO_RE = re.compile(
32-
r'^(?P<app_label>\w+).(?P<module_name>\w+):(?P<pk>\d+)$')
32+
r'^(?P<app_label>\w+).(?P<model_name>\w+):(?P<pk>\d+)$')
3333

3434

3535
# ------------------------------------------------------------------------
@@ -381,7 +381,7 @@ def get_redirect_to_target(self, request):
381381
return self.redirect_to
382382

383383
matches = match.groupdict()
384-
model = get_model(matches['app_label'], matches['module_name'])
384+
model = get_model(matches['app_label'], matches['model_name'])
385385

386386
if not model:
387387
return self.redirect_to

0 commit comments

Comments
 (0)