def load_template(url_hash): global _current_form form = get_open_form() current_cls = type(form) if form is not None and current_cls not in _templates: raise NavigationExit # not using templates logger.debug("Checking routing templates") for cls, path, condition in chain.from_iterable( _ordered_templates.values()): if not url_hash.startswith(path): continue if condition is None: break elif condition(): break else: load_error_or_raise(f"No template for {url_hash!r}") if current_cls is cls: logger.debug(f"{cls.__name__!r} routing template unchanged") else: logger.debug( f"{current_cls.__name__!r} routing template changed to {cls.__name__!r}, exiting this navigation call" ) _current_form = None f = cls() logger.debug(f"form template loaded {cls.__name__!r}, re-navigating") open_form(f) raise NavigationExit
def load_template_or_redirect(url_hash): global _current_form form = get_open_form() current_cls = type(form) if form is not None and current_cls not in _templates: raise NavigationExit # not using templates logger.debug("checking templates and redirects") for info in chain.from_iterable(_ordered_info.values()): callable_, paths, condition = info try: path = next(path for path in paths if url_hash.startswith(path)) except StopIteration: continue if condition is None: break elif not condition(): continue elif type(info) is TemplateInfo: break redirect_hash = callable_() if isinstance(redirect_hash, str): if navigation_context.matches_current_context(redirect_hash): # would cause an infinite loop logger.debug("redirect returned current url_hash, ignoring") continue from . import set_url_hash logger.debug(f"redirecting to url_hash: {redirect_hash!r}") set_url_hash( redirect_hash, set_in_history=False, redirect=True, replace_current_url=True, ) navigation_context.check_stale() else: load_error_or_raise(f"no template for url_hash={url_hash!r}") if current_cls is callable_: logger.debug(f"unchanged template: {callable_.__name__!r}") return info, path else: msg = f"changing template: {current_cls.__name__!r} -> {callable_.__name__!r}" logger.debug(msg) _current_form = None # mark context as stale so that this context is no longer considered the current context navigation_context.mark_all_stale() f = callable_() logger.debug(f"loaded template: {callable_.__name__!r}, re-navigating") open_form(f) raise NavigationExit
def load_error_form(): global _error_form, _current_form logger.debug(f"loading error form: {_error_form!r}") url_hash, _, _ = get_url_components() _cache[url_hash] = _error_form() _current_form = _cache[url_hash] f = get_open_form() if f is not None: add_form_to_container(_current_form) else: open_form(_current_form ) # just in case we somehow don't have a valid template!
def form_show(self, **event_args): anvil.users.login_with_form() open_form("Main")
def _set_pagination_handlers(data_grid, handler): grid_dom = _js.get_dom_node(data_grid) for name in ["first", "last", "previous", "next"]: btn = grid_dom.querySelector(f".{name}-page") # use True so that we capture this event before the anvil click event btn.addEventListener("click", _prevent_disabled, True) btn.addEventListener( "click", _wrap_js_event( _partial( handler, sender=data_grid, button=name, event_name="pagination_click", )), ) # note we don't tidy this up - we should probably call removeEventListener # but this will be called from code and is unlikely that the user will call this function twice if __name__ == "__main__": _ = _anvil.ColumnPanel() _.set_event_handler( "show", lambda **e: _anvil.Notification("oops AnvilAugment is a dependency", timeout=None).show(), ) _anvil.open_form(_) _ = None
def logout_link_click(self, **event_args): anvil.users.logout() anvil.open_form("Login")
from anvil import open_form from . import content_forms {% if cookiecutter.with_authorisation == "yes" %} import anvil.users if anvil.users.get_user(): open_form("Main") else: open_form("Login") {% else %} open_form("Main") {% endif %}