Beispiel #1
0
def flatpage(request, url):
    """
    Public interface to the flat page view.

    Models: `flatpages.flatpages`
    Templates: Uses the template defined by the ``template_name`` field,
        or `flatpages/default.html` if template_name is not defined.
    Context:
        flatpage
            `flatpages.flatpages` object
    """

    if not url.startswith('/'):
        url = '/' + url
    try:
        # try load flatpage from cache, else, update cache and get from DB
        f = get_flapage_from_cache(url)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_flapage_from_cache(url)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise

    # create breadcrumbs
    breadcrumbs_for_flatpages(request, f)

    return render_flatpage(request, f)
Beispiel #2
0
def flatpage(request, url):
    """
    Public interface to the flat page view.

    Models: `flatpages.flatpages`
    Templates: Uses the template defined by the ``template_name`` field,
        or `flatpages/default.html` if template_name is not defined.
    Context:
        flatpage
            `flatpages.flatpages` object
    """

    if not url.startswith('/'):
        url = '/' + url
    try:
        # try load flatpage from cache, else, update cache and get from DB
        f = get_flapage_from_cache(url)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_flapage_from_cache(url)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise

    # create breadcrumbs
    breadcrumbs_for_flatpages(request, f)

    return render_flatpage(request, f)
Beispiel #3
0
def flatpage(request, url):
    """
    Copy of a `flatpage` view from `django.contrib.flatpages`. Use our `FlatPage` model instead of django one.
    """
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(FlatPage, url=url, sites=site_id)
    except Http404:
        try:
            if not url.endswith('/') and settings.APPEND_SLASH:
                url += '/'
                f = get_object_or_404(FlatPage, url=url, sites=site_id)
                return HttpResponsePermanentRedirect('%s/' % request.path)
            else:
                raise
        except Http404:
            # XXX: Temporary redirection of the old person URLs to the new URLs
            resolver = RegexURLResolver(r'^/', HUMAN_PATTERNS)
            match = resolver.resolve(url)
            if Person.objects.filter(is_active=True, human__nickname=match.kwargs['slug']).exists():
                return HttpResponsePermanentRedirect(urljoin('/people/person/', url[1:]))
            raise
    return render_flatpage(request, f)
Beispiel #4
0
def flatpage(request, url):
    """
    Public interface to the multilingual flat page view.

    Models: `mlflatpages.flatpage`
    Templates: Uses the template defined by the ``template_name`` field,
        or `flatpages/default.html` if template_name is not defined.
    Context:
        flatpage
            `mlflatpages.flatpage` object
    """
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(FlatPage,
            url__exact=url, sites__id__exact=site_id)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(FlatPage,
                url__exact=url, sites__id__exact=site_id)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise

    # Use django flatpage render
    return render_flatpage(request, f)
Beispiel #5
0
def responsive_flatpage(request, url):
    """Custom flatpage that changes the template based on middleware depending on 
    whether it is desktop or mobile.
    Based of https://github.com/django/django/blob/stable/1.8.x/django/contrib/flatpages/views.py

    Args:
        request (obj): Request object
        url (str): URL of flat page, for example: /about/

    """
    if not url.startswith("/"):
        url = "/" + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(FlatPage, url=url, sites=site_id)
    except Http404:
        if not url.endswith("/"):
            url += "/"
            f = get_object_or_404(FlatPage, url=url, sites=site_id)
            return HttpResponsePermanentRedirect("%s/" % request.path)
        else:
            raise
    if f.template_name:
        f.template_name = request.template_prefix + "/" + f.template_name
    else:
        f.template_name = request.template_prefix + "/flatpages/default.html"
    return render_flatpage(request, f)
Beispiel #6
0
def render_translated_flatpage(request, f):
    try:
        translation = f.translations.get(language=request.LANGUAGE_CODE)
        f.title = translation.title
        f.content = translation.content
    except FlatPageTranslation.DoesNotExist:
        print(u'no translation for page "{flatpage}" for language {lang}'.format(
            flatpage=f.url,
            lang=request.LANGUAGE_CODE))
    return render_flatpage(request, f)
Beispiel #7
0
def flatpage(request, page=""):
    # Translate flatpages
    lang = request.LANGUAGE_CODE.lower()
    try:
        fpage = FlatPage.objects.get(url__exact=("/%s-%s/" % (page, lang)),
                                     sites__id__exact=settings.SITE_ID)
    except FlatPage.DoesNotExist:
        fpage = get_object_or_404(FlatPage, url__exact=("/%s/" % page),
                                  sites__id__exact=settings.SITE_ID)
    return render_flatpage(request, fpage)
Beispiel #8
0
def render_translated_flatpage(request, f):
    try:
        translation = f.translations.get(language=request.LANGUAGE_CODE)
        f.title = translation.title
        f.content = translation.content
    except FlatPageTranslation.DoesNotExist:
        print(
            u'no translation for page "{flatpage}" for language {lang}'.format(
                flatpage=f.url, lang=request.LANGUAGE_CODE))
    return render_flatpage(request, f)
Beispiel #9
0
    def get(self, request, url):
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'

        from django.contrib.flatpages.views import flatpage, render_flatpage

        if not request.user.is_superuser or FlatPage.objects.filter(url='url', sites=settings.SITE_ID).exists():
            return flatpage(request, url)
        else:
            f = FlatPage(url=url)
            return render_flatpage(request, f)
Beispiel #10
0
    def get(self, request, url):
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'

        from django.contrib.flatpages.views import flatpage, render_flatpage

        if not request.user.is_superuser or FlatPage.objects.filter(url='url', sites=settings.SITE_ID).exists():
            return flatpage(request, url)
        else:
            f = FlatPage(url=url)
            return render_flatpage(request, f)
Beispiel #11
0
def flatpage(request, page=""):
    # Translate flatpages
    lang = request.LANGUAGE_CODE.lower()
    try:
        fpage = FlatPage.objects.get(url__exact=("/%s-%s/" % (page, lang)),
                                     sites__id__exact=settings.SITE_ID)
    except FlatPage.DoesNotExist:
        fpage = get_object_or_404(FlatPage,
                                  url__exact=("/%s/" % page),
                                  sites__id__exact=settings.SITE_ID)
    return render_flatpage(request, fpage)
Beispiel #12
0
def flatpage(request, page=""):

    """
    Function for translating flatpages. This function picks up the pagename
    followed by a dash and the language code. If it's not found it returns
    a 404.

    .. versionadded:: 0.1
    """
    # Translate flatpages
    lang = request.LANGUAGE_CODE.lower()
    fpage = get_object_or_404(FlatPage, url__exact=("/%s-%s/" % (page, lang)), sites__id__exact=settings.SITE_ID)
    return render_flatpage(request, fpage)
Beispiel #13
0
def flatpage(request, page=""):
    """
    Function for translating flatpages. This function picks up the pagename
    followed by a dash and the language code. If it's not found it returns
    a 404.

    .. versionadded:: 0.1
    """
    # Translate flatpages
    lang = request.LANGUAGE_CODE.lower()
    fpage = get_object_or_404(FlatPage,
                              url__exact=("/%s-%s/" % (page, lang)),
                              sites__id__exact=settings.SITE_ID)
    return render_flatpage(request, fpage)
Beispiel #14
0
    def process_request(self, request):
        """This code was partially copied from django.contrib.flatpages.views.flatpage"""

        try:
            flatpage = FlatPage.objects.get(url__exact=request.path_info, sites__id__exact=settings.SITE_ID)
        except FlatPage.DoesNotExist:
            return None

        try:
            trans = flatpage.translations.get(language__iexact=request.LANGUAGE_CODE)

            trans.registration_required = flatpage.registration_required
            trans.template_name = flatpage.template_name
        except FlatPageTranslation.DoesNotExist:
            trans = flatpage

        return render_flatpage(request, trans)
Beispiel #15
0
def page(request, url):
    """
    Attempt to find a flatpage for the path and display it
    """
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(Page, url=url, sites=site_id)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(Page, url=url, sites=site_id)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise
    return cacheatron(request, render_flatpage(request, f), (zxpage,))
Beispiel #16
0
def hierarchical_flatpage(request, url):
    """
    Copy of the standard public interface to the flat page view that integrates
    HierarchicalFlatPages.
    """
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(HierarchicalFlatPage, url=url, sites=site_id)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(HierarchicalFlatPage, url=url, sites=site_id)
            return HttpResponsePermanentRedirect(f'{request.path}/')
        else:
            raise
    return flatpage_views.render_flatpage(request, f)
Beispiel #17
0
    def process_request(self, request):
        """This code was partially copied from django.contrib.flatpages.views.flatpage"""

        try:
            flatpage = FlatPage.objects.get(url__exact=request.path_info,
                                            sites__id__exact=settings.SITE_ID)
        except FlatPage.DoesNotExist:
            return None

        try:
            trans = flatpage.translations.get(
                language__iexact=request.LANGUAGE_CODE)

            trans.registration_required = flatpage.registration_required
            trans.template_name = flatpage.template_name
        except FlatPageTranslation.DoesNotExist:
            trans = flatpage

        return render_flatpage(request, trans)
Beispiel #18
0
def i18n_flatpage(request, url):
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(
            FlatPage,
            url__exact=url,
            sites__id__exact=site_id,
            language=get_language()[:2],
        )
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise
    return render_flatpage(request, f)
Beispiel #19
0
def i18n_flatpage(request, url):
    if not url.startswith('/'):
        url = '/' + url
    site_id = get_current_site(request).id
    try:
        f = get_object_or_404(
            FlatPage,
            url__exact=url,
            sites__id__exact=site_id,
            language=get_language()[:2],
        )
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(FlatPage,
                url__exact=url, sites__id__exact=site_id)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise
    return render_flatpage(request, f)
Beispiel #20
0
def permission_protected_flatpage(request, url):
    """
    Exactly the same as normal FlatPage view which just verifies the access.
    """
    if not url.startswith("/"):
        url = "/" + url

    site_id = get_current_site(request).id

    try:
        f = get_object_or_404(FlatPage, url=url, sites=site_id)

        if hasattr(f, "metadata") and not f.metadata.is_accessible_for(request.user):
            return HttpResponseForbidden()

    except Http404:
        if not url.endswith("/") and settings.APPEND_SLASH:
            url += "/"
            f = get_object_or_404(FlatPage, url=url, sites=site_id)
            return HttpResponsePermanentRedirect("%s/" % request.path)

        raise
    return render_flatpage(request, f)
Beispiel #21
0
def flatpage(request, url):
    """
    Public interface to the flat page view.

    Models: `flatpages.flatpages`
    Templates: Uses the template defined by the ``template_name`` field,
        or :template:`flatpages/default.html` if template_name is not defined.
    Context:
        flatpage
            `flatpages.flatpages` object
    """
    if not url.startswith('/'):
        url = '/' + url
    try:
        f = get_object_or_404(BlogPage, url__exact=url)
    except Http404:
        if not url.endswith('/') and settings.APPEND_SLASH:
            url += '/'
            f = get_object_or_404(BlogPage, url__exact=url)
            return HttpResponsePermanentRedirect('%s/' % request.path)
        else:
            raise
    return render_flatpage(request, f)
Beispiel #22
0
def flatpage(request, page=""):
    # Translate flatpages
    lang = request.LANGUAGE_CODE.lower()
    fpage = get_object_or_404(FlatPage, url__exact=("/%s-%s/" % (page, lang)), sites__id__exact=settings.SITE_ID)
    return render_flatpage(request, fpage)