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