Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jamilatta committed Sep 17, 2014
2 parents b6ffa35 + 6afc1bf commit 1ffe370
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scielomanager/audit_log/tests/tests_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_POST_valid_formdata_do_log(self):
form['journal-use_license'] = use_license.pk
form['journal-languages'] = [language.pk]
form['journal-abstract_keyword_languages'] = [language.pk]
form.set('journal-subject_categories', str(subject_category.pk))
form.set('journal-subject_categories', [str(subject_category.pk),])
form['journal-is_indexed_scie'] = True
form['journal-is_indexed_ssci'] = False
form['journal-is_indexed_aehci'] = True
Expand Down
14 changes: 9 additions & 5 deletions scielomanager/editorialmanager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ class EditorialMemberInline(admin.StackedInline):
class EditorialBoardAdmin(admin.ModelAdmin):
inlines = [EditorialMemberInline, ]

admin.site.register(models.EditorialBoard, EditorialBoardAdmin)
def journal(self, obj):
return obj.issue.journal

def issue_publication_year(self, obj):
return obj.issue.publication_year

class RoleTypeAdmin(admin.ModelAdmin):
list_display = ('name', 'weight', )
search_fields = ('name', 'weight', )
search_fields = ('issue__journal__title', 'issue__volume', 'issue__publication_year')
list_display = ('__unicode__', 'issue_publication_year', 'issue', 'journal')

admin.site.register(models.RoleType, RoleTypeAdmin)
admin.site.register(models.EditorialBoard, EditorialBoardAdmin)
admin.site.register(models.RoleType)
37 changes: 37 additions & 0 deletions scielomanager/editorialmanager/tests/modelfactories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# coding: utf-8

import factory

from editorialmanager import models
from journalmanager.tests.modelfactories import IssueFactory


class EditorialBoardFactory(factory.Factory):
FACTORY_FOR = models.EditorialBoard

issue = factory.SubFactory(IssueFactory)


class RoleTypeFactory(factory.Factory):
FACTORY_FOR = models.RoleType

name = factory.Sequence(lambda n: "Role_%s" % n)


class EditorialMemberFactory(factory.Factory):
FACTORY_FOR = models.EditorialMember

role = factory.SubFactory(RoleTypeFactory)
board = factory.SubFactory(EditorialBoardFactory)

#Required fields
first_name = factory.Sequence(lambda n: "first_name_%s" % n)
last_name = factory.Sequence(lambda n: "last_name_%s" % n)
email = factory.Sequence(lambda n: "email%[email protected]" % n)

institution = factory.Sequence(lambda n: "institution_%s" % n)
link_cv = factory.Sequence(lambda n: "http://buscatextual.cnpq.br/?id_%s" % n)
city = factory.Sequence(lambda n: 'city_%s' % n)
state = factory.Sequence(lambda n: 'state_%s' % n)
country = factory.Sequence(lambda n: 'country_%s' % n)

1 change: 1 addition & 0 deletions scielomanager/journalmanager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class IssueAdmin(admin.ModelAdmin):
def queryset(self, request):
return Issue.nocacheobjects

search_fields = ('publication_year', 'volume', 'number', 'journal__title')
list_display = ('journal', 'volume', 'number', 'is_trashed', 'is_marked_up', '__unicode__',)

admin.site.register(Issue, IssueAdmin)
Expand Down
16 changes: 16 additions & 0 deletions scielomanager/journalmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ class UserProfile(caching.base.CachingMixin, models.Model):

user = models.OneToOneField(User)

@property
def is_editor(self):
return self.user.groups.filter(name__iexact='Editors').exists()

@property
def gravatar_id(self):
return hashlib.md5(self.user.email.lower().strip()).hexdigest()
Expand Down Expand Up @@ -662,6 +666,18 @@ class Meta:
permissions = (("list_journal", "Can list Journals"),
("list_editor_journal", "Can list editor Journals"))

def get_last_issue(self):
"""
Return the latest issue based on descending ordering of parameters:
``publication_year``, ``volume`` and ``number``
Return a issue instance otherwise ``None``
"""
try:
return self.issue_set.order_by('-publication_year', '-volume', '-number')[0]
except IndexError:
return None

def issues_as_grid(self, is_available=True):
objects_all = self.issue_set.available(is_available).order_by(
'-publication_year', '-volume')
Expand Down
7 changes: 7 additions & 0 deletions scielomanager/journalmanager/tests/modelfactories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime

from journalmanager import models
from django.contrib.auth.models import Group


class ArticleFactory(factory.Factory):
Expand Down Expand Up @@ -45,6 +46,12 @@ def _setup_next_sequence(cls):
date_joined = datetime.datetime(1999, 1, 1)


class GroupFactory(factory.Factory):
FACTORY_FOR = Group

name = factory.Sequence(lambda n: "Group #%s" % n)


class SubjectCategoryFactory(factory.Factory):
FACTORY_FOR = models.SubjectCategory

Expand Down
141 changes: 141 additions & 0 deletions scielomanager/journalmanager/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from waffle import Flag

from journalmanager.tests import modelfactories
from editorialmanager.tests.modelfactories import EditorialBoardFactory, EditorialMemberFactory

from journalmanager import forms
from journalmanager import models

Expand Down Expand Up @@ -3444,6 +3446,26 @@ def setUp(self):
def tearDown(self):
pass

def _makeOneWithEditorialBoard(self):
#Create any issue in this journal
issue = modelfactories.IssueFactory(journal=self.journal)

#Create a board to the issue
ed_board = EditorialBoardFactory(issue=issue)

#Add members to the board
member = EditorialMemberFactory(board=ed_board)
member = EditorialMemberFactory(board=ed_board)

return issue

def _makeOneWithoutEditorialBoard(self):
#Create any issue in this journal
issue = modelfactories.IssueFactory(journal=self.journal)

return issue


def test_basic_struture(self):
"""
Just to make sure that the required hidden fields are all
Expand Down Expand Up @@ -3525,6 +3547,125 @@ def test_POST_workflow_with_valid_formdata(self):
self.assertIn('Saved.', response.body)
self.assertTemplateUsed(response, 'journalmanager/issue_list.html')

def test_POST_with_valid_formdata_and_check_copy_of_editorial_board(self):
"""
When a valid form is submited, the user is redirected to
the issue's list and the new user must be part
of the list.
In order to take this action, the user needs the following
permissions: ``journalmanager.add_issue`` and
``journalmanager.list_issue``.
This test check if editorial board of this issue was created
"""

#create an issue with editorial board
issue = self._makeOneWithEditorialBoard()

perm_issue_change = _makePermission(perm='add_issue',
model='issue', app_label='journalmanager')
perm_issue_list = _makePermission(perm='list_issue',
model='issue', app_label='journalmanager')
self.user.user_permissions.add(perm_issue_change)
self.user.user_permissions.add(perm_issue_list)

for t in ['regular', 'supplement', 'special']:
form = self.app.get(reverse('issue.add_%s' % t, args=[self.journal.pk]), user=self.user).forms['issue-form']

if t == 'supplement':
form['number'] = ''
form['volume'] = '29'
form['suppl_type'] = 'volume'
form['suppl_text'] = 'suppl.X'
elif t == 'special':
form['number'] = '3'
form['spe_type'] = 'number'
form['spe_text'] = 'X'
else: # regular
form['number'] = '3'
form['volume'] = '29'

form['total_documents'] = '16'
form.set('ctrl_vocabulary', 'decs')

form['publication_start_month'] = '9'
form['publication_end_month'] = '11'
form['publication_year'] = '2012'
form['is_marked_up'] = False
form['editorial_standard'] = 'other'

response = form.submit().follow()

new_issue = models.Issue.objects.get(publication_year='2012', number='3', volume='29')

#Members of the recent IssueFormTests
new_members = new_issue.editorialboard.editorialmember_set.all()
last_members = issue.editorialboard.editorialmember_set.all()

#comparing first names
last_first_names = [member.first_name for member in last_members]
new_first_names = [member.first_name for member in new_members]

self.assertItemsEqual(last_first_names, new_first_names)
self.assertEqual(len(last_first_names), len(new_first_names))

self.assertIn('Saved.', response.body)
self.assertTemplateUsed(response, 'journalmanager/issue_list.html')

def test_POST_with_valid_formdata_and_check_editorial_board_without_issue(self):
"""
When a valid form is submited, the user is redirected to
the issue's list and the new user must be part
of the list.
In order to take this action, the user needs the following
permissions: ``journalmanager.add_issue`` and
``journalmanager.list_issue``.
This test check if editorial board of this issue was created
"""

#create an issue
issue = self._makeOneWithoutEditorialBoard()

perm_issue_change = _makePermission(perm='add_issue',
model='issue', app_label='journalmanager')
perm_issue_list = _makePermission(perm='list_issue',
model='issue', app_label='journalmanager')
self.user.user_permissions.add(perm_issue_change)
self.user.user_permissions.add(perm_issue_list)

for t in ['regular', 'supplement', 'special']:
form = self.app.get(reverse('issue.add_%s' % t, args=[self.journal.pk]), user=self.user).forms['issue-form']

if t == 'supplement':
form['number'] = ''
form['volume'] = '29'
form['suppl_type'] = 'volume'
form['suppl_text'] = 'suppl.X'
elif t == 'special':
form['number'] = '3'
form['spe_type'] = 'number'
form['spe_text'] = 'X'
else: # regular
form['number'] = '3'
form['volume'] = '29'

form['total_documents'] = '16'
form.set('ctrl_vocabulary', 'decs')

form['publication_start_month'] = '9'
form['publication_end_month'] = '11'
form['publication_year'] = '2012'
form['is_marked_up'] = False
form['editorial_standard'] = 'other'

response = form.submit().follow()

self.assertIn('Saved.', response.body)
self.assertTemplateUsed(response, 'journalmanager/issue_list.html')

def test_POST_workflow_without_volume_and_number_formdata(self):
"""
When a user submit a issue the form must contain unless one of the
Expand Down
15 changes: 15 additions & 0 deletions scielomanager/journalmanager/tests/tests_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,21 @@ def test_logged_user_access_to_index(self):

self.assertTemplateUsed(response, 'journalmanager/home_journal.html')

def test_logged_editor_user_access_to_list_journal(self):
editors_group = modelfactories.GroupFactory.create(name='Editors')
perm = _makePermission(perm='list_editor_journal', model='journal', app_label='journalmanager')
editors_group.permissions.add(perm)

collection = modelfactories.CollectionFactory.create()
collection.add_user(self.user)

self.user.groups.add(editors_group)

response = self.app.get(reverse('index'), user=self.user)
response = response.follow()

self.assertTemplateUsed(response, 'journal/journal_list.html')

def test_not_logged_user_access_to_index(self):
response = self.app.get(reverse('index')).follow()

Expand Down
26 changes: 26 additions & 0 deletions scielomanager/journalmanager/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#coding: utf-8
import json
import urlparse
from datetime import datetime
Expand Down Expand Up @@ -41,6 +42,7 @@
asbool,
)
from audit_log import helpers
from editorialmanager.models import EditorialBoard, EditorialMember

from waffle.decorators import waffle_flag

Expand All @@ -66,6 +68,10 @@ def index(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('journalmanager.user_login'))

#Redirect user when it`s is editor
if request.user.get_profile().is_editor:
return HttpResponseRedirect(reverse('editorial.index'))

pending_journals = models.PendedForm.objects.filter(
user=request.user.id).filter(view_name='journal.add').order_by('-created_at')

Expand Down Expand Up @@ -804,6 +810,9 @@ def get_issue_form_by_type(issue_type, request, journal, instance=None, initial=
'editorial_standard': journal.editorial_standard,
'ctrl_vocabulary': journal.ctrl_vocabulary}
issue = models.Issue()

#get last issue of the journal
last_issue = journal.get_last_issue()
else:
data_dict = None
issue = models.Issue.objects.get(pk=issue_id)
Expand All @@ -826,6 +835,23 @@ def get_issue_form_by_type(issue_type, request, journal, instance=None, initial=
if titleformset.is_valid():
titleformset.save()

#if is a new issue copy editorial board from the last issue
if issue_id is None and last_issue:
try:
members = last_issue.editorialboard.editorialmember_set.all()
except ObjectDoesNotExist:
messages.info(request,
_("Issue created successfully, however we can not create the editorial board."))
else:
ed_board = EditorialBoard()
ed_board.issue = saved_issue
ed_board.save()

for member in members:
member.board = ed_board
member.pk = None
member.save()

audit_data = {
'user': request.user,
'obj': issue,
Expand Down

0 comments on commit 1ffe370

Please sign in to comment.