Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Remove the import success view in favor of a msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Maupetit committed Jun 8, 2017
1 parent a584023 commit be8b972
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 50 deletions.
12 changes: 11 additions & 1 deletion td_biblio/templates/_layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@
<body class="{% block page_class %}{% endblock page_class %}">
{% block body %}
<header id="page-header">
<h1>Publications</h1>
<h1>TailorDev Biblio</h1>
</header>

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}

<div role="main">
{% block content %}{% endblock content %}
</div>
Expand Down
17 changes: 0 additions & 17 deletions td_biblio/templates/td_biblio/entry_import_success.html

This file was deleted.

33 changes: 13 additions & 20 deletions td_biblio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase
Expand Down Expand Up @@ -316,7 +317,7 @@ def test_post(self):
username=self.superuser.username,
password=self.fake_password
)

self.assertEqual(Entry.objects.count(), 0)

data = {
Expand All @@ -333,24 +334,16 @@ def test_post(self):
response = self.client.post(self.url, data, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(
'td_biblio/entry_import_success.html'
'td_biblio/entry_list.html'
)


class EntryBatchImportSuccessViewTests(TestCase):
"""
Tests for the EntryBatchImportSuccessView
"""

def setUp(self):
self.url = reverse('td_biblio:import_success')

def test_get(self):
"""
Test the EntryBatchImportSuccessView get method
"""
response = self.client.get(self.url)

# Standard response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed('td_biblio/entry_import_success.html')
# Test messages
response_messages = response.context['messages']
# We have two messages (we did the same request two times)
self.assertEqual(len(response_messages), 2)
for m in response_messages:
self.assertEqual(
str(m),
'We have successfully imported 4 references.'
)
self.assertEqual(m.level, messages.SUCCESS)
5 changes: 0 additions & 5 deletions td_biblio/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@
views.EntryBatchImportView.as_view(),
name='import'
),
url(
'^import/success$',
views.EntryBatchImportSuccessView.as_view(),
name='import_success'
),
]
18 changes: 11 additions & 7 deletions td_biblio/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
import datetime

from django.contrib import messages
from django.contrib.auth.mixins import UserPassesTestMixin
from django.core.urlresolvers import reverse_lazy
from django.views.generic import FormView, ListView, TemplateView
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView, ListView

from .forms import EntryBatchImportForm
from .models import Author, Collection, Entry, Journal
Expand Down Expand Up @@ -118,7 +120,7 @@ class EntryBatchImportView(UserPassesTestMixin, FormView):

form_class = EntryBatchImportForm
template_name = 'td_biblio/entry_import.html'
success_url = reverse_lazy('td_biblio:import_success')
success_url = reverse_lazy('td_biblio:entry_list')

def test_func(self):
"""Check that request user is a super user (admin)
Expand All @@ -145,9 +147,11 @@ def form_valid(self, form):
doi_loader.load_records(DOIs=dois)
doi_loader.save_records()

return super(EntryBatchImportView, self).form_valid(form)


class EntryBatchImportSuccessView(TemplateView):
messages.success(
self.request,
_("We have successfully imported {} references.").format(
len(dois) + len(pmids)
)
)

template_name = 'td_biblio/entry_import_success.html'
return super(EntryBatchImportView, self).form_valid(form)

0 comments on commit be8b972

Please sign in to comment.