diff --git a/SciPost_v1/settings.py b/SciPost_v1/settings.py index 66601f8063a94a36a6fb7b0024f3d14241da9ae5..ee7a399af4765c4c09a86a7346b97f78f59c867a 100644 --- a/SciPost_v1/settings.py +++ b/SciPost_v1/settings.py @@ -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, ...) import os - import json +from django.utils.translation import ugettext_lazy as _ + + 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)) # Quick-start development settings - unsuitable for production @@ -108,6 +110,7 @@ MATHJAX_CONFIG_DATA = { MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -128,6 +131,7 @@ TEMPLATES = [ 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', + 'django.template.context_processors.i18n', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'scipost.context_processors.searchform', @@ -158,7 +162,12 @@ DATABASES = { # https://docs.djangoproject.com/en/1.8/topics/i18n/ LANGUAGE_CODE = 'en-us' - +LANGUAGES = ( + ('en', _('English')), +) +LOCALE_PATHS = ( + os.path.join(BASE_DIR, 'locale'), +) TIME_ZONE = 'CET' USE_I18N = True diff --git a/scipost/templates/scipost/base.html b/scipost/templates/scipost/base.html index 23a60758b0fdf262600e580d527bc61a30306e2e..607302218daf633d82de877294a23a9d97042172 100644 --- a/scipost/templates/scipost/base.html +++ b/scipost/templates/scipost/base.html @@ -26,6 +26,7 @@ <body> {% include 'scipost/header.html' %} {% include 'scipost/navbar.html' %} + {% include 'scipost/messages.html' %} {% block bodysup %} {% endblock bodysup %} diff --git a/scipost/templates/scipost/messages.html b/scipost/templates/scipost/messages.html new file mode 100644 index 0000000000000000000000000000000000000000..ac8c6dff8c12a6bea16bcdaca31738d52cd55336 --- /dev/null +++ b/scipost/templates/scipost/messages.html @@ -0,0 +1,8 @@ +{% 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">×</span> + </button> + {{ message }} + </div> +{% endfor %} diff --git a/strings/__init__.py b/strings/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..82d957c9dde2ab9c1606aa3568f778e408e13a84 --- /dev/null +++ b/strings/__init__.py @@ -0,0 +1 @@ +acknowledge_request_thesis_link = "Thank you for your request for a Thesis Link. Your request will soon be handled by an editor" diff --git a/theses/test_views.py b/theses/test_views.py index 7e70a6dd41170d221dfd8a4d586a4a8b0ff0c38c..a3283c7318043a1d9313f06aa7a5c1ff46385511 100644 --- a/theses/test_views.py +++ b/theses/test_views.py @@ -36,7 +36,3 @@ class TestRequestThesisLink(TestCase): request.user = UserFactory() response = RequestThesisLink.as_view()(request) 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')) diff --git a/theses/views.py b/theses/views.py index b6136f783aa24c65c53e8c07952e470ea307155f..cb9ce0edc9a179a5ad2ab0a47e625064300c691c 100644 --- a/theses/views.py +++ b/theses/views.py @@ -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.decorators import login_required, permission_required from django.contrib.auth.models import User +from django.contrib import messages 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.views.decorators.csrf import csrf_protect from django.db.models import Avg @@ -33,15 +34,12 @@ title_dict = dict(TITLE_CHOICES) # Convert titles for use in emails class RequestThesisLink(CreateView): form_class = RequestThesisLinkForm template_name = 'theses/request_thesislink.html' - success_url = '' + success_url = reverse_lazy('scipost:personal_page') def form_valid(self, form): - context = {'ack_header': 'Thank you for your request for a Thesis Link', - 'ack_message': 'Your request will soon be handled by an Editor. ', - 'followup_message': 'Return to your ', - 'followup_link': reverse('scipost:personal_page'), - 'followup_link_label': 'personal page'} - return render(self.request, 'scipost/acknowledgement.html', context) + messages.add_message(self.request, messages.SUCCESS, + strings.acknowledge_request_thesis_link) + return super(RequestThesisLink, self).form_valid(form) @permission_required('scipost.can_vet_thesislink_requests', raise_exception=True)