Permalink
Browse files

Added "is_public" field to Pages.

Added migration.
Updated PageManager.
Styling non public pages.
Added page-no-public icon.
Moved page icons from ckeditor to image folder.
  • Loading branch information...
1 parent 90c0d33 commit 85a46b2c996e0640c1978c059d96ba39cfd36b82 @bheesink bheesink committed Jan 10, 2012
View
@@ -45,7 +45,7 @@ class PageAdmin(MPTTModelAdmin):
form = forms.PageForm
fieldsets = (
(None, {'fields': ('parent', 'title', 'url', 'redirect_page', 'template_name')}),
- (_('Advanced options'), {'classes': ('collapse',), 'fields': ('mark_current_regexes', 'show_in_menu', 'protected', 'metadata',)}),
+ (_('Advanced options'), {'classes': ('collapse',), 'fields': ('mark_current_regexes', 'show_in_menu', 'is_public', 'protected', 'metadata',)}),
)
inlines = (PageContentItemInline,)
@@ -62,10 +62,9 @@ def page_info(request):
"""
Block access to pages that the current user isn't supposed to see.
"""
- if request.user.is_authenticated():
- if page:
- if page not in Page.objects.visible_pages_for_user(request.user):
- page = None
+ if page:
+ if page not in Page.objects.public_for_user(request.user):
+ page = None
"""
Find pages that should be marked as current in menus.
View
@@ -84,12 +84,19 @@ def rename_markup(markup):
class PageManager(models.Manager):
- def visible_pages_for_user(self, user):
- visible_pages_qs = self.get_query_set()
+ def public_for_user(self, user):
+ public_pages_qs = self.get_query_set()
if not user.is_staff:
- visible_pages_qs = visible_pages_qs.filter(show_in_menu=True)
+ public_pages_qs = public_pages_qs.filter(is_public=True)
- return visible_pages_qs
+ return public_pages_qs
+
+ def shown_in_menu_for_user(self, user):
+ shown_in_menu_pages_qs = self.get_query_set()
+ if not user.is_staff:
+ shown_in_menu_pages_qs = shown_in_menu_pages_qs.filter(show_in_menu=True, is_public=True)
+
+ return shown_in_menu_pages_qs
class PageContentItemManager(models.Manager):
@@ -0,0 +1,89 @@
+# 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 'Page.is_public'
+ db.add_column('fiber_page', 'is_public', self.gf('django.db.models.fields.BooleanField')(default=True), keep_default=False)
+
+ # Changing field 'Page.url'
+ db.alter_column('fiber_page', 'url', self.gf('fiber.utils.fields.FiberURLField')(max_length=255))
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Page.is_public'
+ db.delete_column('fiber_page', 'is_public')
+
+ # Changing field 'Page.url'
+ db.alter_column('fiber_page', 'url', self.gf('django.db.models.fields.CharField')(max_length=255))
+
+
+ models = {
+ 'fiber.contentitem': {
+ 'Meta': {'object_name': 'ContentItem'},
+ 'content_html': ('fiber.utils.fields.FiberHTMLField', [], {}),
+ 'content_markup': ('fiber.utils.fields.FiberMarkupField', [], {}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'metadata': ('fiber.utils.json.JSONField', [], {'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'protected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'template_name': ('django.db.models.fields.CharField', [], {'max_length': '70', 'blank': 'True'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+ },
+ 'fiber.file': {
+ 'Meta': {'ordering': "('file',)", 'object_name': 'File'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+ },
+ 'fiber.image': {
+ 'Meta': {'ordering': "('image',)", 'object_name': 'Image'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'height': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '255'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'width': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+ },
+ 'fiber.page': {
+ 'Meta': {'ordering': "('tree_id', 'lft')", 'object_name': 'Page'},
+ 'content_items': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['fiber.ContentItem']", 'through': "orm['fiber.PageContentItem']", 'symmetrical': 'False'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'mark_current_regexes': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'metadata': ('fiber.utils.json.JSONField', [], {'null': 'True', 'blank': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'subpages'", 'null': 'True', 'to': "orm['fiber.Page']"}),
+ 'protected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'redirect_page': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'redirected_pages'", 'null': 'True', 'to': "orm['fiber.Page']"}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'show_in_menu': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'template_name': ('django.db.models.fields.CharField', [], {'max_length': '70', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'url': ('fiber.utils.fields.FiberURLField', [], {'max_length': '255', 'blank': 'True'})
+ },
+ 'fiber.pagecontentitem': {
+ 'Meta': {'object_name': 'PageContentItem'},
+ 'block_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'content_item': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'page_content_items'", 'to': "orm['fiber.ContentItem']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'page_content_items'", 'to': "orm['fiber.Page']"}),
+ 'sort': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['fiber']
View
@@ -74,6 +74,7 @@ class Page(MPTTModel):
# TODO: add `alias_page` field
template_name = models.CharField(_('template name'), blank=True, max_length=70)
show_in_menu = models.BooleanField(_('show in menu'), default=True)
+ is_public = models.BooleanField(_('is public'), default=True)
protected = models.BooleanField(_('protected'), default=False)
content_items = models.ManyToManyField(ContentItem, through='PageContentItem', verbose_name=_('content items'))
metadata = JSONField(blank=True, null=True, schema=METADATA_PAGE_SCHEMA, prefill_from='fiber.models.Page')
@@ -254,7 +254,7 @@ ins.jstree-icon {
#df-wpr-sidebar .jstree .ui-state-default .ui-icon,
.jstree .ui-state-default .ui-icon {
- background: url(../images/ckeditor/icon-page.png);
+ background: url(../images/icon-page.png);
background-position: 0 0;
}
@@ -263,26 +263,33 @@ ins.jstree-icon {
margin-top: 14px;
}
-li.hidden-in-menu {
+li.hidden-in-menu,
+li.not-public, {
opacity: 0.5;
filter: alpha(opacity=50);
}
-#df-wpr-sidebar .jstree li.hidden-in-menu {
+#df-wpr-sidebar .jstree li.hidden-in-menu,
+#df-wpr-sidebar .jstree li.not-public {
opacity: 1;
filter: alpha(opacity=100);
}
-#df-wpr-sidebar .jstree li.hidden-in-menu a {
+#df-wpr-sidebar .jstree li.hidden-in-menu a,
+#df-wpr-sidebar .jstree li.not-public a {
color: #999;
}
#df-wpr-sidebar .jstree li.hidden-in-menu > .ui-state-default .ui-icon {
- background: url(../images/ckeditor/icon-page-hidden.png);
+ background: url(../images/icon-page-hidden.png);
+}
+
+#df-wpr-sidebar .jstree li.not-public > .ui-state-default .ui-icon {
+ background: url(../images/icon-page-not-public.png);
}
#df-wpr-sidebar .jstree li.redirect > .ui-state-default .ui-icon {
- background: url(../images/ckeditor/icon-page-redirect.png);
+ background: url(../images/icon-page-redirect.png);
}
#df-wpr-busy {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -6,7 +6,7 @@
<ul>
{% endif %}
{% recursetree fiber_menu_pages %}
- <li class="{{ node.title|slugify }}{% if node in fiber_current_pages %} current{% endif %}{% if node.is_first_child %} first{% endif %}{% if node.is_last_child %} last{% endif %}{% if not node.show_in_menu %} hidden-in-menu{% endif %}{% if node.redirect_page %} redirect{% endif %}">
+ <li class="{{ node.title|slugify }}{% if node in fiber_current_pages %} current{% endif %}{% if node.is_first_child %} first{% endif %}{% if node.is_last_child %} last{% endif %}{% if not node.show_in_menu %} hidden-in-menu{% endif %}{% if not node.is_public %} not-public{% endif %}{% if node.redirect_page %} redirect{% endif %}">
<a href="{{ node.get_absolute_url }}" data-fiber-data='{"type": "page", "id": {{ node.id }}, "parent_id": {{ node.parent.id }}, "url": "{{ node.get_change_url }}", "add_url": "{{ Page.get_add_url }}"}'>{{ node.title }}</a>
{% if children %}
<ul data-fiber-data='{"type": "page", "add_url": "{{ Page.get_add_url }}", "parent_id": {{ node.id }}}'>
@@ -56,10 +56,10 @@ def show_menu(context, menu_name, min_level, max_level, expand=None):
menu_pages.extend(Page.objects.filter(tree_id=root_page.tree_id).filter(level__range=(min_level, max_level)))
"""
- Remove pages that the current user isn't supposed to see.
+ Remove pages that shouldn't be shown in the menu for the current user.
"""
- visible_pages_for_user = Page.objects.visible_pages_for_user(context['user'])
- menu_pages = list(set(menu_pages) & set(visible_pages_for_user))
+ shown_in_menu_for_user = Page.objects.shown_in_menu_for_user(context['user'])
+ menu_pages = list(set(menu_pages) & set(shown_in_menu_for_user))
"""
Order menu_pages for use with tree_info template tag.

0 comments on commit 85a46b2

Please sign in to comment.