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:
Jan Dittberner 2015-01-18 16:05:29 +01:00
parent 56675f6c4d
commit 4c8b173e95
6 changed files with 74 additions and 6 deletions

View file

@ -1,6 +1,9 @@
Changelog Changelog
========= =========
* :feature:`-` add template tags for database icons and human readable names in
:py:mod:`userdbs.templatetags.userdb`
* :release:`0.5.2 <2015-01-18>` * :release:`0.5.2 <2015-01-18>`
* :bug:`-` define proper allauth production settings with https and mandatory * :bug:`-` define proper allauth production settings with https and mandatory
email verification email verification

View file

@ -23,8 +23,14 @@
.. automodule:: userdbs.models .. automodule:: userdbs.models
:members: :members:
:py:mod:`templatetags <userdbs.templatetags>`
---------------------------------------------
:py:mod:`views <userdbs.views>` .. automodule:: userdbs.templatetags
-------------------------------
.. automodule:: userdbs.views
:py:mod:`userdb <userdbs.templatetags.userdb>`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: userdbs.templatetags.userdb
:members:

View file

@ -0,0 +1,3 @@
{# format database types #}
{% load userdb %}
<i class="{% db_type_icon_class %}" title="{% db_type_name %}"></i><span class="sr-only">{% db_type_name %}</span>

View file

@ -0,0 +1,4 @@
"""
This module provides custom template tags for user databases.
"""

View 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)

View file

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.