Beispiel #1
0
    def __call__(self, export_id, lang, **kwargs):

        set_language(lang)

        try:
            export_id = int(export_id)
        except ValueError:
            raise cherrypy.HTTPError(400)

        export = Export.get_instance(export_id)
        if export is None:
            raise cherrypy.NotFound()

        destination = export.destination

        app.user.require_permission(ExportPermission, destination=destination)

        export_object = DataExport(include_paths=True).export_object
        tasks = []
        data = {"state": export.state, "tasks": tasks}

        for task in export.tasks.values():
            item = task["item"]
            lang = task["language"]
            source_url = item.get_uri(language=lang)
            task_data = task.copy()
            task_data["source_url"] = source_url
            task_data["export_url"] = destination.get_export_url(source_url)
            task_data["item"] = export_object(item)
            tasks.append(task_data)

        return data
Beispiel #2
0
    def submit(self):

        mailing = self.context["cms_item"]

        if self.mailer_action == "test":

            # Send a test email
            mailing._v_template_values = {
                "cms": self.context["cms"],
                "base_url": unicode(Location.get_current_host()).rstrip("/")
            }
            test_email = self.params.read(schema.String("test_email"))
            # Create a fake user
            receiver = User(email = test_email)
            set_language(mailing.language)
            mailing.send_message(self.smtp_server, receiver)

        elif self.mailer_action == "send":

            # Send the mailing
            self.task_id = mailing.id
            template_values = {
                "cms": self.context["cms"],
                "base_url": unicode(Location.get_current_host()).rstrip("/")
            }
            mailing.send(self.smtp_server, template_values, self.context.copy())

        else:
            EditController.submit(self)
    def test_uses_implicit_language(self):

        from cocktail.translations import translations, set_language

        translations.define("parrot", ca="Lloro", es="Loro", en="Parrot")

        set_language("ca")
        assert translations("parrot") == "Lloro"
Beispiel #4
0
    def __call__(self, lang, **kwargs):

        set_language(lang)

        if cherrypy.request.method == "GET":
            return self.preview()
        elif cherrypy.request.method == "POST":
            export = self.begin()
            return {"export_id": export.id}
Beispiel #5
0
    def __call__(self, query="", lang=None):

        if isinstance(query, str):
            query = query.decode("utf-8")

        self.query = query
        cherrypy.response.headers["Content-Type"] = "application/json"

        if lang:
            set_language(lang)

        return Controller.__call__(self)
    def __call__(self, *args, **kwargs):

        node = self.stack_node
        previewed_item = self.previewed_item
        publishable = self.preview_publishable
        preview_language = self.preview_language
        user = get_current_user()

        # Set the language for the preview
        if preview_language:
            set_language(preview_language)

        # Enforce permissions
        user.require_permission(ReadPermission, target=previewed_item)

        if publishable is not previewed_item:
            user.require_permission(ReadPermission, target=publishable)

        # Disable the preview if the item's unsaved state produces validation
        # errors; these would usually lead to unhandled server errors during
        # rendering.
        errors = schema.ErrorList(node.iter_errors())

        if errors:
            error_box = templates.new("cocktail.html.ErrorBox")
            error_box.errors = errors
            message = Element("div",
                              class_name="preview-error-box",
                              children=[
                                  translations(
                                      "woost.backoffice invalid item preview",
                                      preview_language), error_box
                              ])
            message.add_resource("/resources/styles/backoffice.css")
            return message.render_page()

        # Update the edited item with the data to preview
        node.import_form_data(node.form_data, previewed_item)

        self.context.update(original_publishable=self.context["publishable"],
                            publishable=publishable)

        controller = publishable.resolve_controller()

        if controller is None:
            raise cherrypy.NotFound()

        if isinstance(controller, type):
            controller = controller()

        return controller()
Beispiel #7
0
    def handle_traversed(cls, event):

        datastore.sync()

        cms = event.source

        cms.context.update(cms=cms, publishable=None)

        # Determine the active website
        cms._establish_active_website()

        # Set the default language
        language = app.language.infer_language()
        set_language(language)

        # Invoke the authentication module
        app.authentication.process_request()
Beispiel #8
0
    def process_request(self, path):

        self.setup_language_fallback_policy()

        if path:
            language = self.uri_component_to_language(path[0])
            if language in Configuration.instance.languages:
                path.pop(0)
            else:
                language = None
        else:
            language = None

        cherrypy.request.language_specified = (language is not None)

        if language is None:
            language = get_language() or self.infer_language()

        cherrypy.response.cookie["language"] = language
        cookie = cherrypy.response.cookie["language"]
        cookie["path"] = "/"
        set_cookie_expiration(cookie, seconds=self.cookie_duration)

        set_language(language)
Beispiel #9
0
 def receive_order_payment(event):
     payment = event.payment
     order = payment.order
     set_language(order.language)
     order.status = payment.status
     order.gateway_parameters = payment.gateway_parameters
Beispiel #10
0
 def setUp(self):
     from woost.models import User
     BaseTestCase.setUp(self)
     set_language("en")
     self.user = User()
     self.user.insert()
Beispiel #11
0
    def index(self, **params):

        set_language("en")
        submitted = cherrypy.request.method == "POST"
        successful = False
        errors = []
 
        HOST_FORMAT = \
            re.compile(r"^([a-z]+(\.[a-z]+)*)|(\d{1,3}(\.\d{1,3}){3})$")

        paths = sorted([p for p in sys.path if os.access(p, os.W_OK)])

        form_schema = schema.Schema(
            name = "Installer",
            members = [
                schema.String(
                    name = "project_name",
                    required = True,
                    format = r"^[A-Z][A-Za-z_0-9]*$",
                    member_group = "project"
                ),
                schema.String(
                    name = "python_package_repository",
                    required = True,
                    enumeration = paths,
                    translatable_enumeration = False,
                    default = paths and paths[0] or None,
                    member_group = "project"
                ),
                schema.String(
                    name = "installation_id",
                    required = True,
                    member_group = "project",
                    default = "DEV"
                ),
                schema.String(
                    name = "admin_email",
                    required = True,
                    default = "admin@localhost",
                    member_group = "project"
                ),
                schema.String(
                    name = "admin_password",
                    required = True,
                    min = 8,
                    edit_control = "cocktail.html.PasswordBox",
                    member_group = "project"
                ),
                schema.String(
                    name = "languages",
                    required = True,
                    default = "en",
                    format = r"^[a-zA-Z]{2}(\W+[a-zA-Z]{2})*$",
                    member_group = "project"
                ),
                schema.String(
                    name = "webserver_host",
                    required = True,
                    format = HOST_FORMAT,
                    default = "127.0.0.1",
                    member_group = "webserver"
                ),
                schema.Integer(
                    name = "webserver_port",
                    required = True,
                    default = 8080,
                    member_group = "webserver"
                ),
                schema.Boolean(
                    name = "validate_webserver_address",
                    default = True,
                    member_group = "webserver"
                ),
                schema.String(
                    name = "database_host",
                    required = True,
                    format = HOST_FORMAT,
                    default = "127.0.0.1",
                    member_group = "database"
                ),
                schema.Integer(
                    name = "database_port",
                    required = True,
                    default = 8081,
                    member_group = "database"
                ),
                schema.Boolean(
                    name = "validate_database_address",
                    default = True,
                    member_group = "database"
                ),
                schema.Integer(
                    name = "base_id",
                    member_group = "database"
                )
            ]
        )

        def make_address_validation(host_field, port_field, check_field):

            def validate_address(schema, validable, context):

                if validable[check_field]:
                    host = validable[host_field]
                    port = validable[port_field]
                    host_member = schema[host_field]
                    port_member = schema[port_field]

                    if host_member.validate(host) \
                    and port_member.validate(port) \
                    and not self._is_valid_local_address(host, port):
                        yield WrongAddressError(
                            schema, validable, context,
                            host_member, port_member
                        )

            return validate_address

        form_schema.add_validation(make_address_validation(
            "webserver_host",
            "webserver_port",
            "validate_webserver_address"
        ))

        form_schema.add_validation(make_address_validation(
            "database_host",
            "database_port",
            "validate_database_address"
        ))

        form_data = {}

        if submitted:
            get_parameter(
                form_schema,
                target = form_data,
                errors = "ignore",
                undefined = "set_none"
            )
            errors = list(form_schema.get_errors(form_data))

            if not errors:

                form_data["project_path"] = os.path.join(
                    form_data["python_package_repository"],
                    form_data["project_name"].lower()
                )

                try:
                    if os.path.exists(form_data["project_path"]):
                        raise InstallFolderExists()

                    self.install(form_data)

                except Exception, ex:
                    errors.append(ex)
                    if not isinstance(ex, InstallFolderExists):
                        traceback.print_tb(sys.exc_info()[2])
                        try:
                            rmtree(form_data["project_path"])
                        except Exception, rmex:
                            tb = sys.exc_info()[2]
                            traceback.print_tb(sys.exc_info()[2])
                            errors.append(rmex)
                else:
                    successful = True
Beispiel #12
0
 def receive_order_payment(event):
     payment = event.payment
     shop_order = payment.shop_order
     set_language(shop_order.language)
     shop_order.status = payment.status
     shop_order.gateway_parameters = payment.gateway_parameters
 def tearDown(self):
     from cocktail.translations import set_language
     set_language(None)
 def setUp(self):
     from cocktail.translations import set_language
     set_language(None)
 def handle_before_request(cls, event):
     user = get_current_user()
     language = (user and user.prefered_language or
                 Configuration.instance.get_setting("backoffice_language"))
     set_language(language)