From 198b77bc032ab059e01c380e8fd577297b997b62 Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Thu, 16 Nov 2017 14:02:19 +0100 Subject: [PATCH] add application name and slug in association context (#19649) --- mandayejs/applications.py | 12 ++++++++++++ mandayejs/mandaye/views.py | 6 +++--- tests/test_mandayejs.py | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/mandayejs/applications.py b/mandayejs/applications.py index ff02ff3..7125e41 100644 --- a/mandayejs/applications.py +++ b/mandayejs/applications.py @@ -24,6 +24,7 @@ from django.conf.urls import patterns, url from django.http import Http404 from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import resolve +from django.utils.text import slugify def get_app_settings(): @@ -75,6 +76,17 @@ class AppSettingsMeta(type): dct['SITE_LOGIN_PATH'] = os.path.join(dct['SITE_LOGIN_PATH_PREFIX'], parent.SITE_LOGIN_PATH.strip('/')) return super(AppSettingsMeta, cls).__new__(cls, name, bases, dct) + @property + def name(self): + app_name = getattr(settings, 'SITE_APP_NAME', None) + if app_name: + return app_name + return self.__name__ + + @property + def slug(self): + return slugify(self.__name__) + class AppSettings(object): __metaclass__ = AppSettingsMeta diff --git a/mandayejs/mandaye/views.py b/mandayejs/mandaye/views.py index f5bc1a3..053b604 100644 --- a/mandayejs/mandaye/views.py +++ b/mandayejs/mandaye/views.py @@ -123,10 +123,10 @@ def associate(request, *args, **kwargs): return HttpResponseRedirect(resolve_url('post-login')) else: form = FormFactory() - + app_settings = get_app_settings() response = render(request, 'mandaye/associate.html', { - 'form': form, - }) + 'form': form, 'app': { + 'name': app_settings.name, 'slug': app_settings.slug}}) return response diff --git a/tests/test_mandayejs.py b/tests/test_mandayejs.py index 8469337..26480b6 100644 --- a/tests/test_mandayejs.py +++ b/tests/test_mandayejs.py @@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse from mandayejs.mandaye.models import UserCredentials from mandayejs.mandaye.utils import exec_phantom from mandayejs.mandaye.forms import FormFactory -from mandayejs.mandaye.views import post_login_do +from mandayejs.mandaye.views import associate, post_login_do from utils import create_user, create_credentials, get_uuid, get_user @@ -409,3 +409,17 @@ def test_post_login_do_with_next_url(mocked_popen, user_john): request.user = user_john response = post_login_do(request) assert 'window.top.location = "http://example.net/"' in response.content + + +@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS) +def test_app_name_slug_in_association_context(settings, user_john): + client = Client() + client.login(username='john', password='john') + response = client.get(reverse('associate')) + assert response.context['app']['name'] == 'Test' + assert response.context['app']['slug'] == 'test' + # when overidding the appname in settings + settings.SITE_APP_NAME = 'Test A' + response = client.get(reverse('associate')) + assert response.context['app']['name'] == 'Test A' + assert response.context['app']['slug'] == 'test' -- 2.11.0