def render(self, **context): """ Render dashboard section """ name = self.get_name() context.update({ 'plugin': self, }) try: context.update(self.get_context()) return template(self.get_template(), **context) except Exception: logging.exception("Plugin rendering failed: {0}".format(name)) return template(self.plugin_error_template, **context)
def render(self, **context): """ Render dashboard section """ name = self.get_name() context.update({ 'plugin': self, }) try: context.update(self.get_context()) return template(self.get_template(), **context) except Exception: logging.exception("Plugin rendering failed: {0}".format(name)) return template(self.plugin_error_template, **context)
def reset(): next_path = request.params.get('next', '/') form = PasswordResetForm(request.params) if request.user.is_authenticated: # Set arbitrary non-empty value to prevent form error. We don't really # care about this field otherwise. form.reset_token.bind_value('not needed') if not form.is_valid(): return dict(next_path=next_path, form=form) if request.user.is_authenticated: username = request.user.username else: user = User.from_reset_token(form.processed_data['reset_token']) if not user: form._error = ValidationError('invalid_token', {'value': ''}) return dict(next_path=next_path, form=form) username = user.username User.set_password(username, form.processed_data['password1']) if request.user.is_authenticated: request.user.logout() login_url = i18n_url('auth:login_form') + set_qparam( next=next_path).to_qs() return template( 'ui/feedback.tpl', # Translators, used as page title on feedback page page_title=_('New password was set'), # Translators, used as link label on feedback page in "You # will be taken to log-in page..." redirect_target=_('log-in page'), # Translators, shown after password has been changed message=_("Password for username '{username}' has been " "set.").format(username=username), status='success', redirect_url=login_url)
def reset(): next_path = request.params.get('next', '/') form = PasswordResetForm(request.params) if request.user.is_authenticated: # Set arbitrary non-empty value to prevent form error. We don't really # care about this field otherwise. form.reset_token.bind_value('not needed') if not form.is_valid(): return dict(next_path=next_path, form=form) if request.user.is_authenticated: username = request.user.username else: user = User.from_reset_token(form.processed_data['reset_token']) if not user: form._error = ValidationError('invalid_token', {'value': ''}) return dict(next_path=next_path, form=form) username = user.username User.set_password(username, form.processed_data['password1']) if request.user.is_authenticated: request.user.logout() login_url = i18n_url('auth:login_form') + set_qparam( next=next_path).to_qs() return template('ui/feedback.tpl', # Translators, used as page title on feedback page page_title=_('New password was set'), # Translators, used as link label on feedback page in "You # will be taken to log-in page..." redirect_target=_('log-in page'), # Translators, shown after password has been changed message=_("Password for username '{username}' has been " "set.").format(username=username), status='success', redirect_url=login_url)
def reset(): reset_token = request.params.get('reset_token') form = EmergencyResetForm(request.params) if not form.is_valid(): return dict(form=form, reset_token=reset_token) request.db.auth.execute(request.db.auth.Delete('users')) request.db.sessions.execute(request.db.sessions.Delete('sessions')) username = form.processed_data['username'] User.create(username, form.processed_data['password1'], is_superuser=True, db=request.db.auth, reset_token=reset_token) return template( 'ui/feedback.tpl', # Translators, used as page title on feedback page page_title=_('Emergency reset successful'), # Translators, used as link label on feedback page in "You # will be taken to log-in page..." redirect_target=_('log-in page'), # Translators, shown after emergency reset message=_("You may now log in as " "'{username}'.").format(username=username), status='success', redirect_url=i18n_url('auth:login_form'))
def wrapper(*args, **kwargs): if (not supervisor.exts.setup_wizard.is_completed and not any([request.path == path[len(request.locale) + 1:] for path in ignored_paths])): if request.is_xhr: return template(NO_XHR_TEMPLATE) return redirect(setup_path) return callback(*args, **kwargs)
def wizard_finished(self, data): setup_data = dict() for step, step_result in data.items(): setup_data.update(step_result) setup = request.app.supervisor.exts.setup setup.append(setup_data) result = template(self.finished_template, setup=setup) return result
def wizard_finished(self, data): setup_data = dict() for step, step_result in data.items(): setup_data.update(step_result) setup = request.app.supervisor.exts.setup setup.append(setup_data) result = template(self.finished_template, setup=setup) return result
def __call__(self): locale = getattr(request, 'locale', '_') key = '{0}_{1}'.format(self.__name__, locale) if request.app.supervisor.exts.is_installed('cache'): # use cache if available source = request.app.supervisor.exts.cache else: # fallback to in-memory dict source = self.versions rendered = source.get(key) if rendered is None: rendered = template(self.path) source.set(key, rendered) return rendered
def wrapper(path, **kwargs): manager = Manager(request.app.supervisor) if not manager.exists(path): # Translators, used as page title when a file's removal is # retried, but it was already deleted before title = _("File already removed") # Translators, used as message when a file's removal is # retried, but it was already deleted before message = _("The specified file has already been removed.") return template('feedback', status='success', page_title=title, message=message, redirect_url=get_parent_url(path), redirect_target=_("Files")) return func(path=path, **kwargs)
def wrapper(*args, **kwargs): target_host = netutils.get_target_host() if target_host not in domain_mappings: # No domain matches captive portal check return callback(*args, **kwargs) logging.debug('Matched captive portal host %s', target_host) # The domain_mappings map domain names to combination of # template name and status code (some captive portal detection # algorithms look for 204 status code instead of 200). template_name, status = domain_mappings[target_host].split(';') if status == '204': response = '' elif status == '302': return redirect(self_url, 302) else: response = template(template_name, {}) raise HTTPResponse(response, int(status))