def content_parser(selector):

            if selector.startswith("branch:"):
                doc_id = selector.split(":", 1)[1]
                try:
                    document = Document.require_instance(int(doc_id))
                except:
                    raise ArgumentTypeError(
                        f"{doc_id} is not a valid branch ID"
                    )
                else:
                    return ("branch", ("post", document))

            elif selector.startswith("delbranch:"):
                doc_id = selector.split(":", 1)[1]
                try:
                    document = Document.require_instance(int(doc_id))
                except:
                    raise ArgumentTypeError(
                        f"{doc_id} is not a valid branch ID"
                    )
                else:
                    return ("branch", ("delete", document))

            elif selector.startswith("item:"):
                pub_id = selector.split(":", 1)[1]
                try:
                    publishable = Publishable.require_instance(int(pub_id))
                except:
                    raise ArgumentTypeError(
                        f"{pub_id} is not a valid branch ID"
                    )
                else:
                    return ("item", ("post", publishable))

            elif selector.startswith("delitem:"):
                pub_id = selector.split(":", 1)[1]
                try:
                    publishable = Publishable.require_instance(int(pub_id))
                except:
                    raise ArgumentTypeError(
                        f"{pub_id} is not a valid branch ID"
                    )
                else:
                    return ("item", ("delete", publishable))

            elif selector.startswith("export:"):
                export_id = selector.split(":", 1)[1]
                try:
                    export = Export.require_instance(int(export_id))
                except:
                    raise ArgumentTypeError(
                        f"{export_id} is not a valid export ID"
                    )
                else:
                    return ("export", export)
Esempio n. 2
0
        def submit(self):

            ProceedForm.submit(self)

            order = Basket.pop()
            order.status = "payment_pending"
            order.update_cost()

            datastore.commit()
            payments = PaymentsExtension.instance

            # Redirect the user to the payment gateway
            if payments.enabled \
            and payments.payment_gateway \
            and order.payment_type == "payment_gateway":
                payments.payment_request(order.id)

            # No payment gateway available, redirect the user to the success
            # page; the payment will have to be handled manually by the site's
            # personnel
            else:
                raise cherrypy.HTTPRedirect(
                    Publishable.require_instance(
                        qname="woost.extensions.ecommerce.success_page").
                    get_uri(parameters={"order": order.id}))
 def confirmation_url(self):
     confirmation_page = Publishable.require_instance(
         qname='woost.password_change_confirmation_page')
     return confirmation_page.get_uri(host=".",
                                      parameters={
                                          "user":
                                          self.identifier,
                                          "hash":
                                          generate_confirmation_hash(
                                              self.identifier)
                                      })
Esempio n. 4
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))
Esempio n. 5
0
        def submit(self):
            Form.submit(self)
            Basket.get().add_purchase(self.instance)
            Basket.store()

            notify_user(translations(
                "woost.extensions.ecommerce.product_added_notice",
                product=self.product),
                        "product_added",
                        transient=False)

            if self.redirect_to_basket:
                raise cherrypy.HTTPRedirect(
                    Publishable.require_instance(
                        qname="woost.extensions.ecommerce.basket_page").
                    get_uri())
            else:
                Location.get_current().go("GET")
Esempio n. 6
0
def requires_agreement(form, name = "terms", document = None):

    if document is None:
        document = "%s.%s" % (app.package, name)

    if isinstance(document, basestring):
        document = Publishable.require_instance(qname = document)

    if document is None:
        raise ValueError(
            "Must specify a document detailing the end user agreement"
        )

    member = schema.Boolean(
        name = name,
        required = True,
        __translate__ = lambda language, **kwargs:
            schema.Boolean.__translate__(member, language, **kwargs)
            or translations(
                "woost.controllers.formagreement.%s" % member.name,
                member = member
            )
            or translations("woost.controllers.formagreement", member =
                member),
        member_group = "form_agreement"
    )
    member.agreement_document = document
    member.add_validation(_validate_consent)

    form.schema.add_member(member)

    if form.schema.groups_order:
        if "form_agreement" not in form.schema.groups_order:
            if not isinstance(form.schema.groups_order, list):
                form.schema.groups_order = list(form.schema.groups_order)
            form.schema.groups_order.append("form_agreement")

    form.adapter.exclude(name)
    return member
Esempio n. 7
0
def catalog_current_state_uri():
    state = session.get(SESSION_KEY) or {}
    catalog = Publishable.require_instance(
        qname="woost.extensions.ecommerce.catalog_page")
    return catalog.get_uri(parameters=state)