Exemple #1
0
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)}
Exemple #2
0
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)}
Exemple #3
0
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)}
Exemple #4
0
def stats_table(conversation,
                stats=None,
                data="votes",
                request=None,
                **kwargs):
    if stats is None:
        stats = conversation.statistics()

    get = COLUMN_NAMES.get
    return div([html_map({get(k, k): v}) for k, v in stats[data].items()],
               **kwargs).add_class("stat-slab", first=True)
Exemple #5
0
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)}
Exemple #6
0
 def test_render_html_map(self):
     assert (html_map({
         'foo': 'bar'
     }, class_='foo').__html__() ==
             '<dl class="foo"><dt>foo</dt><dd>bar</dd></dl>')