Permalink
Browse files

Can control template inheritance, default=False

Added basic actions for active=True, active=False
  • Loading branch information...
1 parent e7a6e6e commit b9dd5c9be20ba14a61f3853b5ace01c0d4508ab3 Charles Mastin committed Mar 30, 2012
View
19 simple_cms/admin.py
@@ -4,6 +4,16 @@
from simple_cms.models import *
+def action_set_active(modeladmin, request, queryset):
+ queryset.update(active=True)
+
+action_set_active.short_description = 'Make published'
+
+def action_set_inactive(modeladmin, request, queryset):
+ queryset.update(active=False)
+
+action_set_inactive.short_description = 'Make un-published'
+
class NavigationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(NavigationForm, self).__init__(*args, **kwargs)
@@ -35,6 +45,7 @@ class NavigationAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}
inlines = [RelatedBlockInline, SeoInline]
search_fields = ['title', 'text']
+ actions = [action_set_active, action_set_inactive]
fieldsets = (
(None, {
'fields': (
@@ -50,11 +61,11 @@ class NavigationAdmin(admin.ModelAdmin):
'classes': ('collapse',),
'fields': (
'page_title',
+ 'render_as_template',
'homepage',
'inherit_blocks',
- 'render_as_template',
('url', 'target'),
- ('view', 'template'),
+ ('view', 'template', 'inherit_template'),
('redirect_url', 'redirect_permanent'),
),
}),
@@ -64,6 +75,7 @@ class NavigationAdmin(admin.ModelAdmin):
class BlockAdmin(admin.ModelAdmin):
list_display = ('key', 'title', 'url', 'image', 'format')
#list_filter = ('format', )
+ actions = [action_set_active, action_set_inactive]
fieldsets = (
(None, {
'fields': (
@@ -92,7 +104,7 @@ class CategoryAdmin(admin.ModelAdmin):
list_display = ['title', 'parent', 'order', 'active']
list_filter = ['active']
prepopulated_fields = {'slug': ('title',)}
-
+ actions = [action_set_active, action_set_inactive]
class CategoryInline(admin.TabularInline):
@@ -118,6 +130,7 @@ class ArticleAdmin(admin.ModelAdmin):
search_fields = ['title', 'text', 'excerpt']
exclude = ['categories']
inlines = [CategoryInline, SeoInline]
+ actions = [action_set_active, action_set_inactive]
fieldsets = (
(None, {
'fields': (
View
9 simple_cms/contrib/actions.py
@@ -0,0 +1,9 @@
+def action_set_active(modeladmin, request, queryset):
+ queryset.update(active=True)
+
+action_set_active.short_description = 'Make published'
+
+def action_set_inactive(modeladmin, request, queryset):
+ queryset.update(active=False)
+
+action_set_inactive.short_description = 'Make un-published'
View
187 simple_cms/migrations/0013_inherit_template.py
@@ -0,0 +1,187 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Navigation.inherit_template'
+ db.add_column('simple_cms_navigation', 'inherit_template', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Navigation.inherit_template'
+ db.delete_column('simple_cms_navigation', 'inherit_template')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 3, 30, 9, 27, 9, 188665)'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 3, 30, 9, 27, 9, 188530)'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'simple_cms.article': {
+ 'Meta': {'ordering': "['-post_date']", 'object_name': 'Article'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'allow_comments': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'categories': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'articles'", 'blank': 'True', 'to': "orm['simple_cms.Category']"}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'display_image': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'display_title': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'excerpt': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+ 'format': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'key_image': ('django.db.models.fields.files.ImageField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
+ 'post_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'render_as_template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'slug': ('django_extensions.db.fields.AutoSlugField', [], {'allow_duplicates': 'False', 'max_length': '50', 'separator': "u'-'", 'blank': 'True', 'populate_from': "'title'", 'overwrite': 'False', 'db_index': 'True'}),
+ 'target': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'text': ('django.db.models.fields.TextField', [], {}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
+ },
+ 'simple_cms.block': {
+ 'Meta': {'ordering': "('-updated_at', '-created_at')", 'object_name': 'Block'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'bypass_layout': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'format': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.files.ImageField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
+ 'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+ 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'render_as_template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'target': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'text': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
+ },
+ 'simple_cms.blockgroup': {
+ 'Meta': {'ordering': "('title',)", 'object_name': 'BlockGroup'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 'simple_cms.category': {
+ 'Meta': {'ordering': "['title']", 'object_name': 'Category'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['simple_cms.Category']", 'null': 'True', 'blank': 'True'}),
+ 'slug': ('django_extensions.db.fields.AutoSlugField', [], {'allow_duplicates': 'False', 'max_length': '50', 'separator': "u'-'", 'blank': 'True', 'populate_from': "'title'", 'overwrite': 'False', 'db_index': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'})
+ },
+ 'simple_cms.navigation': {
+ 'Meta': {'ordering': "['title']", 'unique_together': "(('site', 'slug', 'parent'),)", 'object_name': 'Navigation'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'format': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['simple_cms.NavigationGroup']", 'null': 'True', 'blank': 'True'}),
+ 'homepage': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'inherit_blocks': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'inherit_template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
+ 'page_title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['simple_cms.Navigation']"}),
+ 'redirect_permanent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'redirect_url': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'render_as_template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pages'", 'to': "orm['sites.Site']"}),
+ 'slug': ('django_extensions.db.fields.AutoSlugField', [], {'allow_duplicates': 'False', 'max_length': '50', 'separator': "u'-'", 'blank': 'True', 'populate_from': "'title'", 'overwrite': 'False', 'db_index': 'True'}),
+ 'target': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'template': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'text': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'url': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'view': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
+ },
+ 'simple_cms.navigationgroup': {
+ 'Meta': {'ordering': "('title',)", 'object_name': 'NavigationGroup'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 'simple_cms.relatedblock': {
+ 'Meta': {'ordering': "['order']", 'object_name': 'RelatedBlock'},
+ 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'block': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['simple_cms.Block']"}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['simple_cms.BlockGroup']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'order': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'})
+ },
+ 'simple_cms.seo': {
+ 'Meta': {'unique_together': "(['content_type', 'object_id'],)", 'object_name': 'Seo'},
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'description': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keywords': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+ 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'taggit.tag': {
+ 'Meta': {'object_name': 'Tag'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100', 'db_index': 'True'})
+ },
+ 'taggit.taggeditem': {
+ 'Meta': {'object_name': 'TaggedItem'},
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
+ 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"})
+ }
+ }
+
+ complete_apps = ['simple_cms']
View
1 simple_cms/models.py
@@ -170,6 +170,7 @@ class Navigation(TextMixin, CommonAbstractModel):
redirect_url = models.CharField(max_length=255, blank=True, default='')
redirect_permanent = models.BooleanField(default=False)
inherit_blocks = models.BooleanField(default=True, verbose_name="Inherit Blocks")
+ inherit_template = models.BooleanField(default=False, verbose_name="Inherit Template")
seo = generic.GenericRelation(Seo)
blocks = generic.GenericRelation(RelatedBlock)
View
9 simple_cms/views.py
@@ -34,9 +34,12 @@ def _handler(self, request, *args, **kwargs):
else:
cls = get_callable(context['page'].view)
return cls(request)
- for i in context['pageA']:
- if i.template:
- self.template = i.template
+ if context['page'].template:
+ self.template = context['page'].template
+ elif context['page'].inherit_template:
+ for i in context['pageA']:
+ if i.template:
+ self.template = i.template
return render(request, self.template, {}, context_instance=context)
raise Http404

0 comments on commit b9dd5c9

Please sign in to comment.