lib: remove templatetags

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-03 12:16:55 +02:00
parent 94a5a6c4c0
commit eeb9449c11
14 changed files with 14 additions and 58 deletions

View File

@ -20,7 +20,6 @@ from authentik.core.api.utils import (
) )
from authentik.core.expression import PropertyMappingEvaluator from authentik.core.expression import PropertyMappingEvaluator
from authentik.core.models import PropertyMapping from authentik.core.models import PropertyMapping
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
from authentik.managed.api import ManagedSerializer from authentik.managed.api import ManagedSerializer
from authentik.policies.api.exec import PolicyTestSerializer from authentik.policies.api.exec import PolicyTestSerializer
@ -87,9 +86,10 @@ class PropertyMappingViewSet(
"""Get all creatable property-mapping types""" """Get all creatable property-mapping types"""
data = [] data = []
for subclass in all_subclasses(self.queryset.model): for subclass in all_subclasses(self.queryset.model):
subclass: PropertyMapping
data.append( data.append(
{ {
"name": verbose_name(subclass), "name": subclass._meta.verbose_name,
"description": subclass.__doc__, "description": subclass.__doc__,
"component": subclass.component, "component": subclass.component,
} }

View File

@ -11,7 +11,6 @@ from rest_framework.viewsets import GenericViewSet
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
from authentik.core.models import Provider from authentik.core.models import Provider
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
@ -73,9 +72,10 @@ class ProviderViewSet(
"""Get all creatable provider types""" """Get all creatable provider types"""
data = [] data = []
for subclass in all_subclasses(self.queryset.model): for subclass in all_subclasses(self.queryset.model):
subclass: Provider
data.append( data.append(
{ {
"name": verbose_name(subclass), "name": subclass._meta.verbose_name,
"description": subclass.__doc__, "description": subclass.__doc__,
"component": subclass().component, "component": subclass().component,
} }

View File

@ -13,7 +13,6 @@ from structlog.stdlib import get_logger
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
from authentik.core.models import Source from authentik.core.models import Source
from authentik.core.types import UserSettingSerializer from authentik.core.types import UserSettingSerializer
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
from authentik.policies.engine import PolicyEngine from authentik.policies.engine import PolicyEngine
@ -67,9 +66,11 @@ class SourceViewSet(
"""Get all creatable source types""" """Get all creatable source types"""
data = [] data = []
for subclass in all_subclasses(self.queryset.model): for subclass in all_subclasses(self.queryset.model):
subclass: Source
# pyright: reportGeneralTypeIssues=false
data.append( data.append(
{ {
"name": verbose_name(subclass), "name": subclass._meta.verbose_name,
"description": subclass.__doc__, "description": subclass.__doc__,
"component": subclass().component, "component": subclass().component,
} }

View File

@ -1,6 +1,5 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load authentik_utils %}
<!DOCTYPE html> <!DOCTYPE html>

View File

@ -1,7 +1,6 @@
{% extends 'base/skeleton.html' %} {% extends 'base/skeleton.html' %}
{% load i18n %} {% load i18n %}
{% load authentik_utils %}
{% block head %} {% block head %}
{{ block.super }} {{ block.super }}

View File

@ -2,7 +2,6 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load authentik_utils %}
{% block body %} {% block body %}
<div class="pf-c-background-image"> <div class="pf-c-background-image">

View File

@ -14,7 +14,6 @@ from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
from authentik.core.types import UserSettingSerializer from authentik.core.types import UserSettingSerializer
from authentik.flows.api.flows import FlowSerializer from authentik.flows.api.flows import FlowSerializer
from authentik.flows.models import Stage from authentik.flows.models import Stage
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
LOGGER = get_logger() LOGGER = get_logger()
@ -68,9 +67,10 @@ class StageViewSet(
"""Get all creatable stage types""" """Get all creatable stage types"""
data = [] data = []
for subclass in all_subclasses(self.queryset.model, False): for subclass in all_subclasses(self.queryset.model, False):
subclass: Stage
data.append( data.append(
{ {
"name": verbose_name(subclass), "name": subclass._meta.verbose_name,
"description": subclass.__doc__, "description": subclass.__doc__,
"component": subclass().component, "component": subclass().component,
} }

View File

@ -1,40 +0,0 @@
"""authentik lib Templatetags"""
from django import template
from django.db.models import Model
from structlog.stdlib import get_logger
register = template.Library()
LOGGER = get_logger()
@register.filter("fieldtype")
def fieldtype(field):
"""Return classname"""
if isinstance(field.__class__, Model) or issubclass(field.__class__, Model):
return verbose_name(field)
return field.__class__.__name__
@register.filter(name="css_class")
def css_class(field, css):
"""Add css class to form field"""
return field.as_widget(attrs={"class": css})
@register.filter
def verbose_name(obj) -> str:
"""Return Object's Verbose Name"""
if not obj:
return ""
if hasattr(obj, "verbose_name"):
return obj.verbose_name
return obj._meta.verbose_name
@register.filter
def form_verbose_name(obj) -> str:
"""Return ModelForm's Object's Verbose Name"""
if not obj:
return ""
return verbose_name(obj._meta.model)

View File

@ -19,7 +19,6 @@ from authentik.core.api.utils import (
PassiveSerializer, PassiveSerializer,
TypeCreateSerializer, TypeCreateSerializer,
) )
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
from authentik.outposts.models import ( from authentik.outposts.models import (
DockerServiceConnection, DockerServiceConnection,
@ -76,9 +75,11 @@ class ServiceConnectionViewSet(
"""Get all creatable service connection types""" """Get all creatable service connection types"""
data = [] data = []
for subclass in all_subclasses(self.queryset.model): for subclass in all_subclasses(self.queryset.model):
subclass: OutpostServiceConnection
# pyright: reportGeneralTypeIssues=false
data.append( data.append(
{ {
"name": verbose_name(subclass), "name": subclass._meta.verbose_name,
"description": subclass.__doc__, "description": subclass.__doc__,
"component": subclass().component, "component": subclass().component,
} }

View File

@ -18,7 +18,6 @@ from authentik.core.api.utils import (
MetaNameSerializer, MetaNameSerializer,
TypeCreateSerializer, TypeCreateSerializer,
) )
from authentik.lib.templatetags.authentik_utils import verbose_name
from authentik.lib.utils.reflection import all_subclasses from authentik.lib.utils.reflection import all_subclasses
from authentik.policies.api.exec import PolicyTestResultSerializer, PolicyTestSerializer from authentik.policies.api.exec import PolicyTestResultSerializer, PolicyTestSerializer
from authentik.policies.models import Policy, PolicyBinding from authentik.policies.models import Policy, PolicyBinding
@ -100,9 +99,10 @@ class PolicyViewSet(
"""Get all creatable policy types""" """Get all creatable policy types"""
data = [] data = []
for subclass in all_subclasses(self.queryset.model): for subclass in all_subclasses(self.queryset.model):
subclass: Policy
data.append( data.append(
{ {
"name": verbose_name(subclass), "name": subclass._meta.verbose_name,
"description": subclass.__doc__, "description": subclass.__doc__,
"component": subclass().component, "component": subclass().component,
} }

View File

@ -2,7 +2,6 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load authentik_utils %}
{% block card_title %} {% block card_title %}
{% trans 'Permission denied' %} {% trans 'Permission denied' %}

View File

@ -2,7 +2,6 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load authentik_utils %}
{% block head %} {% block head %}
{{ block.super }} {{ block.super }}

View File

@ -1,6 +1,5 @@
{% extends "email/base.html" %} {% extends "email/base.html" %}
{% load authentik_utils %}
{% load i18n %} {% load i18n %}
{% load humanize %} {% load humanize %}