Skip to content

Commit

Permalink
Merge branch 'feature/speedups' of https://github.com/stephrdev/djang…
Browse files Browse the repository at this point in the history
…o-cms into stephrdev-feature/speedups
  • Loading branch information
Jonas Obrist committed Aug 25, 2011
2 parents 2a46231 + c8312f7 commit 421961d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
7 changes: 6 additions & 1 deletion cms/api.py
Expand Up @@ -11,6 +11,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db.models import Max
from django.template.defaultfilters import slugify
from menus.menu_pool import menu_pool

Expand Down Expand Up @@ -266,10 +267,14 @@ def add_plugin(placeholder, plugin_type, language, position='last-child',
# validate and normalize plugin type
plugin_model, plugin_type = _verify_plugin_type(plugin_type)


max_pos = CMSPlugin.objects.filter(language=language,
placeholder=placeholder).aggregate(Max('position')).values()[0] or 0

plugin_base = CMSPlugin(
plugin_type=plugin_type,
placeholder=placeholder,
position=1,
position=max_pos + 1,
language=language
)
plugin_base.insert_at(target, position=position, save=False)
Expand Down
22 changes: 15 additions & 7 deletions cms/templatetags/cms_admin.py
Expand Up @@ -80,13 +80,21 @@ def boolean_icon(value):

@register.filter
def is_restricted(page, request):
all_perms = get_any_page_view_permissions(request, page)
icon = boolean_icon(all_perms.exists())
return mark_safe(
ugettext('<span title="Restrictions: %(title)s">%(icon)s</span>') % {
'title': u', '.join((perm.get_grant_on_display() for perm in all_perms)) or None,
'icon': icon,
})
if settings.CMS_PERMISSION:
all_perms = get_any_page_view_permissions(request, page)
icon = boolean_icon(all_perms.exists())
return mark_safe(
ugettext('<span title="Restrictions: %(title)s">%(icon)s</span>') % {
'title': u', '.join((perm.get_grant_on_display() for perm in all_perms)) or None,
'icon': icon,
})
else:
icon = boolean_icon(None)
return mark_safe(
ugettext('<span title="Restrictions: %(title)s">%(icon)s</span>') % {
'title': None,
'icon': icon,
})

@register.filter
def moderator_choices(page, user):
Expand Down
7 changes: 4 additions & 3 deletions cms/utils/admin.py
Expand Up @@ -41,9 +41,10 @@ def get_admin_menu_item_context(request, page, filtered=False):
moderator_state = moderator.page_moderator_state(request, page)
has_add_on_same_level_permission = False
opts = Page._meta
if (request.user.has_perm(opts.app_label + '.' + opts.get_add_permission()) and
GlobalPagePermission.objects.with_user(request.user).filter(can_add=True, sites__in=[page.site_id])):
has_add_on_same_level_permission = True
if settings.CMS_PERMISSION:
if (request.user.has_perm(opts.app_label + '.' + opts.get_add_permission()) and
GlobalPagePermission.objects.with_user(request.user).filter(can_add=True, sites__in=[page.site_id])):
has_add_on_same_level_permission = True

if not has_add_on_same_level_permission and page.parent_id:
has_add_on_same_level_permission = permissions.has_generic_permission(page.parent_id, request.user, "add", page.site)
Expand Down

0 comments on commit 421961d

Please sign in to comment.