Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        result = super(UpdaterConfigPage, self).save(no_messages=True,
                                                     *args,
                                                     **kwargs)

        target = self.form.callback_results.get("target", None)
        if target in ["deny", "grant"]:
            result = self.form.callback_results["result"]
            if result:
                if target == "grant":
                    messages.success(_("Update was approved."))
                elif target == "deny":
                    messages.success(_("Update was postponed."))
            else:
                if target == "grant":
                    messages.error(_("Failed to approve the update."))
                elif target == "deny":
                    messages.error(_("Failed to postpone the update."))
            return result

        if result:
            if self.form.callback_results.get("enabled", False):
                messages.success(
                    _("Configuration was successfully saved. Selected "
                      "packages should be installed or removed shortly."))
            else:
                messages.success(_("Configuration was successfully saved."))
        else:
            messages.warning(_("There were some errors in your input."))
        return result
Exemplo n.º 2
0
    def save(self, *args, **kwargs):
        result = super(UpdaterConfigPage, self).save(no_messages=True, *args, **kwargs)

        target = self.form.callback_results.get("target", None)
        if target in ["deny", "grant"]:
            result = self.form.callback_results["result"]
            if result:
                if target == "grant":
                    messages.success(_("Update was approved."))
                elif target == "deny":
                    messages.success(_("Update was postponed."))
            else:
                if target == "grant":
                    messages.error(_("Failed to approve the update."))
                elif target == "deny":
                    messages.error(_("Failed to postpone the update."))
            return result

        if result:
            messages.success(
                _(
                    "Configuration was successfully saved. Selected "
                    "packages should be installed or removed shortly."
                )
            )
        else:
            messages.warning(_("There were some errors in your input."))
        return result
Exemplo n.º 3
0
    def _action_check_registration(self):
        handler = RegistrationCheckHandler(bottle.request.POST.decode())
        if not handler.save():
            messages.warning(_("There were some errors in your input."))
            return self.render(registration_check_form=handler.form)

        email = handler.data["email"]

        result = handler.form.callback_results
        kwargs = {}
        if not result["success"]:
            messages.error(
                _("An error ocurred when checking the registration: "
                  "<br><pre>%(error)s</pre>" % dict(error=result["error"])))
            return self.render()
        else:
            if result["status"] == "owned":
                messages.success(
                    _("Registration for the entered email is valid. "
                      "Now you can enable the data collection."))
                collection_toggle_handler = CollectionToggleHandler(
                    bottle.request.POST.decode())
                kwargs[
                    'collection_toggle_form'] = collection_toggle_handler.form
            elif result["status"] == "foreign":
                messages.warning(
                    _('This router is currently assigned to a different email address. Please '
                      'continue to the <a href="%(url)s">Turris website</a> and use the '
                      'registration code <strong>%(reg_num)s</strong> for a re-assignment to your '
                      'email address.') %
                    dict(url=result["url"],
                         reg_num=result["registration_number"]))
                bottle.redirect(
                    reverse("config_page", page_name="data_collect") + "?" +
                    urlencode({"email": email}))
            elif result["status"] == "free":
                messages.info(
                    _('This email address is not registered yet. Please continue to the '
                      '<a href="%(url)s">Turris website</a> and use the registration code '
                      '<strong>%(reg_num)s</strong> to create a new account.')
                    % dict(url=result["url"],
                           reg_num=result["registration_number"]))
                bottle.redirect(
                    reverse("config_page", page_name="data_collect") + "?" +
                    urlencode({"email": email}))
            elif result["status"] == "not_found":
                messages.error(
                    _('Router failed to authorize. Please try to validate our email later.'
                      ))
                bottle.redirect(
                    reverse("config_page", page_name="data_collect") + "?" +
                    urlencode({"email": email}))
        return self.render(status=result["status"],
                           registration_url=result["url"],
                           reg_num=result["registration_number"],
                           **kwargs)
Exemplo n.º 4
0
 def save(self, *args, **kwargs):
     no_messages = kwargs.pop("no_messages", False)
     result = super(ConfigPageMixin, self).save(*args, **kwargs)
     if no_messages:
         return result
     if result:
         messages.success(_("Configuration was successfully saved."))
     else:
         messages.warning(_("There were some errors in your input."))
     return result
Exemplo n.º 5
0
 def _action_save_notifications(self):
     if bottle.request.method != "POST":
         messages.error(_("Wrong HTTP method."))
         bottle.redirect(reverse("config_page", page_name="maintenance"))
     handler = notifications.NotificationsHandler(bottle.request.POST.decode())
     if handler.save():
         messages.success(_("Configuration was successfully saved."))
         bottle.redirect(reverse("config_page", page_name="maintenance"))
     messages.warning(_("There were some errors in your input."))
     return super(MaintenanceConfigPage, self).render(notifications_form=handler.form)
Exemplo n.º 6
0
 def save(self, *args, **kwargs):
     super(MaintenanceConfigPage, self).save(no_messages=True, *args, **kwargs)
     result = self.form.callback_results.get('result')
     if result:
         messages.success(_("Configuration was successfully restored. "
                            "Note that a reboot will be required to apply restored "
                            "configuration."))
     else:
         messages.warning(_("Failed to restore the backup from the provided file."))
     return result
Exemplo n.º 7
0
 def _action_save_notifications(self):
     if bottle.request.method != 'POST':
         messages.error(_("Wrong HTTP method."))
         bottle.redirect(reverse("config_page", page_name="maintenance"))
     handler = notifications.NotificationsHandler(request.POST.decode())
     if handler.save():
         messages.success(_("Configuration was successfully saved."))
         bottle.redirect(reverse("config_page", page_name="maintenance"))
     messages.warning(_("There were some errors in your input."))
     return super(MaintenanceConfigPage, self).render(notifications_form=handler.form)
Exemplo n.º 8
0
    def _action_toggle_collecting(self):
        if bottle.request.method != 'POST':
            messages.error(_("Wrong HTTP method."))
            bottle.redirect(reverse("config_page", page_name="data_collect"))

        handler = CollectionToggleHandler(bottle.request.POST.decode())
        if handler.save():
            messages.success(_("Configuration was successfully saved."))
            bottle.redirect(reverse("config_page", page_name="data_collect"))

        messages.warning(_("There were some errors in your input."))
        return super().render(collection_toggle_form=handler.form)
Exemplo n.º 9
0
 def save(self, *args, **kwargs):
     super(MaintenanceConfigPage, self).save(no_messages=True, *args, **kwargs)
     result = self.form.callback_results.get("result")
     if result:
         messages.success(
             _(
                 "Configuration was successfully restored. "
                 "Note that a reboot will be required to apply restored "
                 "configuration."
             )
         )
     else:
         messages.warning(_("Failed to restore the backup from the provided file."))
     return result