def on_forbidden_corpus(self, plugin_api, corpname, corp_variant): if self.is_anonymous(plugin_api.user_id): raise ImmediateRedirectException( '{0}{1}first_form?corpname={2}'.format(self.get_login_url(), plugin_api.root_url, corpname)) else: super(FederatedAuthWithFailover, self).on_forbidden_corpus( plugin_api, corpname, corp_variant)
def pre_dispatch(self, plugin_api, action_name, action_metadata, request): # Recent KonText versions avoid specifying corpus variant directly in URL but # we still have to handle external links if action_name in ('query', 'view'): corp = request.args.get('corpname') if corp is not None and corp.startswith('omezeni/'): logging.getLogger(__name__).warning( 'Handling legacy action URL for {0}'.format(action_name)) raise ImmediateRedirectException( plugin_api.updated_current_url(dict(corpname=corp[len('omezeni/'):])))
def sign_up_confirm_email(self, request): with plugins.runtime.AUTH as auth: try: key = request.args['key'] ans = dict(sign_up_url=self.create_url('user/sign_up_form', {})) ans.update(auth.sign_up_confirm(self._plugin_api, key)) return ans except SignUpNeedsUpdateException as ex: logging.getLogger(__name__).warning(ex) raise ImmediateRedirectException(self.create_url('user/sign_up_form', dict(key=key, username_taken=1)))
def on_forbidden_corpus(self, plugin_ctx: 'PluginCtx', corpname: str, corp_variant: str): """ Optional method run in case KonText finds out that user does not have access rights to a corpus specified by 'corpname'. There are two main action types you can perform here: 1) Redirect to a different page or set 'not found'. 2) Set some system message user can read. """ if corpname: raise CorpusForbiddenException(corpname, corp_variant) else: # no default accessible corpus for the current user raise ImmediateRedirectException( plugin_ctx.create_url('corpora/corplist', {}))
def index(self, request: werkzeug.Request): try: conc = require_existing_conc(self.corp, self.args.q) except ConcNotFoundException: args = list(self._request.args.items()) + [('next', 'dispersion')] raise ImmediateRedirectException( self.create_url('restore_conc', args)) resolution = request.args.get('resolution', 100, type=int) if resolution > 1000: resolution = 1000 elif resolution < 1: resolution = 1 return { 'dispersion_resolution': resolution, 'initial_data': self._get_freq_dispersion(conc, resolution), }