Пример #1
0
    def get_published_pagelist(self, request, *args, **kwargs):
        """
        This view is used by the SearchLinkField as the user types to feed the autocomplete drop-down.
        """
        if not request.is_ajax():
            return HttpResponseForbidden()
        data = {'results': []}
        language = get_language_from_request(request)
        query_term = request.GET.get('term')
        if not query_term:
            return JsonResponse(data)

        # first, try to resolve by URL if it points to a local resource
        parse_result = urlparse(query_term)
        if parse_result.netloc.split(':')[0] == request.META['HTTP_HOST'].split(':')[0]:
            site = get_current_site(request)
            path = parse_result.path.lstrip(reverse('pages-root')).rstrip('/')
            page = get_page_from_path(site, path)
            if page:
                data['results'].append(self.get_result_set(language, page))
                return JsonResponse(data)

        # otherwise resolve by search term
        matching_published_pages = Page.objects.published().public().filter(
            Q(title_set__title__icontains=query_term, title_set__language=language)
            | Q(title_set__path__icontains=query_term, title_set__language=language)
            | Q(title_set__menu_title__icontains=query_term, title_set__language=language)
            | Q(title_set__page_title__icontains=query_term, title_set__language=language)
        ).distinct().order_by('title_set__title').iterator()

        for page in matching_published_pages:
            data['results'].append(self.get_result_set(language, page))
            if len(data['results']) > 15:
                break
        return JsonResponse(data)
Пример #2
0
 def post(self, request, *args, **kwargs):
     page_path = request.POST.get('form_page_path', '').strip('/')
     cms_page = get_page_from_path(get_current_site(request), page_path)
     if not cms_page:
         return HttpResponseBadRequest('no cms_page')
     context = {
         'current_app': resolve(request.path).namespace,
         'current_page': cms_page,
     }
     form_plugin_id = request.POST.get('form_plugin_id') or ''
     if not form_plugin_id.isdigit():
         # fail if plugin_id has been tampered with
         return HttpResponseBadRequest('no form plugin')
     try:
         # I believe this could be an issue as we don't check if the form submitted
         # is in anyway tied to this page.
         # But then we have a problem with static placeholders :(
         form_plugin = get_plugin_tree(FormPlugin, pk=form_plugin_id)
     except FormPlugin.DoesNotExist:
         return HttpResponseBadRequest('no form')
     form_plugin_instance = form_plugin.get_plugin_instance()[1]
     # saves the form if it's valid
     form = form_plugin_instance.process_form(form_plugin, request)
     success_url = form_plugin_instance.get_success_url(
         instance=form_plugin)
     if form.is_valid():
         if success_url:
             return HttpResponseRedirect(success_url)
         context['post_success'] = True
     return render(request, 'aldryn_forms/form.html', context)
Пример #3
0
 def test_switch_moderator_off(self):
     site = get_current_site()
     with force_language("en"):
         pages_root = 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(site, path)
         self.assertIsNotNone(page2)
         self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
Пример #4
0
 def test_switch_moderator_on(self):
     site = get_current_site()
     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(site, path)
     self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
Пример #5
0
    def get(self, request, **kwargs):
        draft = use_draft(request)
        preview = 'preview' in request.GET
        try:
            self.cms_page = get_page_from_path(kwargs.get('path', ''), preview,
                                               draft)
            self.cms_page_title = self.cms_page.title_set.get(
                language=request.LANGUAGE_CODE)
        except AttributeError:
            return JsonResponse(data={}, status=404)

        return super(SpaCmsPageDetailApiView, self).get(request, **kwargs)
Пример #6
0
 def to_internal_value(self, data):
     site = get_current_site()
     pages_root = reverse('pages-root')
     ret = []
     for path in data:
         if path.startswith(pages_root):
             path = path[len(pages_root):]
         # strip any final slash
         if path.endswith('/'):
             path = path[:-1]
         page = get_page_from_path(site, path)
         if page:
             ret.append(page)
     return ret
Пример #7
0
 def to_internal_value(self, data):
     site = get_current_site()
     pages_root = reverse('pages-root')
     ret = []
     for path in data:
         if path.startswith(pages_root):
             path = path[len(pages_root):]
         # strip any final slash
         if path.endswith('/'):
             path = path[:-1]
         page = get_page_from_path(site, path)
         if page:
             ret.append(page)
     return ret
Пример #8
0
 def link_repl(match):
     page = get_page_from_path(match.group(1))
     if page:
         return "(" + page.get_absolute_url() + ")"
     else:
         return "(#" + match.group(1) + ")"