SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 72ad07f3 authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

Use django.contrib.messages to handle acknowledgement

The acknowledgement message is no longer hardcoded in
theses/views.py, but resides in the top-level strings module.
parent 194337f6
No related branches found
No related tags found
No related merge requests found
...@@ -12,12 +12,14 @@ https://docs.djangoproject.com/en/1.8/ref/settings/ ...@@ -12,12 +12,14 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
import json import json
from django.utils.translation import ugettext_lazy as _
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
host_settings_path = os.path.join(os.path.dirname(BASE_DIR),"scipost-host-settings.json") host_settings_path = os.path.join(os.path.dirname(BASE_DIR), "scipost-host-settings.json")
host_settings = json.load(open(host_settings_path)) host_settings = json.load(open(host_settings_path))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
...@@ -94,6 +96,7 @@ MATHJAX_CONFIG_DATA = { ...@@ -94,6 +96,7 @@ MATHJAX_CONFIG_DATA = {
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
...@@ -114,6 +117,7 @@ TEMPLATES = [ ...@@ -114,6 +117,7 @@ TEMPLATES = [
'context_processors': [ 'context_processors': [
'django.template.context_processors.debug', 'django.template.context_processors.debug',
'django.template.context_processors.request', 'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'scipost.context_processors.searchform', 'scipost.context_processors.searchform',
...@@ -144,7 +148,12 @@ DATABASES = { ...@@ -144,7 +148,12 @@ DATABASES = {
# https://docs.djangoproject.com/en/1.8/topics/i18n/ # https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
LANGUAGES = (
('en', _('English')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
TIME_ZONE = 'CET' TIME_ZONE = 'CET'
USE_I18N = True USE_I18N = True
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<body> <body>
{% include 'scipost/header.html' %} {% include 'scipost/header.html' %}
{% include 'scipost/navbar.html' %} {% include 'scipost/navbar.html' %}
{% include 'scipost/messages.html' %}
{% block bodysup %} {% block bodysup %}
{% endblock bodysup %} {% endblock bodysup %}
......
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
{{ message }}
</div>
{% endfor %}
acknowledge_request_thesis_link = "Thank you for your request for a Thesis Link. Your request will soon be handled by an editor"
...@@ -36,7 +36,3 @@ class TestRequestThesisLink(TestCase): ...@@ -36,7 +36,3 @@ class TestRequestThesisLink(TestCase):
request.user = UserFactory() request.user = UserFactory()
response = RequestThesisLink.as_view()(request) response = RequestThesisLink.as_view()(request)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_redirects_to_acknowledgement_page(self):
response = self.client.post(reverse('theses:request_thesislink'), {}, follow=True)
self.assertRedirects(response, reverse('scipost:acknowledgement'))
...@@ -5,8 +5,9 @@ from django.shortcuts import get_object_or_404, render ...@@ -5,8 +5,9 @@ from django.shortcuts import get_object_or_404, render
from django.contrib.auth import authenticate, login, logout from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib import messages
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.views.decorators.csrf import csrf_protect from django.views.decorators.csrf import csrf_protect
from django.db.models import Avg from django.db.models import Avg
...@@ -33,15 +34,12 @@ title_dict = dict(TITLE_CHOICES) # Convert titles for use in emails ...@@ -33,15 +34,12 @@ title_dict = dict(TITLE_CHOICES) # Convert titles for use in emails
class RequestThesisLink(CreateView): class RequestThesisLink(CreateView):
form_class = RequestThesisLinkForm form_class = RequestThesisLinkForm
template_name = 'theses/request_thesislink.html' template_name = 'theses/request_thesislink.html'
success_url = '' success_url = reverse_lazy('scipost:personal_page')
def form_valid(self, form): def form_valid(self, form):
context = {'ack_header': 'Thank you for your request for a Thesis Link', messages.add_message(self.request, messages.SUCCESS,
'ack_message': 'Your request will soon be handled by an Editor. ', strings.acknowledge_request_thesis_link)
'followup_message': 'Return to your ', return super(RequestThesisLink, self).form_valid(form)
'followup_link': reverse('scipost:personal_page'),
'followup_link_label': 'personal page'}
return render(self.request, 'scipost/acknowledgement.html', context)
@permission_required('scipost.can_vet_thesislink_requests', raise_exception=True) @permission_required('scipost.can_vet_thesislink_requests', raise_exception=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment