From 4c8b173e950da7ffe22dc9d13f6ae59114d7a141 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 18 Jan 2015 16:05:29 +0100 Subject: [PATCH] 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 --- docs/changelog.rst | 3 + docs/code/userdbs.rst | 12 +++- .../templates/userdbs/snippets/db_type.html | 3 + .../userdbs/templatetags/__init__.py | 4 ++ gnuviechadmin/userdbs/templatetags/userdb.py | 55 +++++++++++++++++++ gnuviechadmin/userdbs/views.py | 3 - 6 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 gnuviechadmin/templates/userdbs/snippets/db_type.html create mode 100644 gnuviechadmin/userdbs/templatetags/__init__.py create mode 100644 gnuviechadmin/userdbs/templatetags/userdb.py delete mode 100644 gnuviechadmin/userdbs/views.py diff --git a/docs/changelog.rst b/docs/changelog.rst index 1cfa8bd..6290ed4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,9 @@ 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>` * :bug:`-` define proper allauth production settings with https and mandatory email verification diff --git a/docs/code/userdbs.rst b/docs/code/userdbs.rst index 7856a9d..3ca1778 100644 --- a/docs/code/userdbs.rst +++ b/docs/code/userdbs.rst @@ -23,8 +23,14 @@ .. automodule:: userdbs.models :members: +:py:mod:`templatetags ` +--------------------------------------------- -:py:mod:`views ` -------------------------------- +.. automodule:: userdbs.templatetags -.. automodule:: userdbs.views + +:py:mod:`userdb ` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. automodule:: userdbs.templatetags.userdb + :members: diff --git a/gnuviechadmin/templates/userdbs/snippets/db_type.html b/gnuviechadmin/templates/userdbs/snippets/db_type.html new file mode 100644 index 0000000..e6df7a5 --- /dev/null +++ b/gnuviechadmin/templates/userdbs/snippets/db_type.html @@ -0,0 +1,3 @@ +{# format database types #} +{% load userdb %} +{% db_type_name %} diff --git a/gnuviechadmin/userdbs/templatetags/__init__.py b/gnuviechadmin/userdbs/templatetags/__init__.py new file mode 100644 index 0000000..922a314 --- /dev/null +++ b/gnuviechadmin/userdbs/templatetags/__init__.py @@ -0,0 +1,4 @@ +""" +This module provides custom template tags for user databases. + +""" diff --git a/gnuviechadmin/userdbs/templatetags/userdb.py b/gnuviechadmin/userdbs/templatetags/userdb.py new file mode 100644 index 0000000..a8d52d4 --- /dev/null +++ b/gnuviechadmin/userdbs/templatetags/userdb.py @@ -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 + `_. + + :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) diff --git a/gnuviechadmin/userdbs/views.py b/gnuviechadmin/userdbs/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/gnuviechadmin/userdbs/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here.