def test_switch_moderator_on(self): with SettingsOverride(CMS_MODERATOR=False): page1 = create_page('page', 'nav_playground.html', 'en', published=True) with SettingsOverride(CMS_MODERATOR=True): call_command('cms', 'moderator', 'on') page2 = get_page_from_path(page1.get_absolute_url().strip('/')) self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
def test_switch_moderator_off(self): with force_language("en"): pages_root = urllib.unquote(reverse("pages-root")) page1 = create_page('page', 'nav_playground.html', 'en', published=True) path = page1.get_absolute_url()[len(pages_root):].strip('/') page2 = get_page_from_path(path) self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
def random_testimonial(context): context['root'] = get_page_from_path('references') if context['root'] and context['root'].children.filter(published=True): context['testimonial'] = context['root'].children.filter( published=True).order_by('?')[0] for p in context['testimonial'].placeholders.all(): context[p.slot] = p return context
def test_switch_moderator_off(self): with SettingsOverride(CMS_MODERATOR=True): page1 = create_page('page', 'nav_playground.html', 'en', published=True) with SettingsOverride(CMS_MODERATOR=False): page2 = get_page_from_path(page1.get_absolute_url().strip('/')) self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
def clean_overwrite_url(self): if 'overwrite_url' in self.fields: url = self.cleaned_data['overwrite_url'] if url: if not any_path_re.match(url): raise forms.ValidationError(_('Invalid URL, use /my/url format.')) if get_page_from_path(url.strip('/')): raise forms.ValidationError(_('Page with redirect url %r already exist') % url) return url
def get_features(context): context['root'] = get_page_from_path('features') if context['root'] and context['root'].children.filter(published=True): context['features'] = context['root'].children.filter(published=True) for f in context['features']: setattr(f, 'plchld', {}) for p in f.placeholders.all(): f.plchld[p.slot] = p return context
def test_switch_moderator_on(self): with force_language("en"): pages_root = unquote(reverse("pages-root")) page1 = create_page('page', 'nav_playground.html', 'en', published=True) with disable_logger(log): call_command('cms', 'moderator', 'on') with force_language("en"): path = page1.get_absolute_url()[len(pages_root):].strip('/') page2 = get_page_from_path(path) self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
def clean_overwrite_url(self): if 'overwrite_url' in self.fields: url = self.cleaned_data['overwrite_url'] if url: if not any_path_re.match(url): raise forms.ValidationError(_('Invalid URL, use /my/url format.')) page = get_page_from_path(url.strip('/')) if page and page.pk != self.instance.pk: raise forms.ValidationError(_('Page with redirect url %r already exist') % url) return url
def clean_overwrite_url(self): if "overwrite_url" in self.fields: url = self.cleaned_data["overwrite_url"] if url: if not any_path_re.match(url): raise forms.ValidationError(_("Invalid URL, use /my/url format.")) page = get_page_from_path(url.strip("/")) if page and page.pk != self.instance.pk: raise forms.ValidationError(_("Page with redirect url %r already exist") % url) return url
def get_slider(context): context['root'] = get_page_from_path('slider') if context['root'] and context['root'].children.filter(published=True): context['slides'] = context['root'].children.filter(published=True) for s in context['slides']: setattr(s, 'plchld', {}) for p in s.placeholders.all(): if p.slot == 'background': setattr(s, 'background', p.get_plugins()[0].filerimage.image.url) s.plchld[p.slot] = p return context
def _find_parent(full_url): parent_url = os.path.dirname(full_url) if not parent_url: root = Page.objects.get_home() if not root: return None return root parent = get_page_from_path(parent_url, draft=True) if not parent: logger.error('Parent {} not found.'.format(parent_url)) return None return parent
def get_context_data(self, *args, **kwargs): context_data = super(ImagePluginDetailView, self).get_context_data( *args, **kwargs) if self.return_url: page = get_page_from_path(self.return_url.strip('/')) if page: context_data.update({ 'link': PluginLink(url=page.get_absolute_url(), text=_('Back to %s') % page.get_title()) }) return context_data
def get_context_data(self, *args, **kwargs): context_data = super(ImagePluginDetailView, self).get_context_data(*args, **kwargs) if self.return_url: page = get_page_from_path(self.return_url.strip('/')) if page: context_data.update({ 'link': PluginLink(url=page.get_absolute_url(), text=_('Back to %s') % page.get_title()) }) return context_data
def get_object(self, *args, **kwargs): obj = super(ImagePluginDetailView, self).get_object(*args, **kwargs) if obj: allowed = False # validate that the object is actually published using the plugin... for plugin in MediaTreeImage.objects.filter(node=obj): # ...and on a publicly accessible page. # TODO: Iterating all plugins and getting each page # is a bit inefficient. page = get_page_from_path(plugin.page.get_path()) if page: allowed = True break if not allowed: raise Http404 return obj
def render_feature(context): context['root'] = get_page_from_path('features') return context
def link_repl(match): page = get_page_from_path(match.group(1)) if page: return "(" + page.get_absolute_url() + ")" else: return "(#" + match.group(1) + ")"
def find_page(url, draft=False): page = get_page_from_path(clean_url(url), draft) if page and draft and not page.publisher_is_draft: return page.get_draft_object() return page