diff --git a/passbook/admin/templates/administration/provider/list.html b/passbook/admin/templates/administration/provider/list.html index 0887b0000..ace453870 100644 --- a/passbook/admin/templates/administration/provider/list.html +++ b/passbook/admin/templates/administration/provider/list.html @@ -57,6 +57,10 @@ {% trans name %} {% endfor %} + {% get_htmls provider as htmls %} + {% for html in htmls %} + {{ html|safe }} + {% endfor %} {% endfor %} diff --git a/passbook/admin/templatetags/admin_reflection.py b/passbook/admin/templatetags/admin_reflection.py index 8f3c112e6..7d4cbe302 100644 --- a/passbook/admin/templatetags/admin_reflection.py +++ b/passbook/admin/templatetags/admin_reflection.py @@ -5,6 +5,8 @@ from logging import getLogger from django import template from django.db.models import Model +from passbook.lib.utils.template import render_to_string + register = template.Library() LOGGER = getLogger(__name__) @@ -29,3 +31,24 @@ def get_links(model_instance): pass return links + + +@register.simple_tag(takes_context=True) +def get_htmls(context, model_instance): + """Find all html_ methods on an object instance, run them and return as dict""" + prefix = 'html_' + htmls = [] + + if not isinstance(model_instance, Model): + LOGGER.warning("Model %s is not instance of Model", model_instance) + return htmls + + try: + for name, method in inspect.getmembers(model_instance, predicate=inspect.ismethod): + if name.startswith(prefix): + template, _context = method(context.get('request')) + htmls.append(render_to_string(template, _context)) + except NotImplementedError: + pass + + return htmls diff --git a/passbook/oauth_provider/models.py b/passbook/oauth_provider/models.py index 8334050d2..a318eb88e 100644 --- a/passbook/oauth_provider/models.py +++ b/passbook/oauth_provider/models.py @@ -1,5 +1,6 @@ """Oauth2 provider product extension""" +from django.shortcuts import reverse from django.utils.translation import gettext as _ from oauth2_provider.models import AbstractApplication @@ -14,6 +15,20 @@ class OAuth2Provider(Provider, AbstractApplication): def __str__(self): return "OAuth2 Provider %s" % self.name + def html_setup_urls(self, request): + """return template and context modal with URLs for authorize, token, openid-config, etc""" + return "oauth2_provider/setup_url_modal.html", { + 'provider': self, + 'authorize_url': request.build_absolute_uri( + reverse('passbook_oauth_provider:oauth2-authorize')), + 'token_url': request.build_absolute_uri( + reverse('passbook_oauth_provider:token')), + 'userinfo_url': request.build_absolute_uri( + reverse('passbook_api:openid')), + 'openid_url': request.build_absolute_uri( + reverse('passbook_oauth_provider:openid-discovery')) + } + class Meta: verbose_name = _('OAuth2 Provider') diff --git a/passbook/oauth_provider/templates/oauth2_provider/setup_url_modal.html b/passbook/oauth_provider/templates/oauth2_provider/setup_url_modal.html new file mode 100644 index 000000000..b17f9ed7f --- /dev/null +++ b/passbook/oauth_provider/templates/oauth2_provider/setup_url_modal.html @@ -0,0 +1,49 @@ +{% load i18n %} + + + \ No newline at end of file