Permalink
Browse files

Tweaking and polishing

  • Loading branch information...
1 parent 1b862ec commit c5793bdfabac7d3ac74c9e7344a846f3a7e43b7e @dbunskoek dbunskoek committed Aug 24, 2012
View
@@ -14,7 +14,16 @@
from .app_settings import PERMISSION_CLASS
-class FileAdmin(admin.ModelAdmin):
+class UserPermissionMixin(object):
+ def save_model(self, request, obj, form, change):
+ """
+ Notifies the PERMISSION_CLASS that an `obj` was created by `user`.
+ """
+ super(UserPermissionMixin, self).save_model(request, obj, form, change)
+ load_class(PERMISSION_CLASS).object_created(request.user, obj)
+
+
+class FileAdmin(UserPermissionMixin, admin.ModelAdmin):
list_display = ('title', '__unicode__')
date_hierarchy = 'updated'
search_fields = ('title', )
@@ -37,7 +46,7 @@ def really_delete_selected(self, request, queryset):
really_delete_selected.short_description = _('Delete selected files')
-class ImageAdmin(admin.ModelAdmin):
+class ImageAdmin(UserPermissionMixin, admin.ModelAdmin):
list_display = ('title', '__unicode__')
date_hierarchy = 'updated'
search_fields = ('title', )
@@ -60,7 +69,7 @@ def really_delete_selected(self, request, queryset):
really_delete_selected.short_description = _('Delete selected images')
-class ContentItemAdmin(admin.ModelAdmin):
+class ContentItemAdmin(UserPermissionMixin, admin.ModelAdmin):
list_display = ('__unicode__',)
form = forms.ContentItemAdminForm
fieldsets = (
@@ -72,12 +81,12 @@ class ContentItemAdmin(admin.ModelAdmin):
search_fields = ('name', get_editor_field_name('content_html'))
-class PageContentItemInline(admin.TabularInline):
+class PageContentItemInline(UserPermissionMixin, admin.TabularInline):
model = PageContentItem
extra = 1
-class PageAdmin(MPTTModelAdmin):
+class PageAdmin(UserPermissionMixin, MPTTModelAdmin):
form = forms.PageForm
fieldsets = (
@@ -128,7 +137,7 @@ def action_links(self, page):
action_links.allow_tags = True
-class FiberAdminContentItemAdmin(fiber_admin.ModelAdmin):
+class FiberAdminContentItemAdmin(UserPermissionMixin, fiber_admin.ModelAdmin):
list_display = ('__unicode__',)
form = forms.ContentItemAdminForm
@@ -145,16 +154,8 @@ def __init__(self, *args, **kwargs):
(None, {'classes': ('hide-label',), 'fields': (get_editor_field_name('content_html'), 'template_name', )}),
)
- def save_model(self, request, obj, form, change):
- """
- Notifies the PERMIISSION_CLASS that a ContentItem was created by `user`.
- """
- # workaround because not all ajax calls go through the api yet
- super(FiberAdminContentItemAdmin, self).save_model(request, obj, form, change)
- load_class(PERMISSION_CLASS).object_created(request.user, obj)
-
-class FiberAdminPageAdmin(fiber_admin.MPTTModelAdmin):
+class FiberAdminPageAdmin(UserPermissionMixin, fiber_admin.MPTTModelAdmin):
form = forms.PageForm
@@ -176,8 +177,10 @@ def __init__(self, *args, **kwargs):
def save_model(self, request, obj, form, change):
"""
- Optionally positions a Page `obj` before or beneath another page, based on POST data.
- - Notifies the PERMIISSION_CLASS that a Page was created by `user`.
+ - Notifies the PERMISSION_CLASS that a Page was created by `user`.
"""
+ super(FiberAdminPageAdmin, self).save_model(request, obj, form, change)
+
if 'before_page_id' in request.POST:
before_page = Page.objects.get(pk=int(request.POST['before_page_id']))
obj.parent = before_page.parent
@@ -187,10 +190,6 @@ def save_model(self, request, obj, form, change):
obj.parent = below_page
obj.insert_at(below_page, position='last-child', save=False)
- super(FiberAdminPageAdmin, self).save_model(request, obj, form, change)
-
- # workaround because not all ajax calls go through the api yet
- load_class(PERMISSION_CLASS).object_created(request.user, obj)
admin.site.register(ContentItem, ContentItemAdmin)
admin.site.register(Image, ImageAdmin)
View
@@ -64,6 +64,6 @@ def pages_json(request):
"""
return HttpResponse(
simplejson.dumps(
- Page.objects.create_jqtree_data()
+ Page.objects.create_jqtree_data(request.user)
)
)
View
@@ -25,8 +25,7 @@ def get_content_groups(self, user=None):
- used once
- used more than once
- If `user` is provided the tree is filtered and only contentitems that user is allowed to
- edit are returned.
+ If `user` is provided the queryset is filtered so only the content items that `user` is allowed to edit are returned.
"""
unused = []
once = []
@@ -185,12 +184,11 @@ def get_by_url(self, url):
if get_named_url_from_quoted_url(page.url) == url:
return page
- def create_jqtree_data(self, user=None):
+ def create_jqtree_data(self, user):
"""
Create a page tree suitable for the jqtree. The result is a recursive list of dicts.
- If `user` is provided the tree is filtered and only pages that user is allowed to
- edit are returned.
+ If `user` is provided the tree is annotated to indicate editability of the pages.
Example:
[
@@ -211,10 +209,8 @@ def create_jqtree_data(self, user=None):
# The queryset contains all pages in correct order
queryset = self.model.tree.get_query_set()
- # Filter queryset through the permissions class
- editables_queryset = []
- if user:
- editables_queryset = load_class(PERMISSION_CLASS).filter_objects(user, queryset)
+ # Filter queryset using the permissions class
+ editables_queryset = load_class(PERMISSION_CLASS).filter_objects(user, queryset)
for page in queryset:
page_info = dict(
View
@@ -1,31 +1,31 @@
"""
-Module that provides a base Permission class. This class may be overridden by changinng the `PERMISSION_CLASS` value in the settings module.
+Module that provides a base Permission class. This class may be overridden by changing the `PERMISSION_CLASS` value in the settings module.
"""
class Permissions(object):
"""
- This class defines the methods that a Permission class may implement.
+ This class defines the methods that a Permission class should implement.
- By default all permissions are granted to a staffuser.
+ By default all permissions are granted to a staff user.
"""
def filter_objects(self, user, qs):
"""
- Should only return those objects which `user` is allowed to edit.
+ Should only return those objects whose `user` is allowed to edit.
`qs` can consist of type `Page` or `ContentItem`.
"""
return qs
def filter_images(self, user, qs):
"""
- Called by api while listing images.
+ Called by API while listing images.
"""
return qs
def filter_files(self, user, qs):
"""
- Called by api while listing files.
+ Called by API while listing files.
"""
return qs
@@ -46,4 +46,3 @@ def object_created(self, user, obj):
Called whenever a new instance has been created of one of Fiber's models by `user`.
"""
pass
-
View
@@ -51,7 +51,7 @@ class ListView(ListOrCreateModelView):
def post(self, request, *args, **kwargs):
"""
- Notify the permissions class of a newly created object.
+ Notify the Permissions class of a newly created object.
"""
response = super(ListView, self).post(request, *args, **kwargs)
PERMISSIONS.object_created(request.user, response.raw_content) # raw_content is the Model instance
@@ -62,7 +62,7 @@ class TreeListView(View):
def get(self, request):
"""
- Provide JqTree data for the PageSelect dialog.
+ Provide jqTree data for the PageSelect dialog.
"""
return Page.objects.create_jqtree_data(request.user)
@@ -77,15 +77,15 @@ def check_fields(self, order_by):
def serialize_page_info(self, page):
"""
- Simpledatagrid expects a total_pages key for a paginated view.
+ simple-data-grid expects a total_pages key for a paginated view.
"""
return {
'total_pages': page.paginator.num_pages,
}
def filter_response(self, obj):
"""
- Simpledatagrid expects rows instead of results, which is DRF default.
+ simple-data-grid expects rows instead of results (the Django REST framework default)
"""
obj = super(PaginatedListView, self).filter_response(obj)
if self.request.method.upper() == 'GET':
@@ -685,16 +685,16 @@ ul.tree .toggler.closed {
background-image: url(../images/icon-page-hidden.png);
}
-.ui-dialog-content ul.tree .page.not-public .icon,
-#df-wpr-sidebar ul.tree .page.not-public .icon {
- background-image: url(../images/icon-page-not-public.png);
+.ui-dialog-content ul.tree .page.non-public .icon,
+#df-wpr-sidebar ul.tree .page.non-public .icon {
+ background-image: url(../images/icon-page-non-public.png);
}
-.ui-dialog-content ul.tree .page.hidden-in-menu .title,
-#df-wpr-sidebar ul.tree .page.hidden-in-menu .title,
-.ui-dialog-content ul.tree .page.not-public .title,
-#df-wpr-sidebar ul.tree .page.not-public .title {
+.ui-dialog-content ul.tree .page.non-editable .title,
+#df-wpr-sidebar ul.tree .page.non-editable .title {
color: #999;
+ text-shadow: 0 1px 0 #fff;
+ filter: dropshadow(color=#fff, offx=0, offy=1);
}
.ui-dialog-content ul.tree div,
@@ -722,14 +722,20 @@ ul.tree .toggler.closed {
text-shadow: 0 1px 0 rgba(255,255,255,0.7);
}
+.ui-dialog-content ul.tree div.page.non-editable:hover,
+#df-wpr-sidebar ul.tree div.page.non-editable:hover {
+ background: none;
+ cursor: default;
+}
+
#df-wpr-sidebar ul.tree .moving > div .title,
ul.tree .moving > div .title {
outline: 1px dashed #666;
}
/* permissions-related styling */
-.ui-dialog .not-editable,
-#df-wpr-sidebar .sidebar-tree .not-editable .title {
+.ui-dialog .non-editable,
+#df-wpr-sidebar .sidebar-tree .non-editable .title {
color: #f00;
}
@@ -632,7 +632,7 @@ var BaseFileSelectDialog = AdminRESTDialog.extend({
uneditables_formatter: function(value, row_data) {
if (!row_data.can_edit) {
- return '<span class="not-editable">' + value + '</span>';
+ return '<span class="non-editable">' + value + '</span>';
}
return value;
},
@@ -795,7 +795,7 @@ Fiber.ImageSelectDialog = BaseFileSelectDialog.extend({
// TODO: use image checksum for cache busting?
return '<span style="display: none;">' + row_data.image_url + '</span>' + '<img src="' + row_data.image_url + '?_c=' + encodeURIComponent(row_data.url) + '" title="' + row_data.title + '"/>';
}
-
+
this.select_grid.simple_datagrid({
columns: [
{title: gettext('Image'), key: 'image', on_generate: thumbnail_formatter},
@@ -1427,15 +1427,15 @@ var adminPage = {
}
if (!node.is_public) {
- $div.addClass('not-public');
+ $div.addClass('non-public');
}
if (node.is_redirect) {
$div.addClass('redirect');
}
if (!node.editable) {
- $div.addClass('not-editable');
+ $div.addClass('non-editable');
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,25 +1,56 @@
{% load fiber_tags %}
{% if content_item %}
- {% if content_item|can_edit:user %}
- {% if fiber_page %}
- {% if content_item.page_content_item %}
- <div data-fiber-data='{ "can_edit":true, "type": "content_item", "id": {{ content_item.id }}, "url": "{{ content_item.get_change_url }}", "add_url": "{{ ContentItem.get_add_url }}", "page_id": {{ fiber_page.id }}, "block_name": "{{ fiber_block_name }}", "page_content_item_id": {{ content_item.page_content_item.id }}, "used_on_pages": {{ content_item.get_used_on_pages_json|safe|escape_json_for_html }}}' class="content">
- {% else %}
- <div data-fiber-data='{ "can_edit":true, "type": "content_item", "id": {{ content_item.id }}, "url": "{{ content_item.get_change_url }}", "add_url": "{{ ContentItem.get_add_url }}", "page_id": {{ fiber_page.id }}, "block_name": "{{ fiber_block_name }}"}' class="content">
- {% endif %}
- {% else %}
- <div data-fiber-data='{ "can_edit":true, "type": "content_item", "id": {{ content_item.id }}, "url": "{{ content_item.get_change_url }}"}' class="content">
- {% endif %}
- {% else %}
- <div class="content">
- {% endif %}
-
- {% if content_item.template_name %}
- {% include content_item.template_name %}
- {% else %}
- {{ content_item.content_html|safe }}
- {% endif %}
-
- </div>
+ {% if content_item|can_edit:user %}
+ {% if fiber_page %}
+ {% if content_item.page_content_item %}
+
+<div data-fiber-data='{
+ "can_edit": true,
+ "type": "content_item",
+ "id": {{ content_item.id }},
+ "url": "{{ content_item.get_change_url }}",
+ "add_url": "{{ ContentItem.get_add_url }}",
+ "page_id": {{ fiber_page.id }},
+ "block_name": "{{ fiber_block_name }}",
+ "page_content_item_id": {{ content_item.page_content_item.id }},
+ "used_on_pages": {{ content_item.get_used_on_pages_json|safe|escape_json_for_html }}
+}' class="content">
+
+ {% else %}
+
+<div data-fiber-data='{
+ "can_edit": true,
+ "type": "content_item",
+ "id": {{ content_item.id }},
+ "url": "{{ content_item.get_change_url }}",
+ "add_url": "{{ ContentItem.get_add_url }}",
+ "page_id": {{ fiber_page.id }},
+ "block_name": "{{ fiber_block_name }}"
+}' class="content">
+
+ {% endif %}
+ {% else %}
+
+<div data-fiber-data='{
+ "can_edit": true,
+ "type": "content_item",
+ "id": {{ content_item.id }},
+ "url": "{{ content_item.get_change_url }}"
+}' class="content">
+
+ {% endif %}
+ {% else %}
+
+<div class="content">
+
+ {% endif %}
+
+ {% if content_item.template_name %}
+ {% include content_item.template_name %}
+ {% else %}
+ {{ content_item.content_html|safe }}
+ {% endif %}
+
+</div>
{% endif %}
Oops, something went wrong.

0 comments on commit c5793bd

Please sign in to comment.