Skip to content

Commit

Permalink
Merge pull request #406 from erudit/1948-add-article-details
Browse files Browse the repository at this point in the history
1948 add article details
  • Loading branch information
cormier authored Oct 31, 2016
2 parents 65c455d + 695b0e6 commit c897db8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 27 deletions.
46 changes: 41 additions & 5 deletions eruditorg/apps/public/search/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from django.conf import settings
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.utils import translation
from django.utils.translation import ugettext as _
from eulfedora.util import RequestFailed
from requests.exceptions import ConnectionError
from rest_framework import serializers
Expand Down Expand Up @@ -43,24 +45,32 @@ def get_real_object(self, obj):
class ArticleSerializer(serializers.ModelSerializer):
authors = serializers.SerializerMethodField()
abstract = serializers.SerializerMethodField()
type = serializers.SerializerMethodField()
collection_name = serializers.SerializerMethodField()
bibliographic_reference = serializers.SerializerMethodField()
paral_titles = serializers.SerializerMethodField()
journal_code = serializers.SerializerMethodField()
journal_name = serializers.SerializerMethodField()
journal_type = serializers.SerializerMethodField()
journal_url = serializers.SerializerMethodField()
issue_localidentifier = serializers.SerializerMethodField()
issue_title = serializers.SerializerMethodField()
issue_number = serializers.SerializerMethodField()
issue_volume = serializers.SerializerMethodField()
issue_published = serializers.SerializerMethodField()
issue_volume_slug = serializers.SerializerMethodField()
issue_publication_date = serializers.SerializerMethodField()
has_pdf = serializers.SerializerMethodField()

class Meta:
model = erudit_models.Article
fields = [
'journal_code', 'journal_name', 'issue_localidentifier', 'issue_title', 'issue_number',
'issue_volume', 'issue_published', 'issue_volume_slug', 'title', 'surtitle', 'subtitle',
'processing', 'authors', 'abstract', 'first_page', 'last_page', 'has_pdf',
'external_url', 'external_pdf_url', 'collection_name',
'journal_code', 'journal_name', 'journal_type', 'journal_url', 'issue_localidentifier',
'issue_title', 'issue_number', 'paral_titles',
'issue_volume', 'issue_published', 'issue_volume_slug', 'issue_publication_date',
'title', 'surtitle', 'subtitle',
'processing', 'authors', 'abstract', 'type', 'first_page', 'last_page', 'has_pdf',
'external_url', 'external_pdf_url', 'collection_name', 'bibliographic_reference',
]

def get_authors(self, obj):
Expand All @@ -73,23 +83,49 @@ def get_authors(self, obj):
})
return authors

def get_type(self, obj):
if obj.type:
return obj.get_type_display()
return _('Article')

def get_paral_titles(self, obj):
paral_titles = obj.titles.filter(paral=True)
return list(t.title for t in paral_titles)

def get_abstract(self, obj):
return obj.abstract

def get_collection_name(self, obj):
return obj.issue.journal.collection.name

def get_bibliographic_reference(self, obj):
return obj.bibliographic_reference

def get_journal_code(self, obj):
return obj.issue.journal.code

def get_journal_name(self, obj):
return obj.issue.journal.name

def get_journal_type(self, obj):
if obj.issue.journal.type:
return obj.issue.journal.type.get_code_display().lower()
return ''

def get_issue_publication_date(self, obj):
return obj.issue.volume_title

def get_journal_url(self, obj):
journal = obj.issue.journal
if journal.external_url:
return journal.external_url
return reverse('public:journal:journal_detail', args=(journal.code, ))

def get_issue_localidentifier(self, obj):
return obj.issue.localidentifier

def get_issue_title(self, obj):
return obj.issue.title
return obj.issue.name_with_themes

def get_issue_number(self, obj):
return obj.issue.number_for_display
Expand Down
28 changes: 23 additions & 5 deletions eruditorg/templates/public/search/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ <h2 class="sr-only">{% trans "Documents repérés" %}</h2>
<p class="authors">
{% if document.real_object.authors %}
{% for author in document.real_object.authors %}
<span class="author">{% if author.firstname and author.lastname %}{{ author.firstname }} {{ author.lastname }}{% elif author.othername %}{{ author.othername }}{% endif %}</span>{% if not forloop.last %}, {% endif %}
<span class="author">{% if author.firstname and author.lastname %}{{ author.lastname }}, {{ author.firstname }}{% elif author.othername %}{{ author.othername }}{% endif %}</span>{% if not forloop.last %}; {% endif %}
{% endfor %}
{% elif document.real_object.author %}
{% with author=document.real_object.author %}
Expand Down Expand Up @@ -193,19 +193,37 @@ <h3>
{% if document.real_object.subtitle %}
<span><br/>{{ document.real_object.subtitle }}</span>
{% endif %}
{% if document.real_object.paral_titles %}
{% for paral_title in document.real_object.paral_titles %}
<span><br>{{ paral_title }}</span>
{% endfor %}
{% endif %}
{% if document.real_object.bibliographic_reference %}
<span><br><em>{{ document.real_object.bibliographic_reference }}</em></span>
{% endif %}
</a>
</h3>
</div>
{# article metadata #}
<div class="meta">
{% if document.real_object.issue_title %}<p>{{ document.real_object.issue_title }}</p>{% endif %}
<p>
{% if document.document_type == 'article' %}
{% trans "Article" %},
{% with article=document.real_object %}
<strong>{{ article.type }}</strong>
{% if article.type == 'note' or article.type == 'Note' %}publiée{% else %}publié{% endif %}
{% trans "dans la revue" %}
{% if article.journal_type == 'culturel' %}{% trans "culturelle" %}{% elif article.journal_type == 'savant' %}{% trans "savante" %}{% endif %}
<a href="{{ article.journal_url }}">{{ article.journal_name }}</a> ({{ article.collection_name }})
{% if document.real_object.issue_title %}<p><strong>{{ document.real_object.issue_title|safe }}</strong></p>{% endif %}
</p>
<p>
{{ article.issue_publication_date }}
</p>
{% endwith %}
{% elif document.document_type == 'thesis' %}
{% trans "Thèse" %},
{% endif %}
{% trans "Thèse" %} {% trans "déposée à" %}
{{ document.real_object.collection_name }}
{% endif %}
</p>
</div>
{# abstract #}
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Django==1.9.9
git+https://github.com/erudit/[email protected]#egg=erudit-core
git+https://github.com/erudit/[email protected]#egg=erudit-core
git+https://github.com/erudit/[email protected]#egg=liberuditarticle
git+https://github.com/erudit/django-resumable-uploads.git@master#egg=django-resumable-uploads
git+https://github.com/erudit/django-account-actions.git@master#egg=django-account-actions
eulxml==1.0.1
eulfedora==1.5.0
git+https://github.com/erudit/[email protected]#egg=liberuditarticle
django-post-office==2.0.5
jsonfield==1.0.3
lxml==3.5.0
Expand Down
22 changes: 13 additions & 9 deletions tests/functional/apps/public/citations/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from erudit.models import JournalType
from erudit.test.factories import ArticleFactory
from erudit.test.factories import ArticleTitleFactory
from erudit.test.factories import AuthorFactory
from erudit.test.factories import CollectionFactory
from erudit.test.factories import IssueFactory
Expand Down Expand Up @@ -47,9 +48,12 @@ def setup(self):
collection=self.collection, type=JournalType.objects.get(code='C'))
self.issue_1 = IssueFactory.create(journal=self.journal_1, year=2012)
self.issue_2 = IssueFactory.create(journal=self.journal_2, year=2013)
self.article_1 = ArticleFactory.create(title='Title A', issue=self.issue_1)
self.article_2 = ArticleFactory.create(title='Title B', issue=self.issue_1)
self.article_3 = ArticleFactory.create(title='Title C', issue=self.issue_2)
self.article_1 = ArticleFactory.create(issue=self.issue_1)
self.article_2 = ArticleFactory.create(issue=self.issue_1)
self.article_3 = ArticleFactory.create(issue=self.issue_2)
ArticleTitleFactory(title='Title A', article=self.article_1)
ArticleTitleFactory(title='Title B', article=self.article_2)
ArticleTitleFactory(title='Title C', article=self.article_3)
self.article_1.authors.add(author_3)
self.article_2.authors.add(author_4)
self.article_3.authors.add(author_3)
Expand Down Expand Up @@ -229,9 +233,9 @@ def setup(self):
collection=self.collection, type=JournalType.objects.get(code='C'))
self.issue_1 = IssueFactory.create(journal=self.journal_1, year=2012)
self.issue_2 = IssueFactory.create(journal=self.journal_2, year=2013)
self.article_1 = ArticleFactory.create(title='Title A', issue=self.issue_1)
self.article_2 = ArticleFactory.create(title='Title B', issue=self.issue_1)
self.article_3 = ArticleFactory.create(title='Title C', issue=self.issue_2)
self.article_1 = ArticleFactory.create(issue=self.issue_1)
self.article_2 = ArticleFactory.create(issue=self.issue_1)
self.article_3 = ArticleFactory.create(issue=self.issue_2)
self.article_1.authors.add(author_3)
self.article_2.authors.add(author_4)
self.article_3.authors.add(author_3)
Expand Down Expand Up @@ -295,9 +299,9 @@ def setup(self):
collection=self.collection, type=JournalType.objects.get(code='C'))
self.issue_1 = IssueFactory.create(journal=self.journal_1, year=2012)
self.issue_2 = IssueFactory.create(journal=self.journal_2, year=2013)
self.article_1 = ArticleFactory.create(title='Title A', issue=self.issue_1)
self.article_2 = ArticleFactory.create(title='Title B', issue=self.issue_1)
self.article_3 = ArticleFactory.create(title='Title C', issue=self.issue_2)
self.article_1 = ArticleFactory.create(issue=self.issue_1)
self.article_2 = ArticleFactory.create(issue=self.issue_1)
self.article_3 = ArticleFactory.create(issue=self.issue_2)
self.article_1.authors.add(author_3)
self.article_2.authors.add(author_4)
self.article_3.authors.add(author_3)
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/apps/public/journal/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_provides_only_authors_for_the_first_available_letter_by_default(self):
def test_only_provides_authors_for_the_given_letter(self):
# Seetup
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create(title="lorem ipsum", issue=issue_1)
article_1 = ArticleFactory.create( issue=issue_1)

author_1 = AuthorFactory.create(lastname='btest')
author_2 = AuthorFactory.create(lastname='ctest1')
Expand All @@ -274,7 +274,7 @@ def test_only_provides_authors_for_the_given_letter(self):

def test_can_provide_contributors_of_article(self):
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create(title="lorem ipsum", issue=issue_1)
article_1 = ArticleFactory.create( issue=issue_1)

author_1 = AuthorFactory.create(lastname='btest')
author_2 = AuthorFactory.create(lastname='ctest1')
Expand All @@ -299,8 +299,8 @@ def test_can_provide_contributors_of_article(self):
def test_can_filter_by_article_type(self):
# Setup
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create(title="lorem ipsum", issue=issue_1, type='article')
article_2 = ArticleFactory.create(title="lorem ipsum 2", issue=issue_1, type='compterendu') # noqa
article_1 = ArticleFactory.create( issue=issue_1, type='article')
article_2 = ArticleFactory.create( issue=issue_1, type='compterendu') # noqa

author_1 = AuthorFactory.create(lastname='btest')
article_1.authors.add(author_1)
Expand All @@ -318,7 +318,7 @@ def test_can_filter_by_article_type(self):

def test_can_filter_by_article_type_when_no_article_of_type(self):
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create(title="lorem ipsum", issue=issue_1, type='article')
article_1 = ArticleFactory.create( issue=issue_1, type='article')
author_1 = AuthorFactory.create(lastname='atest')
article_1.authors.add(author_1)
url = reverse('public:journal:journal_authors_list', kwargs={'code': self.journal.code})
Expand All @@ -333,7 +333,7 @@ def test_only_letters_with_results_are_active(self):
""" Test that for a given selection in the authors list view, only the letters for which
results are present are shown """
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create(title="lorem ipsum", issue=issue_1, type='article')
article_1 = ArticleFactory.create( issue=issue_1, type='article')
author_1 = AuthorFactory.create(lastname='atest')
article_1.authors.add(author_1)
url = reverse('public:journal:journal_authors_list', kwargs={'code': self.journal.code})
Expand Down

0 comments on commit c897db8

Please sign in to comment.