Exemple #1
0
    def _establish_active_website(self):
        location = Location.get_current_host()
        website = Configuration.instance.get_website_by_host(location.host)
        set_current_website(website)

        if website is None:
            raise cherrypy.HTTPError(404, "Unknown hostname: " + location.host)
Exemple #2
0
    def __call__(self):

        output = []
        write = output.append

        write(u"<?xml version='1.0' encoding='utf-8'?>")
        write(u"<urlset xmlns='%s'>" % self.namespace)

        base_url = str(Location.get_current_host()).rstrip(u"/")
        uri = self.context["cms"].uri

        for item in self.items:
            write(u"\t<url>")

            item_uri = base_url + u"/" + uri(item).lstrip(u"/")
            write(u"\t\t<loc>%s</loc>" % item_uri)

            date = item.last_update_time.strftime("%Y-%m-%d")
            write(u"\t\t<lastmod>%s</lastmod>" % date)

            frequency = item.sitemap_change_frequency
            if frequency:
                write(u"\t\t<changefreq>%s</changefreq>" % frequency)

            priority = item.sitemap_priority
            if priority:
                write(u"\t\t<priority>%s</priority>" % priority)

            write(u"\t</url>")

        write(u"</urlset>")
        return u"\n".join(output)
Exemple #3
0
    def _fix_uri(self, uri, host, encode):

        if encode:
            uri = percent_encode_uri(uri)

        if "://" in uri:
            host = None

        if host:
            website = get_current_website()
            policy = website and website.https_policy

            if (policy == "always" or (policy == "per_page" and
                                       (getattr(self, 'requires_https', False)
                                        or not get_current_user().anonymous))):
                scheme = "https"
            else:
                scheme = "http"

            if host == ".":
                location = Location.get_current_host()
                location.scheme = scheme
                host = str(location)
            elif not "://" in host:
                host = "%s://%s" % (scheme, host)

            uri = make_uri(host, uri)
        elif "://" not in uri:
            uri = make_uri("/", uri)

        return uri
Exemple #4
0
    def __call__(self, **parameters):

        # Get references to the gateway and payment
        gateway = get_parameter(
            schema.Reference("gateway_id", type=DummyPaymentGateway))

        if gateway is None:
            raise ValueError("Wrong payment gateway")

        payment_id = get_parameter(schema.String("payment_id"))
        payment = payment_id and gateway.get_payment(payment_id) or None

        if payment is None:
            raise ValueError("Wrong payment id (%s)" % payment_id)

        # Notify the payment to the application
        cms = self.context["cms"]
        notification_uri = Location.get_current_host()
        notification_uri.path_info = cms.application_uri(
            "payment_notification", payment_id=payment_id)
        urlopen(str(notification_uri))

        # Redirect the user after the transaction's over
        redirection = None

        if gateway.payment_status == "accepted":
            redirection = gateway.payment_successful_page
        elif gateway.payment_status == "failed":
            redirection = gateway.payment_failed_page

        raise cherrypy.HTTPRedirect((redirection and cms.uri(redirection)
                                     or cms.application_uri()).encode("utf-8"))
Exemple #5
0
        def initializer(session):
            if open_browser:

                # Find the web console document
                webconsole = Publishable.require_instance(
                    qname="woost.extensions.webconsole.page")

                # Determine the URI for the breakpoint session
                webconsole_location = Location.get_current_host()
                webconsole_location.path_info = webconsole.get_uri()
                webconsole_location.query_string["session_id"] = session.id

                # Open a web browser tab pointing at the URI
                from webbrowser import open
                open(str(webconsole_location))