def role_index(): data = [] classes = set() # Collect all models and roles in the default render registry for (cls, __) in html.registry: if not issubclass(cls, Model) or cls in classes: continue classes.add(cls) name = cls.__name__ href = reverse("role-model", kwargs={"model": name.lower()}) data.append((name, span([a(name, href=href), ": " + get_doc(cls)]))) # Now we collect the queryset renderers classes = set() for (cls, __) in register_queryset.registry: classes.add(cls) name = cls.__name__ href = reverse("role-model-queryset", kwargs={"model": name.lower()}) data.append([ name + " (queryset)", span([a(name, href=href), ": " + get_doc(cls)]) ]) return {"data": html_map(data)}
def role_index(): data = [] classes = set() # Collect all models and roles in the default render registry for (cls, __) in render.registry: if not issubclass(cls, Model) or cls in classes: continue classes.add(cls) name = cls.__name__ href = reverse('role-model', kwargs={'model': name.lower()}) data.append((name, span([a(name, href=href), ': ' + cls.__doc__]))) # Now we collect the queryset renderers classes = set() for (cls, __) in register_queryset.registry: classes.add(cls) name = cls.__name__ href = reverse('role-model-queryset', kwargs={'model': name.lower()}) data.append([ name + ' (queryset)', span([a(name, href=href), ': ' + cls.__doc__]), ]) return {'data': html_map(data)}
def render_collapsible(lst, item_role='collapsible-item', title=None, expanded=False, **kwargs): """ Renders a queryset or list of objects Args: lst: List or queryset of objects inside the collapsible list. item_role: Role assigned to each element in the list. Defaults to 'collapsible-item'. title (bool): Title in which the list of object is displayed. expanded (str): If true, start list in the "expanded" state. """ if title is None: if isinstance(lst, QuerySet): title = title.model._meta.verbose_name_plural else: raise TypeError('must provide an explicit title!') data = [render(x, item_role, **kwargs) for x in lst] random_id = str(uuid.uuid4()) display = 'block' if expanded else 'none' return div( class_='CollapsibleList' )[h2(onclick=f"$('#{random_id}').toggle()", children=[title, span(f'({len(data)})'), fa_icon('angle-down')]), html_list(data, style=f'display: {display}', id=random_id), ]
def render_collapsible(lst, item_role='collapsible-item', title=None, expanded=False, **kwargs): """ Renders a queryset or list of objects Args: lst: List or queryset of objects inside the collapsible list. item_role: Role assigned to each element in the list. Defaults to 'collapsible-item'. title (bool): Title in which the list of object is displayed. expanded (str): If true, start list in the "expanded" state. """ if title is None: if isinstance(lst, QuerySet): title = title.model._meta.verbose_name_plural else: raise TypeError('must provide an explicit title!') data = [html(x, item_role, **kwargs) for x in lst] return div(class_='CollapsibleList', is_component=True)[ h2([title, span(f'({len(data)})' ), fa_icon('angle-up')]), div(class_='CollapsibleList-data')[html_list(data), ]]
def role_model_list(request, model, role): cls = get_class(model) kwargs = query_to_kwargs(request) size = kwargs.pop("size", 10) data = [] for idx, obj in enumerate(cls.objects.all()[:size], 1): link = reverse("role-model-instance", kwargs={"model": model, "role": role, "id": obj.id}) key = span([f"{idx}) ", a(str(obj), href=link)]) data.append((key, html(obj, role, **kwargs))) return {"data": html_map(data)}
def decorated_text(text, icon, style=None, href=None, **kwargs): """ This element is a simple text with an icon placed on the left hand side. If style='accent', it decorates the icon with the accent color. Style can also be href can be given towraps content inside an <a> tag. """ return a_or_span(class_='DecoratedText', href=href, **kwargs)[_icon(icon), span(text)]
def role_model_list(request, model, role): cls = get_class(model) kwargs = query_to_kwargs(request) size = kwargs.pop('size', 10) data = [] for idx, obj in enumerate(cls.objects.all()[:size], 1): link = reverse('role-model-instance', kwargs={'model': model, 'role': role, 'id': obj.id}) key = span([f'{idx}) ', a(str(obj), href=link)]) data.append((key, html(obj, role, **kwargs))) return {'data': html_map(data)}
def collapsible_list(lst, item_role="list-item", title=None, **kwargs): """ Renders a queryset or list of objects Args: lst: List or queryset of objects inside the collapsible list. item_role: Role assigned to each element in the list. Defaults to 'list-item'. title (bool): Title in which the list of object is displayed. expanded (str): If true, start list in the "expanded" state. """ size = len(lst) title = _title(lst) if title is None else title title = Block([title, span(f" ({size})", class_="text-accent")]) items = [html(x, item_role, **kwargs) for x in lst] data = html_list(items, class_="list-reset") return collapsible(data, title=title)