Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed all uses of the CMS_MODERATOR flag

Fixed tests to ensure that public and draft pages are used in the proper places.
  • Loading branch information...
commit b76641be80782925f70cd67f30e5aaba3b793d18 1 parent 74bdf0a
@adaptivelogic adaptivelogic authored
Showing with 513 additions and 757 deletions.
  1. +4 −43 cms/admin/change_list.py
  2. +0 −13 cms/admin/dialog/forms.py
  3. +4 −18 cms/admin/dialog/views.py
  4. +20 −63 cms/admin/pageadmin.py
  5. +1 −9 cms/admin/permissionadmin.py
  6. +22 −42 cms/api.py
  7. +5 −10 cms/appresolver.py
  8. +6 −16 cms/cms_toolbar.py
  9. +1 −1  cms/conf/__init__.py
  10. +0 −4 cms/conf/global_settings.py
  11. +3 −5 cms/forms/utils.py
  12. +2 −7 cms/management/commands/publisher_publish.py
  13. +18 −4 cms/management/commands/subcommands/moderator.py
  14. +2 −1  cms/menu.py
  15. +3 −10 cms/models/managers.py
  16. +0 −2  cms/models/metaclasses.py
  17. +43 −54 cms/models/pagemodel.py
  18. +0 −1  cms/models/permissionmodels.py
  19. +0 −2  cms/models/query.py
  20. +1 −1  cms/plugins/inherit/cms_plugins.py
  21. +1 −1  cms/sitemaps/cms_sitemap.py
  22. +1 −7 cms/templates/admin/cms/page/change_form.html
  23. +1 −1  cms/templatetags/cms_admin.py
  24. +1 −1  cms/templatetags/cms_tags.py
  25. +0 −1  cms/test_utils/cli.py
  26. +3 −3 cms/test_utils/fixtures/menus.py
  27. +1 −1  cms/test_utils/fixtures/navextenders.py
  28. +1 −1  cms/test_utils/fixtures/templatetags.py
  29. +23 −63 cms/tests/admin.py
  30. +39 −38 cms/tests/apphooks.py
  31. +28 −31 cms/tests/forms.py
  32. +1 −7 cms/tests/menu.py
  33. +0 −2  cms/tests/menu_page_viewperm.py
  34. +0 −1  cms/tests/menu_page_viewperm_staff.py
  35. +1 −2  cms/tests/multilingual.py
  36. +1 −2  cms/tests/navextender.py
  37. +3 −3 cms/tests/nested_plugins.py
  38. +23 −27 cms/tests/nonroot.py
  39. +98 −77 cms/tests/page.py
  40. +57 −75 cms/tests/permmod.py
  41. +2 −2 cms/tests/placeholder.py
  42. +40 −37 cms/tests/plugins.py
  43. +1 −11 cms/tests/publisher.py
  44. +0 −1  cms/tests/rendering.py
  45. +0 −1  cms/tests/templatetags.py
  46. +3 −11 cms/tests/toolbar.py
  47. +1 −2  cms/tests/views.py
  48. +0 −2  cms/utils/admin.py
  49. +13 −16 cms/utils/moderator.py
  50. +1 −2  cms/utils/page.py
  51. +30 −18 cms/utils/page_resolver.py
  52. +4 −4 cms/utils/permissions.py
View
47 cms/admin/change_list.py
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from cms.exceptions import NoHomeFound
-from cms.models import Title, Page, PageModerator
-from cms.models.moderatormodels import MASK_PAGE, MASK_CHILDREN, \
- MASK_DESCENDANTS, PageModeratorState
+from cms.models import Title, Page
from cms.utils.permissions import get_user_sites_queryset
from django.conf import settings
from django.contrib.admin.views.main import ChangeList, ALL_VAR, IS_POPUP_VAR, \
@@ -120,27 +118,7 @@ def set_items(self, request):
if perm_edit_ids and perm_edit_ids != Page.permissions.GRANT_ALL:
pages = pages.filter(pk__in=perm_edit_ids)
#pages = pages.filter(pk__in=perm_change_list_ids)
-
- if settings.CMS_MODERATOR:
- # get all ids of public instances, so we can cache them
- # TODO: add some filtering here, so the set is the same like page set...
- published_public_page_id_set = Page.objects.public().filter(published=True).values_list('id', flat=True)
-
- # get all moderations for current user and all pages
- pages_moderator_set = PageModerator.objects \
- .filter(user=request.user, page__site=self._current_site) \
- .values_list('page', 'moderate_page', 'moderate_children', 'moderate_descendants')
- # put page / moderations into singe dictionary, where key is page.id
- # and value is sum of moderations, so if he can moderate page and descendants
- # value will be MASK_PAGE + MASK_DESCENDANTS
- page_moderator = map(lambda item: (item[0], item[1] * MASK_PAGE + item[2] * MASK_CHILDREN + item[3] * MASK_DESCENDANTS), pages_moderator_set)
- page_moderator = dict(page_moderator)
-
- # page moderator states
- pm_qs = PageModeratorState.objects.filter(page__site=self._current_site)
- pm_qs.query.group_by = ['page_id']
- pagemoderator_states_id_set = pm_qs.values_list('page', flat=True)
-
+
ids = []
root_pages = []
pages = list(pages)
@@ -156,7 +134,6 @@ def set_items(self, request):
cache_tree_children(pages)
for page in pages:
-
children = list(page.get_children())
@@ -176,23 +153,7 @@ def set_items(self, request):
page.permission_publish_cache = perm_publish_ids == Page.permissions.GRANT_ALL or page.pk in perm_publish_ids
page.permission_advanced_settings_cache = perm_advanced_settings_ids == Page.permissions.GRANT_ALL or page.pk in perm_advanced_settings_ids
page.permission_user_cache = request.user
-
- if settings.CMS_MODERATOR:
- # set public instance existence state
- page.public_published_cache = page.publisher_public_id in published_public_page_id_set
-
- # moderation for current user
- moderation_value = 0
- try:
- moderation_value = page_moderator[page.pk]
- except:
- pass
- page._moderation_value_cache = moderation_value
- page._moderation_value_cache_for_user_id = request.user.pk
-
- #moderation states
- page._has_moderator_state_cache = page.pk in pagemoderator_states_id_set
-
+
if page.root_node or self.is_filtered():
page.last = True
if len(children):
@@ -222,7 +183,7 @@ def set_items(self, request):
page.childrens = []
else:
page.childrens = children
-
+
# TODO: OPTIMIZE!!
titles = Title.objects.filter(page__in=ids)
for page in all_pages:# add the title and slugs and some meta data
View
13 cms/admin/dialog/forms.py
@@ -9,16 +9,3 @@ class PermissionForm(forms.Form):
copy_permissions = forms.BooleanField(label=_('Copy permissions'),
required=False, initial=True)
-class ModeratorForm(forms.Form):
- '''
- Holds the specific field for moderator
- '''
- copy_moderation = forms.BooleanField(label=_('Copy moderation'),
- required=False, initial=True)
-
-class PermissionAndModeratorForm(PermissionForm, ModeratorForm):
- '''
- Subclass of both ModeratorForm AND PermissionForm, thus it inherits both
- fields
- '''
- pass
View
22 cms/admin/dialog/views.py
@@ -1,40 +1,26 @@
# -*- coding: utf-8 -*-
-from cms.admin.dialog.forms import PermissionAndModeratorForm, PermissionForm, ModeratorForm
+from cms.admin.dialog.forms import PermissionForm
from cms.models import Page
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.http import Http404, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
-def _form_class_selector():
- '''
- This replaces the magic that used to happen in forms, where a dynamic
- class was generated at runtime. Now it's a bit cleaner...
- '''
- form_class = None
- if settings.CMS_PERMISSION and settings.CMS_MODERATOR:
- form_class = PermissionAndModeratorForm
- elif settings.CMS_PERMISSION:
- form_class = PermissionForm
- elif settings.CMS_MODERATOR:
- form_class = ModeratorForm
- return form_class
-
@staff_member_required
def get_copy_dialog(request, page_id):
- if not (settings.CMS_PERMISSION or settings.CMS_MODERATOR):
+ if not settings.CMS_PERMISSION:
return HttpResponse('')
page = get_object_or_404(Page, pk=page_id)
target = get_object_or_404(Page, pk=request.REQUEST['target'])
if not page.has_change_permission(request) or \
- not target.has_add_permission(request): # pragma: no cover
+ not target.has_add_permission(request):
raise Http404
context = {
'dialog_id': 'dialog-copy',
- 'form': _form_class_selector()(), # class needs to be instanciated
+ 'form': PermissionForm(), # class needs to be instantiated
'callback': request.REQUEST['callback'],
}
return render_to_response("admin/cms/page/dialog/copy.html", context)
View
83 cms/admin/pageadmin.py
@@ -20,10 +20,8 @@
from cms.utils.i18n import get_language_dict, get_language_list, get_language_tuple, get_language_object
from cms.utils.page_resolver import is_valid_url
from cms.utils.admin import jsonify_request
-from cms.utils.permissions import has_plugin_permission
from copy import deepcopy
from distutils.version import LooseVersion
-from django import template
from django.conf import settings
from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters
@@ -35,7 +33,7 @@
from django.db import router, transaction, models
from django.forms import CharField
from django.http import (HttpResponseRedirect, HttpResponse, Http404,
- HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed, HttpResponseServerError)
+ HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed)
from django.shortcuts import render_to_response, get_object_or_404
from django.template.context import RequestContext
from django.template.defaultfilters import (title, escape, force_escape,
@@ -88,8 +86,6 @@ def contribute_fieldsets(cls):
general_fields.append('publication_date')
elif settings.CMS_SHOW_END_DATE:
general_fields.append( 'publication_end_date')
- if settings.CMS_MODERATOR:
- additional_hidden_fields += ['moderator_state', 'moderator_message']
if settings.CMS_SEO_FIELDS:
seo_fields = ['page_title', 'meta_description', 'meta_keywords']
if not settings.CMS_URL_OVERWRITE:
@@ -137,8 +133,6 @@ def contribute_fieldsets(cls):
def contribute_list_filter(cls):
list_filter = ['published', 'in_navigation', 'template', 'changed_by']
- if settings.CMS_MODERATOR:
- list_filter.append('moderator_state')
if settings.CMS_SOFTROOT:
list_filter.append('soft_root')
setattr(cls, 'list_filter', list_filter)
@@ -211,7 +205,6 @@ def get_urls(self):
pat(r'^([0-9]+)/permissions/$', self.get_permissions),
pat(r'^([0-9]+)/moderation-states/$', self.get_moderation_states),
pat(r'^([0-9]+)/change-moderation/$', self.change_moderation),
- pat(r'^([0-9]+)/approve/$', self.approve_page), # approve page
pat(r'^([0-9]+)/publish/$', self.publish_page), # publish page
pat(r'^([0-9]+)/remove-delete-state/$', self.remove_delete_state),
pat(r'^([0-9]+)/dialog/copy/$', get_copy_dialog), # copy dialog
@@ -489,15 +482,6 @@ def get_formsets(self, request, obj=None):
def add_view(self, request, form_url='', extra_context=None):
extra_context = extra_context or {}
- if settings.CMS_MODERATOR and 'target' in request.GET and 'position' in request.GET:
- moderation_required = moderator.will_require_moderation(
- request.GET['target'], request.GET['position']
- )
- extra_context.update({
- 'moderation_required': moderation_required,
- 'moderation_level': _('higher'),
- 'show_save_and_continue':True,
- })
language = get_language_from_request(request)
extra_context.update({
'language': language,
@@ -517,10 +501,9 @@ def change_view(self, request, object_id, extra_context=None):
obj = None
else:
selected_template = get_template_from_request(request, obj)
- moderation_level, moderation_required = moderator.get_test_moderation_level(obj, request.user)
# if there is a delete request for this page
- moderation_delete_request = (settings.CMS_MODERATOR and
+ moderation_delete_request = (
obj.pagemoderatorstate_set.get_delete_actions(
).count())
@@ -530,14 +513,8 @@ def change_view(self, request, object_id, extra_context=None):
'placeholders': self.get_fieldset_placeholders(selected_template),
'page': obj,
'CMS_PERMISSION': settings.CMS_PERMISSION,
- 'CMS_MODERATOR': settings.CMS_MODERATOR,
'ADMIN_MEDIA_URL': settings.STATIC_URL,
'has_change_permissions_permission': obj.has_change_permissions_permission(request),
- 'has_moderate_permission': obj.has_moderate_permission(request),
- 'moderation_level': moderation_level,
- 'moderation_required': moderation_required,
- 'moderator_should_approve': moderator.moderator_should_approve(request, obj),
- 'moderation_delete_request': moderation_delete_request,
'show_delete_translation': len(obj.get_languages()) > 1,
'current_site_id': settings.SITE_ID,
}
@@ -585,10 +562,9 @@ def response_change(self, request, obj):
some new stuff, which should be published after all other objects on page
are collected.
"""
- if settings.CMS_MODERATOR:
- # save the object again, so all the related changes to page model
- # can be published if required
- obj.save()
+ # save the object again, so all the related changes to page model
+ # can be published if required
+ obj.save()
return super(PageAdmin, self).response_change(request, obj)
def has_add_permission(self, request):
@@ -690,7 +666,6 @@ def changelist_view(self, request, extra_context=None):
'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
'softroot': settings.CMS_SOFTROOT,
'CMS_PERMISSION': settings.CMS_PERMISSION,
- 'CMS_MODERATOR': settings.CMS_MODERATOR,
'has_recover_permission': 'reversion' in settings.INSTALLED_APPS and self.has_recover_permission(request),
'DEBUG': settings.DEBUG,
'site_languages': languages,
@@ -832,7 +807,6 @@ def copy_page(self, request, page_id, extra_context=None):
try:
kwargs = {
'copy_permissions': request.REQUEST.get('copy_permissions', False),
- 'copy_moderation': request.REQUEST.get('copy_moderation', False),
}
page.copy_page(target, site, position, **kwargs)
return jsonify_request(HttpResponse("ok"))
@@ -842,50 +816,31 @@ def copy_page(self, request, page_id, extra_context=None):
return HttpResponseRedirect('../../')
def get_moderation_states(self, request, page_id):
- """Returns moderation messsages. Is loaded over ajax to inline-group
+ """Returns moderation messages. Is loaded over ajax to inline-group
element in change form view.
"""
page = get_object_or_404(Page, id=page_id)
- if not page.has_moderate_permission(request):
- raise Http404()
-
context = {
'page': page,
}
return render_to_response('admin/cms/page/moderation_messages.html', context)
@transaction.commit_on_success
- def approve_page(self, request, page_id):
- """Approve changes on current page by user from request.
- """
- #TODO: change to POST method !! get is not safe
+ def publish_page(self, request, page_id):
page = get_object_or_404(Page, id=page_id)
- if not page.has_moderate_permission(request):
- raise Http404()
-
- moderator.approve_page(request, page)
+ # ensure user has permissions to publish this page
+ if not page.has_publish_permission(request):
+ return HttpResponseForbidden("Denied")
+ page.publish()
# Django SQLite bug. Does not convert to string the lazy instances
from django.utils.translation import ugettext as _
- self.message_user(request, _('Page was successfully approved.'))
+ self.message_user(request, _('Page was successfully published.'))
if 'node' in request.REQUEST:
# if request comes from tree..
return admin_utils.render_admin_menu_item(request, page)
- referer = request.META.get('HTTP_REFERER', reverse('admin:cms_page_changelist'))
- path = '../../'
- if 'admin' not in referer:
- path = '%s?edit-off' % referer.split('?')[0]
- return HttpResponseRedirect( path )
-
- @transaction.commit_on_success
- def publish_page(self, request, page_id):
- page = get_object_or_404(Page, id=page_id)
- # ensure user has permissions to publish this page
- if not page.has_moderate_permission(request):
- return HttpResponseForbidden("Denied")
- page.publish()
referer = request.META.get('HTTP_REFERER', '')
path = '../../'
# TODO: use admin base here!
@@ -895,7 +850,7 @@ def publish_page(self, request, page_id):
def delete_view(self, request, object_id, *args, **kwargs):
- """If page is under modaretion, just mark this page for deletion = add
+ """If page is under moderation, just mark this page for deletion = add
delete action to page states.
"""
page = get_object_or_404(Page, id=object_id)
@@ -903,7 +858,7 @@ def delete_view(self, request, object_id, *args, **kwargs):
if not self.has_delete_permission(request, page):
raise PermissionDenied
- if page.is_under_moderation():
+ if page.published:
# don't perform a delete action, just mark page for deletion
page.force_moderation_action = PageModeratorState.ACTION_DELETE
page.moderator_state = Page.MODERATOR_NEED_DELETE_APPROVEMENT
@@ -1395,17 +1350,19 @@ def remove_plugin(self, request):
placeholder = plugin.placeholder
page = placeholder.page if placeholder else None
- if page and not page.has_change_permission(request):
- raise Http404
+ if page:
+ if not page.publisher_is_draft:
+ raise Http404
+ if not page.has_change_permission(request):
+ raise HttpResponseForbidden(ugettext("You have no permission to remove a plugin"))
- if page and settings.CMS_MODERATOR and page.is_under_moderation():
# delete the draft version of the plugin
plugin.delete()
# set the page to require approval and save
page.moderator_state = Page.MODERATOR_NEED_APPROVEMENT
page.save()
else:
- plugin.delete_with_public()
+ plugin.delete()
plugin_name = unicode(plugin_pool.get_plugin(plugin.plugin_type).name)
comment = ugettext(u"%(plugin_name)s plugin at position %(position)s in %(placeholder)s was deleted.") % {
View
10 cms/admin/permissionadmin.py
@@ -78,8 +78,6 @@ def get_formset(self, request, obj=None, **kwargs):
exclude.append('can_change_advanced_settings')
if not obj.has_move_page_permission(request):
exclude.append('can_move_page')
- if not settings.CMS_MODERATOR or not obj.has_moderate_permission(request):
- exclude.append('can_moderate')
formset_cls = super(PagePermissionInlineAdmin, self
).get_formset(request, obj=None, exclude=exclude, *kwargs)
qs = self.queryset(request)
@@ -96,7 +94,7 @@ class ViewRestrictionInlineAdmin(PagePermissionInlineAdmin):
exclude = [
'can_add', 'can_change', 'can_delete', 'can_view',
'can_publish', 'can_change_advanced_settings', 'can_move_page',
- 'can_moderate', 'can_change_permissions'
+ 'can_change_permissions'
]
def get_formset(self, request, obj=None, **kwargs):
@@ -133,12 +131,6 @@ class GlobalPagePermissionAdmin(admin.ModelAdmin):
list_display.append('can_change_advanced_settings')
list_filter.append('can_change_advanced_settings')
-
- if settings.CMS_MODERATOR:
- list_display.append('can_moderate')
- list_filter.append('can_moderate')
- else:
- exclude.append('can_moderate')
class GenericCmsPermissionAdmin(object):
View
64 cms/api.py
@@ -7,6 +7,7 @@
calling these methods!
"""
import datetime
+from django.core.exceptions import PermissionDenied
from cms.utils.i18n import get_language_list
from django.conf import settings
@@ -191,9 +192,6 @@ def create_page(title, template, language, menu_title=None, slug=None,
page.insert_at(parent, position)
page.save()
- if settings.CMS_MODERATOR and _thread_locals.user:
- page.pagemoderator_set.create(user=_thread_locals.user)
-
create_title(
language=language,
title=title,
@@ -335,7 +333,7 @@ def create_page_user(created_by, user,
def assign_user_to_page(page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
can_add=False, can_change=False, can_delete=False,
can_change_advanced_settings=False, can_publish=False,
- can_change_permissions=False, can_move_page=False, can_moderate=False,
+ can_change_permissions=False, can_move_page=False,
can_recover_page=True, can_view=False,
grant_all=False, global_permission=False):
"""
@@ -343,22 +341,18 @@ def assign_user_to_page(page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
See docs/extending_cms/api_reference.rst for more info
"""
- if grant_all and not global_permission:
- # shortcut to grant all permissions
- return assign_user_to_page(page, user, grant_on, True, True, True, True,
- True, True, True, True, True)
-
+ grant_all = grant_all and not global_permission
data = {
- 'can_add': can_add,
- 'can_change': can_change,
- 'can_delete': can_delete,
- 'can_change_advanced_settings': can_change_advanced_settings,
- 'can_publish': can_publish,
- 'can_change_permissions': can_change_permissions,
- 'can_move_page': can_move_page,
- 'can_moderate': can_moderate,
- 'can_view': can_view,
- }
+ 'can_add': can_add or grant_all,
+ 'can_change': can_change or grant_all,
+ 'can_delete': can_delete or grant_all,
+ 'can_change_advanced_settings': can_change_advanced_settings or grant_all,
+ 'can_publish': can_publish or grant_all,
+ 'can_change_permissions': can_change_permissions or grant_all,
+ 'can_move_page': can_move_page or grant_all,
+ 'can_view': can_view or grant_all,
+ }
+
page_permission = PagePermission(page=page, user=user,
grant_on=grant_on, **data)
page_permission.save()
@@ -369,28 +363,10 @@ def assign_user_to_page(page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
page_permission.sites.add(Site.objects.get_current())
return page_permission
-def publish_page(page, user, approve=False):
+def publish_page(page, user):
"""
- Publish a page. This sets `page.published` to `True` and saves it, which
- triggers `cms.utils.moderator.page_changed` which does the actual moderation
- and publishing action.
-
- See docs/extending_cms/api_reference.rst for more info
- """
- page.published = True
- # the magic happens in the post save signal here... WTF?
- page.save()
- page.publish()
- # reload page
- page = Page.objects.get(pk=page.pk)
- # approve page if requested
- if approve:
- page = approve_page(page, user)
- return page.reload()
-
-def approve_page(page, user):
- """
- Approve a page version.
+ Publish a page. This sets `page.published` to `True` and calls publish()
+ which does the actual publishing.
See docs/extending_cms/api_reference.rst for more info
"""
@@ -398,5 +374,9 @@ class FakeRequest(object):
def __init__(self, user):
self.user = user
request = FakeRequest(user)
- moderator.approve_page(request, page)
- return Page.objects.get(pk=page.pk)
+ if not page.has_publish_permission(request):
+ raise PermissionDenied
+ page.published = True
+ page.save()
+ page.publish()
+ return page.reload()
View
15 cms/appresolver.py
@@ -2,7 +2,7 @@
from __future__ import with_statement
from cms.apphook_pool import apphook_pool
from cms.utils.i18n import force_language, get_language_list
-from cms.utils.moderator import get_page_queryset
+from cms.utils.page_resolver import get_page_queryset
from django.conf import settings
from django.conf.urls.defaults import patterns
@@ -38,10 +38,7 @@ def applications_page_check(request, current_page=None, path=None):
try:
page_id = resolver.resolve_page_id(path)
# yes, it is application page
- if settings.CMS_MODERATOR:
- page = get_page_queryset(request).get(Q(id=page_id) | Q(publisher_draft=page_id))
- else:
- page = get_page_queryset(request).get(id=page_id)
+ page = get_page_queryset(request).get(id=page_id)
# If current page was matched, then we have some override for content
# from cms, but keep current page. Otherwise return page to which was application assigned.
return page
@@ -178,12 +175,10 @@ def get_app_patterns():
included = []
# we don't have a request here so get_page_queryset() can't be used,
- # so, if CMS_MODERATOR, use, public() queryset, otherwise
- # use draft(). This can be done, because url patterns are used just
- # in frontend
- is_draft = not settings.CMS_MODERATOR
+ # so use public() queryset.
+ # This can be done because url patterns are used just in frontend
- title_qs = Title.objects.filter(page__publisher_is_draft=is_draft, page__site=current_site)
+ title_qs = Title.objects.public().filter(page__site=current_site)
hooked_applications = {}
View
22 cms/cms_toolbar.py
@@ -99,22 +99,12 @@ def get_items(self, context, **kwargs):
)
# publish button
- if self.edit_mode and settings.CMS_MODERATOR:
- moderator_state = page_moderator_state(self.request, self.request.current_page)
- should_approve = moderator_state['state'] >= I_APPROVE
- has_perms = self.request.current_page.has_moderate_permission(self.request)
- if should_approve and has_perms:
- label = moderator_state['label']
- urlgetter = _get_approve_url
- elif has_perms:
- label = _("Publish")
- urlgetter = _get_publish_url
- else:
- urlgetter = _get_approve_url
- label = _("Request Approval")
- items.append(
- GetButton(RIGHT, 'moderator', label, urlgetter)
- )
+ if self.edit_mode:
+ has_perms = self.request.current_page.has_publish_permission(self.request)
+ if has_perms:
+ items.append(
+ GetButton(RIGHT, 'moderator', _("Publish"), _get_publish_url)
+ )
has_global_current_page_change_permission = False
if settings.CMS_PERMISSION:
View
2  cms/conf/__init__.py
@@ -20,7 +20,7 @@ def patch_settings():
warnings.warn("CMS_FLAT_URLS are deprecated and will be removed in django CMS 2.4!", CMSDeprecationWarning)
if getattr(settings, 'CMS_MODERATOR', False):
- warnings.warn("CMS_MODERATOR will be removed and replaced in django CMS 2.4!", CMSDeprecationWarning)
+ warnings.warn("CMS_MODERATOR has no function in django CMS 2.4!", CMSDeprecationWarning)
from cms.conf import global_settings
# patch settings
View
4 cms/conf/global_settings.py
@@ -118,10 +118,6 @@
# Path (relative to MEDIA_ROOT/MEDIA_URL) to directory for storing page-scope files.
CMS_PAGE_MEDIA_PATH = 'cms_page_media/'
-# moderator mode - if True, approve path can be setup for every page, so there
-# will be some control over the published stuff
-CMS_MODERATOR = False
-
# Defines what character will be used for the __unicode__ handling of cms pages
CMS_TITLE_CHARACTER = '+'
View
8 cms/forms/utils.py
@@ -16,11 +16,9 @@ def update_site_and_page_choices(lang=None):
lang = lang or translation.get_language()
SITE_CHOICES_KEY = get_site_cache_key(lang)
PAGE_CHOICES_KEY = get_page_cache_key(lang)
- if settings.CMS_MODERATOR:
- title_queryset = Title.objects.filter(page__publisher_is_draft=False)
- else:
- title_queryset = Title.objects.filter(page__publisher_is_draft=True)
- title_queryset = title_queryset.select_related('page', 'page__site').order_by('page__tree_id', 'page__lft', 'page__rght')
+ title_queryset = Title.objects.drafts() \
+ .select_related('page', 'page__site') \
+ .order_by('page__tree_id', 'page__lft', 'page__rght')
pages = defaultdict(SortedDict)
sites = {}
for title in title_queryset:
View
9 cms/management/commands/publisher_publish.py
@@ -1,16 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
-from django.conf import settings
from django.core.management.base import NoArgsCommand, CommandError
class Command(NoArgsCommand):
def handle_noargs(self, **options):
- """Create published public version of all published drafts. Useful,
- when CMS_MODERATOR gets turned on after some time.
+ """Create published public version of all published drafts.
"""
- if not getattr(settings, 'CMS_MODERATOR', False):
- raise CommandError("This command may be used only with settings.CMS_MODERATOR")
-
self.publish_pages()
def publish_pages(self):
@@ -27,7 +22,7 @@ def publish_pages(self):
raise CommandError("No super user found, create one using `manage.py createsuperuser`.")
set_current_user(user) # set him as current user
-
+
qs = Page.objects.drafts().filter(published=True)
pages_total, pages_published = qs.count(), 0
View
22 cms/management/commands/subcommands/moderator.py
@@ -1,16 +1,30 @@
# -*- coding: utf-8 -*-
from cms.management.commands.subcommands.base import SubcommandsCommand
+from cms.models import CMSPlugin
from cms.models.pagemodel import Page
-from django.conf import settings
from django.core.management.base import NoArgsCommand
class ModeratorOnCommand(NoArgsCommand):
- help = 'Turn moderation on, run AFTER setting CMS_MODERATOR = True'
+ help = 'Turn moderation on, run AFTER upgrading to 2.4'
def handle_noargs(self, **options):
- assert settings.CMS_MODERATOR == True, 'Command can only be run if CMS_MODERATOR is True'
- for page in Page.objects.filter(published=True):
+ """
+ Ensure that the public pages look the same as their draft versions.
+ This is done by checking the content of the public pages, and reverting
+ the draft version to look the same.
+
+ The second stage is to go through the draft pages and publish the ones
+ marked as published.
+
+ The end result should be that the public pages and their draft versions
+ have the same plugins listed. If both versions exist and have content,
+ the public page has precedence. Otherwise, the draft version is used.
+ """
+ for page in Page.objects.public():
+ if CMSPlugin.objects.filter(placeholder__page=page).count():
+ page.revert()
+ for page in Page.objects.drafts().filter(published=True):
page.publish()
View
3  cms/menu.py
@@ -7,7 +7,8 @@
from cms.models.titlemodels import Title
from cms.utils import get_language_from_request
from cms.utils.i18n import get_fallback_languages, hide_untranslated
-from cms.utils.moderator import get_page_queryset, get_title_queryset
+from cms.utils.page_resolver import get_page_queryset
+from cms.utils.moderator import get_title_queryset
from cms.utils.plugins import current_site
from menus.base import Menu, NavigationNode, Modifier
from menus.menu_pool import menu_pool
View
13 cms/models/managers.py
@@ -101,8 +101,7 @@ def search(self, q, language=None, current_site_only=True):
"""
from cms.plugin_pool import plugin_pool
qs = self.get_query_set()
- if settings.CMS_MODERATOR:
- qs = qs.public()
+ qs = qs.public()
if current_site_only:
site = Site.objects.get_current()
@@ -339,6 +338,8 @@ def for_page(self, page):
NOTE: this returns just PagePermission instances, to get complete access
list merge return of this function with Global permissions.
"""
+ # permissions should be managed on the draft page only
+ page = page.get_draft_object()
from cms.models import ACCESS_DESCENDANTS, ACCESS_CHILDREN,\
ACCESS_PAGE_AND_CHILDREN, ACCESS_PAGE_AND_DESCENDANTS
# code taken from
@@ -416,14 +417,6 @@ def get_move_page_id_list(self, user, site):
"""
return self.__get_id_list(user, site, "can_move_page")
- def get_moderate_id_list(self, user, site):
- """Give a list of pages which user can moderate. If moderation isn't
- installed, nobody can moderate.
- """
- if not settings.CMS_MODERATOR:
- return []
- return self.__get_id_list(user, site, "can_moderate")
-
def get_view_id_list(self, user, site):
"""Give a list of pages which user can view.
"""
View
2  cms/models/metaclasses.py
@@ -9,8 +9,6 @@
class PageMetaClass(MPTTModelBase):
def __new__(cls, name, bases, attrs):
super_new = super(PageMetaClass, cls).__new__
- if not settings.CMS_MODERATOR:
- return super_new(cls, name, bases, attrs)
if 'objects' in attrs:
if not isinstance(attrs['objects'], PublisherManager):
View
97 cms/models/pagemodel.py
@@ -69,7 +69,7 @@ class Page(MPTTModel):
template = models.CharField(_("template"), max_length=100, choices=template_choices, help_text=_('The template used to render the content.'))
site = models.ForeignKey(Site, help_text=_('The site the page is accessible at.'), verbose_name=_("site"))
- moderator_state = models.SmallIntegerField(_('moderator state'), choices=moderator_state_choices, default=MODERATOR_NEED_APPROVEMENT, blank=True)
+ moderator_state = models.SmallIntegerField(_('moderator state'), choices=moderator_state_choices, default=MODERATOR_NEED_APPROVEMENT, blank=True, editable=False)
level = models.PositiveIntegerField(db_index=True, editable=False)
lft = models.PositiveIntegerField(db_index=True, editable=False)
@@ -85,6 +85,7 @@ class Page(MPTTModel):
# Publisher fields
publisher_is_draft = models.BooleanField(default=1, editable=False, db_index=True)
+ #This is misnamed - the one-to-one relation is populated on both ends
publisher_public = models.OneToOneField('self', related_name='publisher_draft', null=True, editable=False)
publisher_state = models.SmallIntegerField(default=0, editable=False, db_index=True)
@@ -111,7 +112,7 @@ def __unicode__(self):
title = self.get_menu_title(fallback=True)
if title is None:
title = u""
- return u'%s' % (title,)
+ return unicode(title)
def get_absolute_url(self, language=None, fallback=True):
if self.is_home():
@@ -133,6 +134,7 @@ def move_page(self, target, position='first-child'):
as it remains the same regardless of the page position in the tree
"""
# make sure move_page does not break when using INHERIT template
+ # and moving to a top level position
if (position in ('left', 'right')
and not target.parent
and self.template == settings.CMS_TEMPLATE_INHERITANCE_MAGIC):
@@ -150,8 +152,7 @@ def move_page(self, target, position='first-child'):
page_utils.check_title_slugs(self)
def copy_page(self, target, site, position='first-child',
- copy_permissions=True, copy_moderation=True,
- public_copy=False):
+ copy_permissions=True, public_copy=False):
"""
Copy a page [ and all its descendants to a new location ]
Doesn't checks for add page permissions anymore, this is done in PageAdmin.
@@ -242,25 +243,20 @@ def copy_page(self, target, site, position='first-child',
# code taken from Publisher publish() overridden here as we need to save the page
# before we are able to use the page object for titles, placeholders etc.. below
# the method has been modified to return the object after saving the instance variable
+
page = self._publisher_save_public(page)
page_copy = page # create a copy used in the return
else:
# only need to save the page if it isn't public since it is saved above otherwise
page.save()
- # copy moderation, permissions if necessary
+ # copy permissions if necessary
if settings.CMS_PERMISSION and copy_permissions:
from cms.models.permissionmodels import PagePermission
for permission in PagePermission.objects.filter(page__id=origin_id):
permission.pk = None
permission.page = page
permission.save()
- if settings.CMS_MODERATOR and copy_moderation:
- from cms.models.moderatormodels import PageModerator
- for moderator in PageModerator.objects.filter(page__id=origin_id):
- moderator.pk = None
- moderator.page = page
- moderator.save()
# update moderation message for standard copy
if not public_copy:
@@ -313,15 +309,12 @@ def save(self, no_signals=False, change_state=True, commit=True,
if hasattr(self, '_template_cache'):
delattr(self, '_template_cache')
+ created = not bool(self.pk)
# Published pages should always have a publication date
- publish_directly, under_moderation = False, False
if self.publisher_is_draft:
# publisher specific stuff, but only on draft model, this is here
# because page initializes publish process
- under_moderation = force_with_moderation or self.pk and bool(self.get_moderator_queryset().count())
-
- created = not bool(self.pk)
if change_state:
if created:
# new page....
@@ -330,11 +323,6 @@ def save(self, no_signals=False, change_state=True, commit=True,
# always change state to need approvement when there is some change
self.moderator_state = Page.MODERATOR_NEED_APPROVEMENT
- if not under_moderation and (self.published or self.publisher_public):
- # existing page without moderator - publish it directly if
- # published is True
- publish_directly = True
-
elif change_state:
self.moderator_state = Page.MODERATOR_CHANGED
#publish_directly = True - no publisher, no publishing!! - we just
@@ -356,7 +344,7 @@ def save(self, no_signals=False, change_state=True, commit=True,
self.changed_by = user.username
else:
self.changed_by = "script"
- if not self.pk:
+ if created:
self.created_by = self.changed_by
if commit:
@@ -365,13 +353,6 @@ def save(self, no_signals=False, change_state=True, commit=True,
else:
super(Page, self).save(**kwargs)
- #if commit and (publish_directly or created and not under_moderation):
- #if self.publisher_is_draft:
- # if self.published:
- # if commit and publish_directly:
-
- # self.publish()
-
def save_base(self, *args, **kwargs):
"""Overridden save_base. If an instance is draft, and was changed, mark
it as dirty.
@@ -400,6 +381,7 @@ def publish(self):
"""
# Publish can only be called on draft pages
if not self.publisher_is_draft:
+ # TODO: Issue a warning
return
# publish, but only if all parents are published!!
@@ -419,12 +401,15 @@ def publish(self):
old_public.publisher_state = self.PUBLISHER_STATE_DELETE
# store old public on self, pass around instead
self.old_public = old_public
- old_public.publisher_public = None # remove the reference to the publisher_draft version of the page so it does not get deleted
+ # remove the one-to-one references between public and draft
+ old_public.publisher_public = None
old_public.save()
+ #self.publisher_public = None
+ #self.save()
# we hook into the modified copy_page routing to do the heavy lifting of copying the draft page to a new public page
new_public = self.copy_page(target=None, site=self.site,
- copy_moderation=False, position=None,
+ position=None,
copy_permissions=False, public_copy=True)
# taken from Publisher - copy_page needs to call self._publisher_save_public(copy) for mptt insertion
@@ -445,6 +430,10 @@ def publish(self):
self.moderator_state = Page.MODERATOR_APPROVED_WAITING_FOR_PARENTS
self.save(change_state=False)
+ # If we are publishing, this page might have become a "home" which
+ # would change the path
+ for title in self.title_set.all():
+ title.save()
if not published:
# was not published, escape
@@ -482,6 +471,15 @@ def publish(self):
return published
+ def revert(self):
+ """Revert the draft version to the same state as the public version
+ """
+ # Revert can only be called on draft pages
+ if not self.publisher_is_draft:
+ # TODO: Issue a warning
+ return
+ # TO BE IMPLEMENTED
+
def delete(self):
"""Mark public instance for deletion and delete draft.
"""
@@ -513,9 +511,13 @@ def delete_with_public(self):
super(Page, self).delete()
def get_draft_object(self):
+ if not self.publisher_is_draft:
+ return self.publisher_draft
return self
def get_public_object(self):
+ if not self.publisher_is_draft:
+ return self
return self.publisher_public
def get_languages(self):
@@ -541,6 +543,8 @@ def get_cached_ancestors(self, ascending=True):
self.ancestors_descending = list(self.get_ancestors(ascending))
return self.ancestors_descending
+ ### Title object access
+
def get_title_obj(self, language=None, fallback=True, version_id=None, force_reload=False):
"""Helper function for accessing wanted / current title.
If wanted title doesn't exists, EmptyTitle instance will be returned.
@@ -759,6 +763,7 @@ def has_delete_permission(self, request):
def has_publish_permission(self, request):
return self.has_generic_permission(request, "publish")
+ has_moderate_permission = has_publish_permission
def has_advanced_settings_permission(self, request):
return self.has_generic_permission(request, "advanced_settings")
@@ -780,15 +785,6 @@ def has_move_page_permission(self, request):
"""
return self.has_generic_permission(request, "move_page")
- def has_moderate_permission(self, request):
- """
- Has user ability to moderate current page? If moderation isn't
- installed, nobody can moderate.
- """
- if not settings.CMS_MODERATOR:
- return False
- return self.has_generic_permission(request, "moderate")
-
def has_generic_permission(self, request, perm_type):
"""
Return true if the current user has permission on the page.
@@ -844,19 +840,17 @@ def last_page_states(self):
query only if some states available
"""
# TODO: optimize SQL... 1 query per page
- if settings.CMS_MODERATOR:
- has_moderator_state = getattr(self, '_has_moderator_state_cache', None)
- if has_moderator_state == False:
- return self.pagemoderatorstate_set.none()
- return self.pagemoderatorstate_set.all().order_by('created',)[:5]
- return self.pagemoderatorstate_set.none()
+ has_moderator_state = getattr(self, '_has_moderator_state_cache', None)
+ if has_moderator_state == False:
+ return self.pagemoderatorstate_set.none()
+ return self.pagemoderatorstate_set.all().order_by('created',)[:5]
def get_moderator_queryset(self):
"""Returns ordered set of all PageModerator instances, which should
moderate this page
"""
from cms.models.moderatormodels import PageModerator
- if not settings.CMS_MODERATOR or not self.tree_id:
+ if not self.tree_id:
return PageModerator.objects.get_empty_query_set()
query = Q(page__tree_id=self.tree_id, page__level__lt=self.level, moderate_descendants=True) | \
Q(page__tree_id=self.tree_id, page__level=self.level - 1, moderate_children=True) | \
@@ -876,14 +870,9 @@ def is_approved(self):
def is_public_published(self):
"""Returns true if public model is published.
"""
- if hasattr(self, 'public_published_cache'):
- # if it was cached in change list, return cached value
- return self.public_published_cache
- # othervise make db lookup
- if self.publisher_public_id:
- return self.publisher_public.published
- #return is_public_published(self)
- return False
+ # If we have a public version it will be published as well.
+ # If it isn't published, it should be deleted.
+ return bool(self.publisher_public_id)
def reload(self):
"""
View
1  cms/models/permissionmodels.py
@@ -25,7 +25,6 @@ class AbstractPagePermission(models.Model):
can_publish = models.BooleanField(_("can publish"), default=True)
can_change_permissions = models.BooleanField(_("can change permissions"), default=False, help_text=_("on page level"))
can_move_page = models.BooleanField(_("can move"), default=True)
- can_moderate = models.BooleanField(_("can moderate"), default=True)
can_view = models.BooleanField(_("view restricted"), default=False, help_text=_("frontend view restriction"))
class Meta:
View
2  cms/models/query.py
@@ -6,8 +6,6 @@
from django.conf import settings
from cms.exceptions import NoHomeFound
-#from cms.utils.urlutils import levelize_path
-
class PageQuerySet(PublisherQuerySet):
def on_site(self, site=None):
View
2  cms/plugins/inherit/cms_plugins.py
@@ -36,7 +36,7 @@ def render(self, context, instance, placeholder):
page = instance.from_page
else:
page = instance.page
- if settings.CMS_MODERATOR and not instance.page.publisher_is_draft and page.publisher_is_draft:
+ if not instance.page.publisher_is_draft and page.publisher_is_draft:
page = page.publisher_public
plugins = get_cmsplugin_queryset(request).filter(
View
2  cms/sitemaps/cms_sitemap.py
@@ -14,7 +14,7 @@ class CMSSitemap(Sitemap):
priority = 0.5
def items(self):
- from cms.utils.moderator import get_page_queryset
+ from cms.utils.page_resolver import get_page_queryset
page_queryset = get_page_queryset(None)
all_pages = page_queryset.published().filter(login_required=False)
return all_pages
View
8 cms/templates/admin/cms/page/change_form.html
@@ -75,13 +75,7 @@ <h1 class="moderation-approve-deletion">{% trans "Approve page deletion" %}</h1>
{% else %}
- <h1>{{ title }}
- {% if CMS_MODERATOR %}
- {% if moderation_required %}<span class="moderation-requires-approvement">{% blocktrans %}(requires approvement at {{ moderation_level }} level){% endblocktrans %}</span>
- {% else %}<span>{% trans '(you can perform actions on this page directly)' %}</span>
- {% endif %}
- {% endif %}
- </h1>
+ <h1>{{ title }}</h1>
{% endif %}
{% endblock %}
View
2  cms/templatetags/cms_admin.py
@@ -117,7 +117,7 @@ def get_context(self, context, cl, spec):
@register.filter
def boolean_icon(value):
BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'}
- return mark_safe(u'<img src="%sicon-%s.gif" alt="%s" />' % (CMS_ADMIN_ICON_BASE, BOOLEAN_MAPPING[value], value))
+ return mark_safe(u'<img src="%sicon-%s.gif" alt="%s" />' % (CMS_ADMIN_ICON_BASE, BOOLEAN_MAPPING.get(value, 'unknown'), value))
@register.filter
def is_restricted(page, request):
View
2  cms/templatetags/cms_tags.py
@@ -7,7 +7,7 @@
from cms.plugin_rendering import render_plugins, render_placeholder
from cms.plugins.utils import get_plugins, assign_plugins
from cms.utils import get_language_from_request
-from cms.utils.moderator import get_cmsplugin_queryset, get_page_queryset
+from cms.utils.page_resolver import get_page_queryset
from cms.utils.placeholder import validate_placeholder_name
from django import template
from django.conf import settings
View
1  cms/test_utils/cli.py
@@ -184,7 +184,6 @@ def configure(**extra):
},
},
CMS_SOFTROOT = True,
- CMS_MODERATOR = True,
CMS_PERMISSION = True,
CMS_PUBLIC_FOR = 'all',
CMS_CACHE_DURATIONS = {
View
6 cms/test_utils/fixtures/menus.py
@@ -23,7 +23,7 @@ def create_fixtures(self):
'template': 'nav_playground.html',
'language': 'en',
}
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
p1 = create_page('P1', published=True, in_navigation=True, **defaults)
p4 = create_page('P4', published=True, in_navigation=True, **defaults)
p6 = create_page('P6', published=True, in_navigation=False, **defaults)
@@ -56,7 +56,7 @@ def create_fixtures(self):
'template': 'nav_playground.html',
'language': 'en',
}
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
p1 = create_page('P1', published=True, in_navigation=True, **defaults)
p4 = create_page('P4', published=True, in_navigation=True, **defaults)
p6 = create_page('P6', published=True, in_navigation=True, **defaults)
@@ -93,7 +93,7 @@ def create_fixtures(self):
'in_navigation': True,
'published': True,
}
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
top = create_page('top', **defaults)
root = create_page('root', parent=top, **defaults)
aaa = create_page('aaa', parent=root, **defaults)
View
2  cms/test_utils/fixtures/navextenders.py
@@ -20,7 +20,7 @@ def create_fixtures(self):
'template': 'nav_playground.html',
'language': 'en',
}
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
p1 = create_page('page1', published=True, in_navigation=True, **defaults)
p4 = create_page('page4', published=True, in_navigation=True, **defaults)
p1 = Page.objects.get(pk=p1.pk)
View
2  cms/test_utils/fixtures/templatetags.py
@@ -11,7 +11,7 @@ def create_fixtures(self):
'published': True,
'in_navigation': True,
}
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
first = create_page('first', language='en', **defaults)
create_title('de', 'erste', first)
second = create_page('second', language='en', reverse_id='myreverseid', **defaults)
View
86 cms/tests/admin.py
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
from cms.admin.change_list import CMSChangeList
-from cms.admin.dialog.forms import (ModeratorForm, PermissionForm,
- PermissionAndModeratorForm)
-from cms.admin.dialog.views import _form_class_selector
+from cms.admin.dialog.forms import PermissionForm
from cms.admin.forms import PageForm
from cms.admin.pageadmin import contribute_fieldsets, contribute_list_filter
from cms.api import create_page, create_title, add_plugin
@@ -66,7 +64,6 @@ def _get_guys(self, admin_only=False):
can_publish=True,
can_change_permissions=False,
can_move_page=True,
- can_moderate=True,
)
gpp.sites = Site.objects.all()
return admin, normal_guy
@@ -253,28 +250,10 @@ def test_delete(self):
data = {'post': 'yes'}
response = self.client.post(URL_CMS_PAGE_DELETE % page.pk, data)
self.assertRedirects(response, URL_CMS_PAGE)
- self.assertRaises(Page.DoesNotExist, self.reload, page)
- self.assertRaises(Page.DoesNotExist, self.reload, child)
-
- def test_admin_dialog_form_no_moderation_or_permissions(self):
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
- result = _form_class_selector()
- self.assertEqual(result, None)
-
- def test_admin_dialog_form_permission_only(self):
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=True):
- result = _form_class_selector()
- self.assertEqual(result, PermissionForm)
-
- def test_admin_dialog_form_moderation_only(self):
- with SettingsOverride(CMS_MODERATOR=True, CMS_PERMISSION=False):
- result = _form_class_selector()
- self.assertEqual(result, ModeratorForm)
-
- def test_admin_dialog_form_moderation_and_permisison(self):
- with SettingsOverride(CMS_MODERATOR=True, CMS_PERMISSION=True):
- result = _form_class_selector()
- self.assertEqual(result, PermissionAndModeratorForm)
+ # TODO - The page should be marked for deletion, but nothing more
+ # until publishing
+ #self.assertRaises(Page.DoesNotExist, self.reload, page)
+ #self.assertRaises(Page.DoesNotExist, self.reload, child)
def test_search_fields(self):
superuser = self._get_guys(admin_only=True)
@@ -416,16 +395,10 @@ def validate_attributes(self, a, b, ignore=None):
self.assertEqual(a_attr, b_attr)
def test_no_moderator(self):
- with SettingsOverride(CMS_MODERATOR=True):
- control = AttributeObject()
- contribute_fieldsets(control)
- with SettingsOverride(CMS_MODERATOR=False):
- nomod = AttributeObject()
- contribute_fieldsets(nomod)
- self.validate_attributes(control, nomod, ['fieldsets', 'additional_hidden_fields'])
- self.assertEqual(control.additional_hidden_fields, ['moderator_state', 'moderator_message'])
- self.assertEqual(nomod.additional_hidden_fields, [])
-
+ control = AttributeObject()
+ contribute_fieldsets(control)
+ self.assertEqual(control.additional_hidden_fields, [])
+
def test_no_menu_title_overwrite(self):
with SettingsOverride(CMS_MENU_TITLE_OVERWRITE=True):
control = AttributeObject()
@@ -541,15 +514,10 @@ def func_false(self):
class AdminListFilterTests(TestCase):
def test_no_moderator(self):
- with SettingsOverride(CMS_MODERATOR=True):
- control = AttributeObject()
- contribute_list_filter(control)
- with SettingsOverride(CMS_MODERATOR=False):
- experiment = AttributeObject()
- contribute_list_filter(experiment)
- self.assertTrue('moderator_state' in control.list_filter, control.list_filter)
- self.assertFalse('moderator_state' in experiment.list_filter, experiment.list_filter)
-
+ control = AttributeObject()
+ contribute_list_filter(control)
+ #self.assertTrue('moderator_state' in control.list_filter, control.list_filter)
+
def test_no_softroot(self):
with SettingsOverride(CMS_SOFTROOT=True):
control = AttributeObject()
@@ -589,8 +557,8 @@ def test_get_moderation_state(self):
admin = self.get_admin()
with self.login_user_context(permless):
request = self.get_request()
- self.assertRaises(Http404, self.admin_class.get_moderation_states,
- request, page.pk)
+ response = self.admin_class.get_moderation_states(request, page.pk)
+ self.assertEqual(response.status_code, 200)
with self.login_user_context(admin):
request = self.get_request()
response = self.admin_class.get_moderation_states(request, page.pk)
@@ -679,13 +647,6 @@ def test_change_moderation(self):
self.assertRaises(Http404, self.admin_class.change_moderation,
request, page.pk)
- def test_approve_page_requires_perms(self):
- permless = self.get_permless()
- with self.login_user_context(permless):
- request = self.get_request()
- self.assertRaises(Http404, self.admin_class.approve_page,
- request, 1)
-
def test_publish_page_requires_perms(self):
permless = self.get_permless()
with self.login_user_context(permless):
@@ -793,7 +754,7 @@ def test_too_many_plugins_global(self):
}
admin = self.get_admin()
url = reverse('admin:cms_page_add_plugin')
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False,
+ with SettingsOverride(CMS_PERMISSION=False,
CMS_PLACEHOLDER_CONF=conf):
page = create_page('somepage', 'nav_playground.html', 'en')
body = page.placeholders.get(slot='body')
@@ -817,7 +778,7 @@ def test_too_many_plugins_type(self):
}
admin = self.get_admin()
url = reverse('admin:cms_page_add_plugin')
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False,
+ with SettingsOverride(CMS_PERMISSION=False,
CMS_PLACEHOLDER_CONF=conf):
page = create_page('somepage', 'nav_playground.html', 'en')
body = page.placeholders.get(slot='body')
@@ -882,7 +843,6 @@ def _give_cms_permissions(self, user, save=True):
can_publish=True,
can_change_permissions=False,
can_move_page=True,
- can_moderate=True,
)
gpp.sites = Site.objects.all()
if save:
@@ -980,7 +940,7 @@ def test_clean_overwrite_url(self):
user.is_superuser = True
user.pk = 1
request = type('Request', (object,), {'user': user})
- with SettingsOverride(CMS_MODERATOR=False):
+ with SettingsOverride():
data = {
'title': 'TestPage',
'slug': 'test-page',
@@ -1018,14 +978,14 @@ def test_reverse_id_error_location(self):
'reverse_id': dupe_id,
}
form = PageForm(data=page2_data, files=None)
- self.assertTrue(not form.is_valid())
+ self.assertFalse(form.is_valid())
# reverse_id is the only item that is in __all__ as every other field
# has it's own clean method. Moving it to be a field error means
# __all__ is now not available.
- self.assertTrue('__all__' not in form.errors)
+ self.assertNotIn('__all__', form.errors)
# In moving it to it's own field, it should be in form.errors, and
# the values contained therein should match these.
- self.assertTrue('reverse_id' in form.errors)
+ self.assertIn('reverse_id', form.errors)
self.assertEqual(1, len(form.errors['reverse_id']))
self.assertEqual([u'A page with this reverse URL id exists already.'],
form.errors['reverse_id'])
@@ -1050,7 +1010,7 @@ def test_reverse_id_error_location(self):
# reverse_id form row has an errors class. Django's admin avoids
# collapsing these, so that the error is visible.
resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page2.pk, page2_data)
- self.assertTrue('<div class="form-row errors reverse_id">' in resp.content)
+ self.assertContains(resp, '<div class="form-row errors reverse_id">')
class AdminPageEditContentSizeTests(AdminTestsBase):
@@ -1067,7 +1027,7 @@ def test_editpage_contentsize(self):
Expected a username only 2 times in the content, but a relationship
between usercount and pagesize
"""
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=True):
+ with SettingsOverride(CMS_PERMISSION=True):
admin = self.get_superuser()
PAGE_NAME = 'TestPage'
USER_NAME = 'test_size_user_0'
View
77 cms/tests/apphooks.py
@@ -4,7 +4,7 @@
from cms.apphook_pool import apphook_pool
from cms.appresolver import (applications_page_check, clear_app_resolvers,
get_app_patterns)
-from cms.test_utils.testcases import CMSTestCase
+from cms.test_utils.testcases import CMSTestCase, SettingsOverrideTestCase
from cms.test_utils.util.context_managers import SettingsOverride
from cms.tests.menu_utils import DumbPageLanguageUrl
from cms.utils.i18n import force_language
@@ -291,7 +291,7 @@ def test_include_urlconf(self):
apphook_pool.clear()
def test_apphook_breaking_under_home_with_new_path_caching(self):
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
home = create_page("home", "nav_playground.html", "en", published=True)
child = create_page("child", "nav_playground.html", "en", published=True, parent=home)
# not-home is what breaks stuff, because it contains the slug of the home page
@@ -305,7 +305,9 @@ def test_apphook_breaking_under_home_with_new_path_caching(self):
self.assertEqual(url, 'child/not-home/subchild/')
-class ApphooksPageLanguageUrlTestCase(CMSTestCase):
+class ApphooksPageLanguageUrlTestCase(SettingsOverrideTestCase):
+
+ settings_overrides = {'ROOT_URLCONF': 'cms.test_utils.project.second_urls_for_apphook_tests'}
def setUp(self):
clear_app_resolvers()
@@ -323,47 +325,46 @@ def tearDown(self):
def test_page_language_url_for_apphook(self):
- with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
+ apphook_pool.clear()
+ superuser = User.objects.create_superuser('admin', 'admin@admin.com', 'admin')
+ page = create_page("home", "nav_playground.html", "en",
+ created_by=superuser)
+ create_title('de', page.get_title(), page)
+ page.publish()
- apphook_pool.clear()
- superuser = User.objects.create_superuser('admin', 'admin@admin.com', 'admin')
- page = create_page("home", "nav_playground.html", "en",
- created_by=superuser, published=True)
- create_title('de', page.get_title(), page)
- child_page = create_page("child_page", "nav_playground.html", "en",
- created_by=superuser, published=True, parent=page)
- create_title('de', child_page.get_title(), child_page)
- child_child_page = create_page("child_child_page", "nav_playground.html",
- "en", created_by=superuser, published=True, parent=child_page, apphook='SampleApp')
- create_title("de", '%s_de' % child_child_page.get_title(), child_child_page, apphook='SampleApp')
-
- child_page.publish()
- child_child_page.publish()
- # publisher_public is set to draft on publish, issue with onetoone reverse
- child_child_page = self.reload(child_child_page)
- with force_language("en"):
- path = reverse('extra_first')
+ child_page = create_page("child_page", "nav_playground.html", "en",
+ created_by=superuser, parent=page)
+ create_title('de', child_page.get_title(), child_page)
+ child_page.publish()
- request = self.get_request(path)
- request.LANGUAGE_CODE = 'en'
- request.current_page = child_child_page
+ child_child_page = create_page("child_child_page", "nav_playground.html",
+ "en", created_by=superuser, parent=child_page, apphook='SampleApp')
+ create_title("de", '%s_de' % child_child_page.get_title(), child_child_page, apphook='SampleApp')
+ child_child_page.publish()
- fake_context = {'request': request}
- tag = DumbPageLanguageUrl()
+ # publisher_public is set to draft on publish, issue with onetoone reverse
+ child_child_page = self.reload(child_child_page)
+ with force_language("en"):
+ path = reverse('extra_first')
- output = tag.get_context(fake_context, 'en')
- url = output['content']
- self.assertEqual(url, '/en/child_page/child_child_page/extra_1/')
+ request = self.get_request(path)
+ request.LANGUAGE_CODE = 'en'
+ request.current_page = child_child_page
+ fake_context = {'request': request}
+ tag = DumbPageLanguageUrl()
+ output = tag.get_context(fake_context, 'en')
+ url = output['content']
+ self.assertEqual(url, '/en/child_page/child_child_page/extra_1/')
- output = tag.get_context(fake_context, 'de')
- url = output['content']
- # look the extra "_de"
- self.assertEqual(url, '/de/child_page/child_child_page_de/extra_1/')
+ output = tag.get_context(fake_context, 'de')
+ url = output['content']
+ # look the extra "_de"
+ self.assertEqual(url, '/de/child_page/child_child_page_de/extra_1/')
- output = tag.get_context(fake_context, 'fr')
- url = output['content']
- self.assertEqual(url, '/fr/child_page/child_child_page/extra_1/')
+ output = tag.get_context(fake_context, 'fr')
+ url = output['content']
+ self.assertEqual(url, '/fr/child_page/child_child_page/extra_1/')
- apphook_pool.clear()
+ apphook_pool.clear()
View
59 cms/tests/forms.py
@@ -33,22 +33,20 @@ def test_get_page_choices(self):
self.assertEquals(result, [('', '----')])
def test_get_site_choices_without_moderator(self):
- with SettingsOverride(CMS_MODERATOR=False):
- result = get_site_choices()
- self.assertEquals(result, [])
+ result = get_site_choices()
+ self.assertEquals(result, [])
def test_get_site_choices_without_moderator_with_superuser(self):
- with SettingsOverride(CMS_MODERATOR=False):
- # boilerplate (creating a page)
- user_super = User(username="super", is_staff=True, is_active=True,
- is_superuser=True)
- user_super.set_password("super")
- user_super.save()
- with self.login_user_context(user_super):
- create_page("home", "nav_playground.html", "en", created_by=user_super)
- # The proper test
- result = get_site_choices()
- self.assertEquals(result, [(1,'example.com')])
+ # boilerplate (creating a page)
+ user_super = User(username="super", is_staff=True, is_active=True,
+ is_superuser=True)
+ user_super.set_password("super")
+ user_super.save()
+ with self.login_user_context(user_super):
+ create_page("home", "nav_playground.html", "en", created_by=user_super)
+ # The proper test
+ result = get_site_choices()
+ self.assertEquals(result, [(1,'example.com')])
def test_compress_function_raises_when_page_is_none(self):
raised = False
@@ -88,24 +86,23 @@ def test_compress_function_gets_a_page_when_one_exists(self):
self.assertEquals(home_page,result)
def test_update_site_and_page_choices(self):
- with SettingsOverride(CMS_MODERATOR=False):
- Site.objects.all().delete()
- site = Site.objects.create(domain='http://www.django-cms.org', name='Django CMS')
- page1 = create_page('Page 1', 'nav_playground.html', 'en', site=site)
- page2 = create_page('Page 2', 'nav_playground.html', 'de', site=site)
- page3 = create_page('Page 3', 'nav_playground.html', 'en',
- site=site, parent=page1)
- # enfore the choices to be casted to a list
- site_choices, page_choices = [list(bit) for bit in update_site_and_page_choices('en')]
- self.assertEqual(page_choices, [
- ('', '----'),
- (site.name, [
- (page1.pk, 'Page 1'),
- (page3.pk, '&nbsp;&nbsp;Page 3'),
- (page2.pk, 'Page 2'),
- ])
+ Site.objects.all().delete()
+ site = Site.objects.create(domain='http://www.django-cms.org', name='Django CMS')
+ page1 = create_page('Page 1', 'nav_playground.html', 'en', site=site)
+ page2 = create_page('Page 2', 'nav_playground.html', 'de', site=site)
+ page3 = create_page('Page 3', 'nav_playground.html', 'en',
+ site=site, parent=page1)
+ # enforce the choices to be casted to a list
+ site_choices, page_choices = [list(bit) for bit in update_site_and_page_choices('en')]
+ self.assertEqual(page_choices, [
+ ('', '----'),
+ (site.name, [
+ (page1.pk, 'Page 1'),
+ (page3.pk, '&nbsp;&nbsp;Page 3'),
+ (page2.pk, 'Page 2'),
])
- self.assertEqual(site_choices, [(site.pk, site.name)])
+ ])
+ self.assertEqual(site_choices, [(site.pk, site.name)])
def test_superlazy_iterator_behaves_properly_for_sites(self):
View
8 cms/tests/menu.py
@@ -25,10 +25,7 @@
class BaseMenuTest(SettingsOverrideTestCase):
- settings_overrides = {
- 'CMS_MODERATOR': False,
- }
-
+
def _get_nodes(self, path='/'):
node1 = NavigationNode('1', '/1/', 1)
node2 = NavigationNode('2', '/2/', 2, 1)
@@ -538,7 +535,6 @@ class AdvancedSoftrootTests(SoftrootFixture, SettingsOverrideTestCase):
If we are above that page, the children of this page are not shown.
"""
settings_overrides = {
- 'CMS_MODERATOR': False,
'CMS_PERMISSION': False
}
@@ -781,7 +777,6 @@ def test_not_in_navigation_num_queries(self):
class ViewPermissionMenuTests(SettingsOverrideTestCase):
settings_overrides = {
- 'CMS_MODERATOR': False,
'CMS_PERMISSION': True,
'CMS_PUBLIC_FOR': 'all',
}
@@ -1127,7 +1122,6 @@ class SoftrootTests(SettingsOverrideTestCase):
Instruments
"""
settings_overrides = {
- 'CMS_MODERATOR': False,
'CMS_SOFTROOT': True,
'CMS_PERMISSION': False
}
View
2  cms/tests/menu_page_viewperm.py
@@ -226,7 +226,6 @@ class ViewPermissionComplexMenuAllNodesTests(ViewPermissionTests):
Test CMS_PUBLIC_FOR=all group access and menu nodes rendering
"""
settings_overrides = {
- 'CMS_MODERATOR': False,
'CMS_PERMISSION': True,
'CMS_PUBLIC_FOR': 'all',
}
@@ -419,7 +418,6 @@ class ViewPermissionTreeBugTests(ViewPermissionTests):
Test if this affects the menu entries and page visibility
"""
settings_overrides = {
- 'CMS_MODERATOR': False,
'CMS_PERMISSION': True,
'CMS_PUBLIC_FOR': 'all',
}
View
1  cms/tests/menu_page_viewperm_staff.py
@@ -11,7 +11,6 @@ class ViewPermissionComplexMenuStaffNodeTests(ViewPermissionTests):
Test CMS_PUBLIC_FOR=staff group access and menu nodes rendering
"""
settings_overrides = {
- 'CMS_MODERATOR': False,
'CMS_PERMISSION': True,
'CMS_PUBLIC_FOR': 'staff',
}
View
3  cms/tests/multilingual.py
@@ -17,7 +17,6 @@ class MultilingualTestCase(SettingsOverrideTestCase):
settings_overrides = {
'CMS_TEMPLATES': [(TEMPLATE_NAME, TEMPLATE_NAME), ('extra_context.html', 'extra_context.html'),
('nav_playground.html', 'nav_playground.html')],
- 'CMS_MODERATOR': False,
}
@@ -32,7 +31,7 @@ def test_multilingual_page(self):
self.assertEqual(placeholder.cmsplugin_set.filter(language='de').count(), 1)
self.assertEqual(placeholder.cmsplugin_set.filter(language='en').count(), 1)
user = User.objects.create_superuser('super', 'super@django-cms.org', 'super')
- page = publish_page(page, user, True)
+ page = publish_page(page, user)
public = page.publisher_public
placeholder = public.placeholders.all()[0]
self.assertEqual(placeholder.cmsplugin_set.filter(language='de').count(), 1)
View
3  cms/tests/navextender.py
@@ -9,8 +9,7 @@
from menus.menu_pool import menu_pool
class NavExtenderTestCase(NavextendersFixture, SettingsOverrideTestCase):
- settings_overrides = {'CMS_MODERATOR': False}
-
+
"""
Tree from fixture:
View
6 cms/tests/nested_plugins.py
@@ -20,7 +20,7 @@ def test_nested_plugin_on_page(self):
mptt values are correctly showing a parent child relationship
of a nested plugin
"""
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
# setup page 1
page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
position=u"last-child", published=True, in_navigation=True)
@@ -83,7 +83,7 @@ def test_copy_page_nested_plugin(self):
page two (copy target)
Verify copied page, placeholders, plugins and body text
"""
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
templates = []
# setup page 1
page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
@@ -291,7 +291,7 @@ def test_copy_page_nested_plugin_moved_parent_plugin(self):
col_right: 1 text plugin with nested link plugin
verify the copied page structure
"""
- with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
+ with SettingsOverride(CMS_PERMISSION=False):
templates = []
# setup page 1
page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
View
50 cms/tests/nonroot.py
@@ -17,12 +17,11 @@ class NonRootCase(CMSTestCase):
urls = 'cms.test_utils.project.nonroot_urls'
def setUp(self):
- with SettingsOverride(CMS_MODERATOR = False):
- u = User(username="test", is_staff = True, is_active = True, is_superuser = True)
- u.set_password("test")
- u.save()
- with self.login_user_context(u):
- self.create_some_pages()
+ u = User(username="test", is_staff = True, is_active = True, is_superuser = True)
+ u.set_password("test")
+ u.save()
+ with self.login_user_context(u):
+ self.create_some_pages()
def create_some_pages(self):
"""
@@ -51,31 +50,28 @@ def test_get_page_root(self):
self.assertEqual(self.get_pages_root(), '/en/content/')
def test_basic_cms_menu(self):
- with SettingsOverride(CMS_MODERATOR = False):
- response = self.client.get(self.get_pages_root())
- self.assertEquals(response.status_code, 200)
- self.assertEquals(self.get_pages_root(), "/en/content/")
+ response = self.client.get(self.get_pages_root())
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(self.get_pages_root(), "/en/content/")
def test_show_menu(self):
- with SettingsOverride(CMS_MODERATOR = False):
- context = self.get_context()
- tpl = Template("{% load menu_tags %}{% show_menu %}")
- tpl.render(context)
- nodes = context['children']
- self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
- self.assertEqual(nodes[0].get_absolute_url(), "/en/content/")
+ context = self.get_context()
+ tpl = Template("{% load menu_tags %}{% show_menu %}")
+ tpl.render(context)
+ nodes = context['children']
+ self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
+ self.assertEqual(nodes[0].get_absolute_url(), "/en/content/")
def test_show_breadcrumb(self):
- with SettingsOverride(CMS_MODERATOR = False):
- page2 = Page.objects.get(pk=self.page2.pk)
- context = self.get_context(path=self.page2.get_absolute_url())
- tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
- tpl.render(context)
- nodes = context['ancestors']
- self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
- self.assertEqual(nodes[0].get_absolute_url(), "/en/content/")
- self.assertEqual(isinstance(nodes[0], NavigationNode), True)
- self.assertEqual(nodes[1].get_absolute_url(), page2.get_absolute_url())
+ page2 = Page.objects.get(pk=self.page2.pk)
+ context = self.get_context(path=self.page2.get_absolute_url())
+ tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
+ tpl.render(context)
+ nodes = context['ancestors']
+ self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
+ self.assertEqual(nodes[0].get_absolute_url(), "/en/content/")
+ self.assertEqual(isinstance(nodes[0], NavigationNode), True)
+ self.assertEqual(nodes[1].get_absolute_url(), page2.get_absolute_url())
def test_form_multilingual_admin(self):
"""
View
175 cms/tests/page.py
@@ -26,7 +26,6 @@
from cms.utils.page_resolver import get_page_from_request, is_valid_url
from cms.utils.page import is_valid_page_slug
-
class PagesTestCase(CMSTestCase):
def test_add_page(self):
@@ -38,7 +37,7 @@ def test_add_page(self):
response = self.client.get(URL_CMS_PAGE_ADD)
self.assertEqual(response.status_code, 200)
- def test_create_page(self):
+ def test_create_page_admin(self):
"""
Test that a page can be created via the admin
"""
@@ -71,6 +70,24 @@ def test_create_page(self):
title = Title.objects.drafts().get(slug=page_data['slug'])
title = Title.objects.public().get(slug=page_data['slug'])
+ def test_create_page_api(self):
+ page_data = {
+ 'title': 'root',
+ 'slug': 'root',
+ 'language': settings.LANGUAGES[0][0],
+ 'template': 'nav_playground.html',
+ }
+ page = create_page(**page_data)
+
+ self.assertFalse(page.is_home(), "The page should not be marked as "
+ "home before being published")
+ page.publish()
+ assert page.is_home()
+ assert page.publisher_public.is_home()
+
+ self.assertEqual(list(Title.objects.drafts().values_list('path', flat=True)), [u''])
+ self.assertEqual(list(Title.objects.public().values_list('path', flat=True)), [u''])
+
def test_slug_collision(self):
"""
Test a slug collision
@@ -100,51 +117,48 @@ def test_slug_collision(self):
def test_slug_collisions_api_1(self):
""" Checks for slug collisions on sibling pages - uses API to create pages
"""
- with SettingsOverride(CMS_MODERATOR=False):
- page1 = create_page('test page 1', 'nav_playground.html', 'en',
- published=True)
- page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
- published=True, parent=page1, slug="foo")
- page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
- published=True, parent=page1, slug="foo")
- # both sibling pages has same slug, so both pages has an invalid slug
- self.assertFalse(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
- self.assertFalse(is_valid_page_slug(page1_2,page1_2.parent,"en",page1_2.get_slug("en"),page1_2.site))
+ page1 = create_page('test page 1', 'nav_playground.html', 'en',
+ published=True)
+ page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
+ published=True, parent=page1, slug="foo")
+ page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
+ published=True, parent=page1, slug="foo")
+ # both sibling pages has same slug, so both pages has an invalid slug
+ self.assertFalse(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
+ self.assertFalse(is_valid_page_slug(page1_2,page1_2.parent,"en",page1_2.get_slug("en"),page1_2.site))
def test_slug_collisions_api_2(self):
""" Checks for slug collisions on root (not home) page and a home page child - uses API to create pages
"""
- with SettingsOverride(CMS_MODERATOR=False):
- page1 = create_page('test page 1', 'nav_playground.html', 'en',
- published=True)
- page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
- published=True, parent=page1, slug="foo")
- page2 = create_page('test page 1_1', 'nav_playground.html', 'en',
- published=True, slug="foo")
- # Home page child has an invalid slug, while root page is ok. Root wins!
- self.assertFalse(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
- self.assertTrue(is_valid_page_slug(page2,page2.parent,"en",page2.get_slug("en"),page2.site))
+ page1 = create_page('test page 1', 'nav_playground.html', 'en',
+ published=True)
+ page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
+ published=True, parent=page1, slug="foo")
+ page2 = create_page('test page 1_1', 'nav_playground.html', 'en',
+ published=True, slug="foo")
+ # Home page child has an invalid slug, while root page is ok. Root wins!
+ self.assertFalse(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
+ self.assertTrue(is_valid_page_slug(page2,page2.parent,"en",page2.get_slug("en"),page2.site))
def test_slug_collisions_api_3(self):
""" Checks for slug collisions on children of a non root page - uses API to create pages
"""
- with SettingsOverride(CMS_MODERATOR=False):
- page1 = create_page('test page 1', 'nav_playground.html', 'en',
- published=True)
- page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
- published=True, parent=page1, slug="foo")
- page1_1_1 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
- published=True, parent=page1_1, slug="bar")
- page1_1_2 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
- published=True, parent=page1_1, slug="bar")
- page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
- published=True, parent=page1, slug="bar")
- # Direct children of home has different slug so it's ok.
- self.assertTrue(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
- self.assertTrue(is_valid_page_slug(page1_2,page1_2.parent,"en",page1_2.get_slug("en"),page1_2.site))
- # children of page1_1 has the same slug -> you lose!
- self.assertFalse(is_valid_page_slug(page1_1_1,page1_1_1.parent,"en",page1_1_1.get_slug("en"),page1_1_1.site))
- self.assertFalse(is_valid_page_slug(page1_1_2,page1_1_2.parent,"en",page1_1_2.get_slug("en"),page1_1_2.site))
+ page1 = create_page('test page 1', 'nav_playground.html', 'en',
+ published=True)
+ page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
+ published=True, parent=page1, slug="foo")
+ page1_1_1 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
+ published=True, parent=page1_1, slug="bar")
+ page1_1_2 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
+ published=True, parent=page1_1, slug="bar")
+ page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
+ published=True, parent=page1, slug="bar")
+ # Direct children of home has different slug so it's ok.
+ self.assertTrue(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
+ self.assertTrue(is_valid_page_slug(page1_2,page1_2.parent,"en",page1_2.get_slug("en"),page1_2.site))
+ # children of page1_1 has the same slug -> you lose!
+ self.assertFalse(is_valid_page_slug(page1_1_1,page1_1_1.parent,"en",page1_1_1.get_slug("en"),page1_1_1.site))
+ self.assertFalse(is_valid_page_slug(page1_1_2,page1_1_2.parent,"en",page1_1_2.get_slug("en"),page1_1_2.site))
def test_details_view(self):
"""
@@ -187,25 +201,24 @@ def test_moderator_edit_page_redirect(self):
"""
superuser = self.get_superuser()
with self.login_user_context(superuser):
- with SettingsOverride(CMS_MODERATOR=True):
- page_data = self.get_new_page_data()
- response = self.client.post(URL_CMS_PAGE_ADD, page_data)
- self.assertEquals(response.status_code, 302)
- page = Page.objects.get(title_set__slug=page_data['slug'])
- response = self.client.get('/en/admin/cms/page/%s/' %page.id)
- self.assertEqual(response.status_code, 200)
- page_data['overwrite_url'] = '/hello/'
- page_data['has_url_overwrite'] = True
- response = self.client.post('/en/admin/cms/page/%s/' %page.id, page_data)
- self.assertRedirects(response, URL_CMS_PAGE)
- self.assertEqual(page.get_absolute_url(), '/en/hello/')
- title = Title.objects.all()[0]
- page.publish()
- page_data['title'] = 'new title'
- response = self.client.post('/en/admin/cms/page/%s/' %page.id, page_data)
- page = Page.objects.get(title_set__slug=page_data['slug'], publisher_is_draft=True)
- self.assertRedirects(response, URL_CMS_PAGE)
- self.assertEqual(page.get_title(), 'new title')
+ page_data = self.get_new_page_data()
+ response = self.client.post(URL_CMS_PAGE_ADD, page_data)
+ self.assertEquals(response.status_code, 302)
+ page = Page.objects.get(title_set__slug=page_data['slug'])
+ response = self.client.get('/en/admin/cms/page/%s/' %page.id)
+ self.assertEqual(response.status_code, 200)
+ page_data['overwrite_url'] = '/hello/'
+ page_data['has_url_overwrite'] = True
+ response = self.client.post('/en/admin/cms/page/%s/' %page.id, page_data)
+ self.assertRedirects(response, URL_CMS_PAGE)
+ self.assertEqual(page.get_absolute_url(), '/en/hello/')
+ title = Title.objects.all()[0]
+ page.publish()
+ page_data['title'] = 'new title'
+ response = self.client.post('/en/admin/cms/page/%s/' %page.id, page_data)
+ page = Page.objects.get(title_set__slug=page_data['slug'], publisher_is_draft=True)
+ self.assertRedirects(response, URL_CMS_PAGE)
+ self.assertEqual(page.get_title(), 'new title')
def test_meta_description_and_keywords_fields_from_admin(self):
@@ -293,6 +306,7 @@ def test_move_page(self):
page1 = Page.objects.all()[0]
page2 = Page.objects.all()[1]
page3 = Page.objects.all()[2]
+
# move pages
response = self.client.post("/en/admin/cms/page/%s/move-page/" % page3.pk, {"target": page2.pk, "position": "last-child"})
self.assertEqual(response.status_code, 200)
@@ -306,10 +320,11 @@ def test_move_page(self):
page3 = Page.objects.get(pk=