Révision def3bf44
Ajouté par Josué Kouka il y a plus de 6 ans
mandayejs/applications.py | ||
---|---|---|
24 | 24 |
from django.http import Http404 |
25 | 25 |
from django.core.exceptions import ImproperlyConfigured |
26 | 26 |
from django.core.urlresolvers import resolve |
27 |
from django.utils.text import slugify |
|
27 | 28 |
|
28 | 29 |
|
29 | 30 |
def get_app_settings(): |
... | ... | |
79 | 80 |
return value |
80 | 81 |
return super(AppSettings, self).__getattribute__(name) |
81 | 82 |
|
83 |
def get_name(self): |
|
84 |
name = getattr(settings, 'SITE_APP_NAME', None) |
|
85 |
if name: |
|
86 |
return name |
|
87 |
return type(self).__name__ |
|
88 |
|
|
89 |
def get_slug(self): |
|
90 |
return slugify(type(self).__name__) |
|
91 |
|
|
82 | 92 |
|
83 | 93 |
# Test App Settings |
84 | 94 |
class Test(AppSettings): |
mandayejs/mandaye/views.py | ||
---|---|---|
123 | 123 |
return HttpResponseRedirect(resolve_url('post-login')) |
124 | 124 |
else: |
125 | 125 |
form = FormFactory() |
126 |
|
|
126 |
app_settings = get_app_settings() |
|
127 | 127 |
response = render(request, 'mandaye/associate.html', { |
128 |
'form': form, |
|
129 |
}) |
|
128 |
'form': form, 'app': {
|
|
129 |
'name': app_settings.get_name(), 'slug': app_settings.get_slug()}})
|
|
130 | 130 |
return response |
131 | 131 |
|
132 | 132 |
|
tests/test_mandayejs.py | ||
---|---|---|
16 | 16 |
from mandayejs.mandaye.models import UserCredentials |
17 | 17 |
from mandayejs.mandaye.utils import exec_phantom, get_login_info |
18 | 18 |
from mandayejs.mandaye.forms import FormFactory |
19 |
from mandayejs.mandaye.views import post_login_do |
|
19 |
from mandayejs.mandaye.views import associate, post_login_do
|
|
20 | 20 |
|
21 | 21 |
from utils import create_user, create_credentials, get_uuid, get_user |
22 | 22 |
|
... | ... | |
442 | 442 |
data = get_login_info(request, cred_john) |
443 | 443 |
assert data['address'] == 'http://testserver/' |
444 | 444 |
assert data['form_submit_element'] == '' |
445 |
|
|
446 |
|
|
447 |
def test_app_name_slug_in_association_context(settings, user_john): |
|
448 |
client = Client() |
|
449 |
client.login(username='john', password='john') |
|
450 |
response = client.get(reverse('associate')) |
|
451 |
assert response.context['app']['name'] == 'Test' |
|
452 |
assert response.context['app']['slug'] == 'test' |
|
453 |
# when overidding the appname in settings |
|
454 |
settings.SITE_APP_NAME = 'Test A' |
|
455 |
response = client.get(reverse('associate')) |
|
456 |
assert response.context['app']['name'] == 'Test A' |
|
457 |
assert response.context['app']['slug'] == 'test' |
Formats disponibles : Unified diff
add application name and slug in association context (#19649)