add userdb template tags
- add changelog entry - add generated documentation for userdbs.templatetags.userdb - add userdb template tags db_type_icon_class and db_type_name - remove empty userdbs.views
This commit is contained in:
parent
56675f6c4d
commit
4c8b173e95
6 changed files with 74 additions and 6 deletions
4
gnuviechadmin/userdbs/templatetags/__init__.py
Normal file
4
gnuviechadmin/userdbs/templatetags/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
"""
|
||||
This module provides custom template tags for user databases.
|
||||
|
||||
"""
|
55
gnuviechadmin/userdbs/templatetags/userdb.py
Normal file
55
gnuviechadmin/userdbs/templatetags/userdb.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
"""
|
||||
This is the template tag library for user databases.
|
||||
|
||||
"""
|
||||
|
||||
from django import template
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from userdbs.models import DB_TYPES
|
||||
|
||||
register = template.Library()
|
||||
|
||||
_TYPE_NAME_MAP = {
|
||||
DB_TYPES.mysql: 'mysql',
|
||||
DB_TYPES.pgsql: 'postgres',
|
||||
}
|
||||
|
||||
|
||||
def db_type_icon_class(context):
|
||||
"""
|
||||
This template tag derives the matching icon name for the numeric database
|
||||
type stored in the context variable db_type.
|
||||
|
||||
The icon names used are those of `Font Mfizz
|
||||
<http://mfizz.com/oss/font-mfizz>`_.
|
||||
|
||||
:param context: the template context
|
||||
:return: icon name
|
||||
:rtype: str
|
||||
|
||||
"""
|
||||
db_type = context['db_type']
|
||||
if db_type in _TYPE_NAME_MAP:
|
||||
return 'icon-' + _TYPE_NAME_MAP[db_type]
|
||||
return 'icon-database'
|
||||
|
||||
|
||||
register.simple_tag(db_type_icon_class, takes_context=True)
|
||||
|
||||
|
||||
def db_type_name(context):
|
||||
"""
|
||||
This template tag gets the human readable database type for the numeric
|
||||
database type stored in the context variable db_type.
|
||||
|
||||
:param context: the template context
|
||||
:return: human readable database type name
|
||||
:rtype: str
|
||||
|
||||
"""
|
||||
db_type = context['db_type']
|
||||
return _(DB_TYPES[db_type])
|
||||
|
||||
|
||||
register.simple_tag(db_type_name, takes_context=True)
|
|
@ -1,3 +0,0 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Add table
Add a link
Reference in a new issue