views.py :  » Content-Management-Systems » PyLucid » PyLucid_standalone » pylucid_project » pylucid_plugins » redirect » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Content Management Systems » PyLucid 
PyLucid » PyLucid_standalone » pylucid_project » pylucid_plugins » redirect » views.py
# coding:utf-8

from django import http
from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext

from redirect.models import RedirectModel


def setup_view(request):
    """
    called to setup a page entry
    TODO: This must be implemented in PyLucid, see also:
    http://pylucid.org/phpBB2/viewtopic.php?p=1551&highlight=setup+view#1551 (de)
    """
    pass


def redirect(request, rest_url=""):
    pagetree = request.PYLUCID.pagetree
    #lang_entry = request.PYLUCID.current_language

    try:
        redirect_info = RedirectModel.objects.get(pagetree=pagetree)#, language=lang_entry)
    except RedirectModel.DoesNotExist, err:
        # TODO: Don't redirect to admin panel -> Display a own create view!
        request.page_msg(
             _("Redirect entry for page: %s doesn't exist, please create.") % pagetree.get_absolute_url()
        )
        return HttpResponseRedirect(reverse("admin:redirect_redirectmodel_add"))

    destination_url = redirect_info.destination_url

    #print "rest_url: %r" % rest_url
    rest_url = rest_url.lstrip("/")
    if rest_url: # Handel the additional url part
        if not redirect_info.full_url:
            # raise 404, because we should not match on the full url.
            msg = ""
            if settings.DEBUG or request.user.is_staff:
                msg += " URL has additional parts %r, but 'full_url' is not allowed." % rest_url
            raise http.Http404(msg)
        destination_url += rest_url

    if request.GET and redirect_info.append_query_string:
        # Add GET query string
        # We don't use request.GET.urlencode() here, because it can change the key positions
        full_path = request.get_full_path()
        get_string = full_path.split("?", 1)[1]
        destination_url += "?" + get_string

    response_data = redirect_info.get_response_data()

    # get HttpResponsePermanentRedirect or HttpResponseRedirect class
    response_class = response_data["class"]
    response = response_class(destination_url)

    if settings.DEBUG or request.user.is_staff:
        msg = "You redirected from %r to %r (%s)" % (
            request.path, destination_url, response_data["title"]
        )
        if redirect_info.debug:
            return "Debug: %s" % msg
        else:
            request.page_msg.info(msg)

    return response

def redirect_index(request):
    return redirect(request)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.