0001-misc-ask-for-most-important-parameters-on-home-page-.patch
hobo/templates/hobo/home.html | ||
---|---|---|
20 | 20 |
<li><a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a></li> |
21 | 21 |
<li><a href="{% url 'debug-home' %}">{% trans 'Debugging' %}</a></li> |
22 | 22 |
</ul> |
23 | 23 |
</span> |
24 | 24 |
{% endblock %} |
25 | 25 | |
26 | 26 |
{% block content %} |
27 | 27 | |
28 |
{% if not has_global_title %} |
|
29 |
<div class="warningnotice"> |
|
30 |
<p class="action"> |
|
31 |
<span class="action-label"> |
|
32 |
{% trans 'You have not yet defined a name for the platform; the generic title "Compte Citoyen" is used.' %} |
|
33 |
</span> |
|
34 |
<a class="action-button" href="{% url 'theme-options' %}">{% trans 'Set up a title' %}</a> |
|
35 |
</p> |
|
36 |
</div> |
|
37 |
{% endif %} |
|
38 |
{% if not has_default_from_email %} |
|
39 |
<div class="warningnotice"> |
|
40 |
<p class="action"> |
|
41 |
<span class="action-label"> |
|
42 |
{% trans "You have not yet defined an address for emails sent by Publik." %} |
|
43 |
</span> |
|
44 |
<a class="action-button" href="{% url 'emails-home' %}">{% trans 'Set up email options' %}</a> |
|
45 |
</p> |
|
46 |
</div> |
|
47 |
{% endif %} |
|
48 | ||
28 | 49 |
{% if services %} |
29 | 50 |
<div class="services"> |
30 | 51 |
{% for service in services %} |
31 | 52 |
<a href="{{ service.base_url }}" class="service-link" data-service-slug="{{ service.slug }}"> |
32 | 53 |
<div class="service" data-service-slug="{{ service.slug }}"> |
33 | 54 |
<h3 class="service-title">{{ service.title }} <span class="service-url">{{ service.base_url }}</span></h3> |
34 | 55 |
<p class="service-status-items"> |
35 | 56 |
<span class="checking">{% trans "checking..." %}</span> |
hobo/views.py | ||
---|---|---|
9 | 9 |
from django.core.exceptions import PermissionDenied |
10 | 10 |
from django.urls import reverse |
11 | 11 |
from django.contrib.auth.decorators import user_passes_test |
12 | 12 |
from django.contrib.auth import logout as auth_logout |
13 | 13 |
from django.contrib.auth import views as auth_views |
14 | 14 |
from django.shortcuts import resolve_url |
15 | 15 |
from django.utils.encoding import force_text |
16 | 16 | |
17 |
from .environment.models import Authentic |
|
17 |
from .environment.models import Authentic, Variable
|
|
18 | 18 |
from .environment.utils import Zone, get_installed_services |
19 | 19 |
from .forms import HoboForm, HoboUpdateForm, get_tenant_model |
20 | 20 | |
21 | 21 |
def is_superuser(u): |
22 | 22 |
if not u.is_authenticated: |
23 | 23 |
return False |
24 | 24 |
if not u.is_superuser: |
25 | 25 |
raise PermissionDenied |
... | ... | |
29 | 29 | |
30 | 30 |
class Home(TemplateView): |
31 | 31 |
template_name = 'hobo/home.html' |
32 | 32 | |
33 | 33 |
def get_context_data(self, **kwargs): |
34 | 34 |
context = super(Home, self).get_context_data(**kwargs) |
35 | 35 |
context['services'] = [x for x in get_installed_services() if not x.secondary] |
36 | 36 |
context['has_authentic'] = bool(Authentic.objects.filter(secondary=False)) |
37 |
context['has_global_title'] = Variable.objects.filter(name='global_title').exists() |
|
38 |
context['has_default_from_email'] = Variable.objects.filter( |
|
39 |
name='default_from_email').exists() |
|
37 | 40 |
return context |
38 | 41 | |
39 | 42 |
home = admin_required(Home.as_view()) |
40 | 43 | |
41 | 44 | |
42 | 45 |
def hobo(request, **kwargs): |
43 | 46 |
# The hobos URL is supposed to return a list of hobo websites, this |
44 | 47 |
# dummy implementation makes it possible to point deployment agents to |
tests/test_home_views.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
import json |
3 | 3 |
import mock |
4 | 4 |
import pytest |
5 | 5 |
import re |
6 | 6 | |
7 | 7 |
from django.contrib.auth.models import User |
8 | 8 | |
9 |
from hobo.environment.models import Authentic |
|
9 |
from hobo.environment.models import Authentic, Variable
|
|
10 | 10 | |
11 | 11 |
from test_manager import login |
12 | 12 | |
13 | 13 |
pytestmark = pytest.mark.django_db |
14 | 14 | |
15 | 15 | |
16 | 16 |
@pytest.fixture |
17 | 17 |
def user(db): |
... | ... | |
92 | 92 |
resp = app.get('/menu.json') |
93 | 93 |
assert resp.content_type == 'application/json' |
94 | 94 |
assert resp.json == expected |
95 | 95 | |
96 | 96 |
resp = app.get('/menu.json?callback=foo') |
97 | 97 |
assert resp.content_type == 'application/javascript' |
98 | 98 |
json_str = re.match(r'foo\((.*)\)', resp.text).group(1) |
99 | 99 |
assert json.loads(json_str) == expected |
100 | ||
101 |
def test_warning_notifications(app, admin_user): |
|
102 |
app = login(app) |
|
103 |
resp = app.get('/') |
|
104 |
assert len(resp.html.find_all('div', {'class': 'warningnotice'})) == 2 |
|
105 | ||
106 |
assert resp.html.find('div', {'class': 'warningnotice'}).a['href'] == '/theme/options' |
|
107 |
Variable.objects.create(name='global_title', value='Publik') |
|
108 |
resp = app.get('/') |
|
109 |
assert len(resp.html.find_all('div', {'class': 'warningnotice'})) == 1 |
|
110 | ||
111 |
assert resp.html.find('div', {'class': 'warningnotice'}).a['href'] == '/emails/' |
|
112 |
Variable.objects.create(name='default_from_email', value='publik@example.com') |
|
113 |
resp = app.get('/') |
|
114 |
assert not resp.html.find_all('div', {'class': 'warningnotice'}) |
|
100 |
- |