Skip to content

Commit 995680c

Browse files
committed
feincms_validate: Check base and content types for common pitfalls
1 parent afc160a commit 995680c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/api/commands.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ management commands helped cleaning up the mess.
3131
.. automodule:: feincms.management.commands.rebuild_mptt_direct
3232
:members:
3333
:noindex:
34+
35+
36+
Miscellaneous commands
37+
----------------------
38+
39+
.. automodule:: feincms.management.commands.feincms_validate
40+
:members:
41+
:noindex:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ------------------------------------------------------------------------
2+
# coding=utf-8
3+
# $Id$
4+
# ------------------------------------------------------------------------
5+
"""
6+
``feincms_validate``
7+
--------------------
8+
9+
``feincms_validate`` checks your models for common pitfalls.
10+
"""
11+
12+
from django.core.management.base import NoArgsCommand
13+
from django.core.management.color import color_style
14+
from django.db.models import loading
15+
16+
17+
class Command(NoArgsCommand):
18+
help = "Check models for common pitfalls."
19+
20+
requires_model_validation = False
21+
22+
def handle_noargs(self, **options):
23+
self.style = color_style()
24+
25+
print "Running Django's own validation:"
26+
self.validate(display_num_errors=True)
27+
28+
for model in loading.get_models():
29+
if hasattr(model, '_create_content_base'):
30+
self.validate_base_model(model)
31+
32+
if hasattr(model, '_feincms_content_models'):
33+
self.validate_content_type(model)
34+
35+
def validate_base_model(self, model):
36+
"""
37+
Validate a subclass of ``feincms.models.Base`` or anything else created
38+
by ``feincms.models.create_base_model``
39+
"""
40+
41+
if not hasattr(model, 'template'):
42+
print self.style.NOTICE('%s has no template attribute; did you forget register_templates or register_regions?' % model)
43+
44+
def validate_content_type(self, model):
45+
"""
46+
Validate a dynamically created concrete content type
47+
"""
48+
49+
for base in model.__bases__:
50+
if not base._meta.abstract:
51+
print self.style.NOTICE('One of %s bases, %s, is not abstract' % (model, base))

0 commit comments

Comments
 (0)