def user_parser(value):

            try:
                try:
                    id = int(value)
                except ValueError:
                    return User.require_instance(email=value)
                else:
                    return User.require_instance(id)
            except:
                pass

            raise ArgumentTypeError(f"{id} is not a valid user ID or email")
Exemplo n.º 2
0
    def _create_ecommerceorder_completed_trigger(self):
        from woost.extensions.ecommerce.ecommerceordercompletedtrigger import \
            ECommerceOrderCompletedTrigger
        trigger = ECommerceOrderCompletedTrigger( )
        trigger.qname = \
            "woost.extensions.ecommerce.ecommerceorder_completed_trigger"
        self.__translate_field(trigger, "title")
        Configuration.instance.triggers.append(trigger)
        trigger.condition = "target.customer and not target.customer.anonymous and target.customer.email"
        trigger.matching_items = {'type': u'woost.extensions.ecommerce.ecommerceorder.ECommerceOrder'}

        # EmailTemplate
        template = EmailTemplate()
        template.qname = \
            "woost.extensions.ecommerce.ecommerceorder_completed_emailtemplate"
        self.__translate_field(template, "title")
        template.sender = '"%s"' % User.require_instance(
            qname = "woost.administrator"
        ).email
        template.receivers = '[items[0].customer.email]'
        template.embeded_images = """
from woost.models import Configuration
logo = Configuration.instance.get_setting("logo")
if logo:
    images["logo"] = logo
"""
        template.template_engine = "cocktail"

        for language in translations:
            with language_context(language):
                template.subject = template.title
                template.body = """
<%
from cocktail.controllers import Location
from cocktail.html import templates

order = items[0]
order_summary = templates.new("woost.extensions.ecommerce.OrderConfirmationMessage")
order_summary.order = order
%>

<html>
    <head>
        <base href="@{unicode(Location.get_current_host())}"/>
    </head>
    <body>
        ${order_summary.render()}
    </body>
</html>
"""

        # Response
        response = SendEmailTriggerResponse()
        response.qname = \
            "woost.extensions.ecommerce.ecommerceorder_completed_response"
        response.email_template = template

        trigger.responses = [response]
        return trigger
Exemplo n.º 3
0
    def _create_incoming_order_trigger(self):
        from woost.extensions.ecommerce.incomingordertrigger import \
            IncomingOrderTrigger
        trigger = IncomingOrderTrigger( )
        trigger.qname = "woost.extensions.ecommerce.incoming_order.trigger"
        self.__translate_field(trigger, "title")
        Configuration.instance.triggers.append(trigger)
        trigger.matching_items = {'type': u'woost.extensions.ecommerce.ecommerceorder.ECommerceOrder'}

        # EmailTemplate
        template = EmailTemplate()
        template.qname = \
            "woost.extensions.ecommerce.incoming_order.email_template"
        self.__translate_field(template, "title")
        admin = User.require_instance(qname = "woost.administrator")
        template.sender = repr(admin.email)
        template.receivers = repr([admin.email])
        template.template_engine = "cocktail"

        for language in translations:
            with language_context(language):
                template.subject = template.title
                template.body = """
<%
from cocktail.translations import translations
from woost.models import Publishable

order = items[0]
bo = Publishable.require_instance(qname = "woost.backoffice")
edit_url = bo.get_uri(host = ".", path = ["content", str(order.id)])
%>

<html>
    <body>
        <a href="${edit_url}">${translations('woost.extensions.ecommerce.incoming_order.edit_link')}
        </a>
    </body>
</html>
"""

        # Response
        response = SendEmailTriggerResponse()
        response.email_template = template
        trigger.responses = [response]

        return trigger
Exemplo n.º 4
0
def _create_symlink(file, dest):
    """Create a symbolic link for static publication of an encoded file."""

    if not hasattr(os, "symlink"):
        return

    # Only create static publication links for public content
    anonymous = User.require_instance(qname="woost.anonymous_user")
    if not anonymous.has_permission(ReadPermission, target=file):
        return

    static_folder = app.path("static", "audio", str(file.id))
    static_link = os.path.join(static_folder, os.path.basename(dest))

    if not os.path.lexists(static_link):

        # Make sure the containing folder exists
        if not os.path.exists(static_folder):
            os.mkdir(static_folder)

        os.symlink(dest, static_link)
Exemplo n.º 5
0
    def _install(self):

        from woost.models import (
            extension_translations,
            User,
            Controller,
            Document,
            StandardPage,
            Template,
            EmailTemplate
        )
        from woost.extensions.signup.signuppage import SignUpPage

        signup_controller = self._create_asset(
            Controller,
            "signup_controller",
            python_name =
                "woost.extensions.signup.signupcontroller.SignUpController",
            title = extension_translations
        )
        
        signup_confirmation_controller = self._create_asset(
            Controller,
            "signup_confirmation_controller",
            python_name = 
                "woost.extensions.signup.signupconfirmationcontroller."
                "SignUpConfirmationController",
            title = extension_translations
        )

        signup_view = self._create_asset(
            Template,
            "signup_template",
            identifier = "woost.extensions.signup.SignUpView",
            engine = u"cocktail",
            title = extension_translations
        )

        signup_confirmation_view = self._create_asset(
            Template,
            "signup_confirmation_template",
            identifier = u"woost.extensions.signup.SignUpConfirmationView",
            engine = u"cocktail",
            title = extension_translations
        )

        confirmation_email_template = self._create_asset(
            EmailTemplate,
            "signup_confirmation_email_template",
            python_name =
                u"woost.extensions.signup.signupconfirmationemailtemplate."
                "SignUpConfirmationEmailTemplate",
            template_engine = u"mako",
            sender = User.require_instance(qname="woost.administrator").email,
            receivers = u"[user.email]",
            title = extension_translations,
            subject = extension_translations,
            body = extension_translations
        )

        confirmation_target = self._create_asset(
            StandardPage,
            "signup_confirmation_target",
            title = extension_translations,
            controller = signup_confirmation_controller,
            template = signup_confirmation_view,
            hidden = True
        )

        signup_page = self._create_asset(
            SignUpPage,
            "signup_page",
            title = extension_translations,
            user_type = User,
            confirmation_target = confirmation_target,
            parent = Document.get_instance(qname="woost.home"),
        )

        signup_page.children.append(confirmation_target)