Skip to content

Commit

Permalink
Merge pull request #977 from jfunez/beta
Browse files Browse the repository at this point in the history
 Primeira versão da interface para marcar o usuário editor da revista #963
  • Loading branch information
jfunez committed Sep 17, 2014
2 parents 1ffe370 + 4c6bcf0 commit 7e39798
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 57 deletions.
1 change: 1 addition & 0 deletions scielomanager/editorialmanager/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def backwards(self, orm):
'creator': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'enjoy_creator'", 'to': "orm['auth.User']"}),
'ctrl_vocabulary': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'current_ahead_documents': ('django.db.models.fields.IntegerField', [], {'default': '0', 'max_length': '3', 'null': 'True', 'blank': 'True'}),
'editor': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'editor_journal'", 'null': 'True', 'to': "orm['auth.User']"}),
'editor_address': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'editor_address_city': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'editor_address_country': ('scielo_extensions.modelfields.CountryField', [], {'max_length': '2'}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
{% block extrafooter %}
{{ block.super }}
<script>
$(document).ready(function() {
$(document).ready(function(){

$("#q").focus();
$("#q").focus();

});
});
</script>
{% endblock %}

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion scielomanager/journalmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ class Journal(caching.base.CachingMixin, models.Model):
userobjects = modelmanagers.JournalManager()

# Relation fields
editor = models.ForeignKey(User, verbose_name=_('Editor'), related_name='editor_journal', null=True, blank=True)
creator = models.ForeignKey(User, related_name='enjoy_creator', editable=False)
sponsor = models.ManyToManyField('Sponsor', verbose_name=_('Sponsor'), related_name='journal_sponsor', null=True, blank=True)
previous_title = models.ForeignKey('Journal', verbose_name=_('Previous title'), related_name='prev_title', null=True, blank=True)
Expand Down Expand Up @@ -664,7 +665,8 @@ def __unicode__(self):
class Meta:
ordering = ('title', 'id')
permissions = (("list_journal", "Can list Journals"),
("list_editor_journal", "Can list editor Journals"))
("list_editor_journal", "Can list editor Journal"),
("change_editor", "Can change editor of the journal"))

def get_last_issue(self):
"""
Expand Down
83 changes: 83 additions & 0 deletions scielomanager/journalmanager/templates/journalmanager/editor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{% extends "base_lv1.html" %}
{% load inctag_toolbars %}
{% load user_avatar %}
{% load modal %}
{% load i18n %}

{% block page_title %}{{block.super}}{% endblock %}

{% block content %}

{% journaldash_toolbar 'editor' journal user %}

{{block.super}}

{% if editor %}
<table class="table table-condensed _listings">
<thead>
<tr>
<th>{% trans "Username" %}:</th>
<th>{% trans "E-mail" %}:</th>
<th>{% trans "Full name" %}:</th>
<th>{% trans "Groups" %}:</th>
<th>{% trans "Actions" %}:</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a {% if not editor.is_active %}class="strikethrough"{% endif %}
href="{% url user.edit user.pk %}">
<img class="img-rounded" src="{% user_avatar_url editor 'small' %}" alt="Gravatar">
{{ editor.username }}
</a>
</td>
<td>
<a href="mailto:{{ editor.email }}">
{{ editor.email }}
</a>
</td>
<td>{{ editor.get_full_name }}</td>
<td>{{ editor.groups.all|join:", " }}</td>
<td>
<a data-target='#id_modal_change_editor' data-toggle="modal" href="{% url editor.add journal.id %}" class="btn btn-mini btn-warning">
<i class="icon-pencil"></i> {% trans 'Change user editor' %}
</a>
</td>
</tr>
</tbody>
</table>
{% else %}
<div class="alert">
{% trans "<strong>Warning!</strong> No user was selected as editor of this journal. To be the editor user must be in 'Editors' group" %}
</div>

{% include 'journalmanager/includes/form_add_editor.html' %}

{% endif %}

{% modal_form title="Change editor user" modal_id="id_modal_change_editor" %}

{% endblock %}

{% block extrafooter %}
<script>

$('#close_btn').click(function(){

$('#modal').modal('hide');

});

$(".chzn-select").chosen({no_results_text: "Nenhum resultado encontrado para: "})

$('#modal').on('shown', function () {

$("select[name='editor']").attr('class', 'chzn-select span12');
$(".chzn-select").chosen({no_results_text: "Nenhum resultado encontrado para: "});

});

</script>
{% endblock %}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% load i18n %}

<div style="height: 150px">
<h4>{% trans 'Choose a user to be editor of this journal' %}:</h4>

<form method="POST" action="{% url editor.add journal.id %}" enctype="application/x-www-form-urlencoded">
{% csrf_token %}
<div class="control-group">
<div class="controls">
<select name="editor" class="chzn-select span3">
{% for user in users_editor %}
<option value="">{% trans 'Nobody' %}</option>
<option value="{{ user.pk }}">{{ user.get_full_name }}</option>
{% endfor %}
</select>
</div>
</div>

{% if not request.is_ajax %}
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success">{% trans 'Add this user as editor of this journal' %}</button>
</div>
</div>
{% endif %}

</form>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<a href="{% url journal_status.edit journal_id %}">{% trans 'Status' %}</a>
</li>
{% endif %}
{% flag 'editorialmanager' %}
{% if perms.journalmanager.change_editor %}
<li {% if page == 'editor' %}class="active activedash" {% endif %}>
<a href="{% url editor.index journal_id %}">{% trans 'Editor' %}</a>
</li>
{% endif %}
{% endflag %}
</ul>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions scielomanager/journalmanager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
url(r'^user/(?P<user_id>\d+)/toggle_active_collection/(?P<collection_id>\d+)$',
views.toggle_active_collection, name='usercollection.toggle_active'),

#Editor
url(r'^(?P<journal_id>\d+)/editor/$', views.get_editor, name="editor.index"),
url(r'^(?P<journal_id>\d+)/editor/add/$', views.add_editor, name="editor.add"),

# Ajax requests
url(r'^ajx/ajx1/$', views.ajx_list_issues_for_markup_files, name="ajx.list_issues_for_markup_files"),
url(r'^ajx/ajx2/$', views.ajx_lookup_for_section_translation, name="ajx.lookup_for_section_translation"),
Expand Down
67 changes: 67 additions & 0 deletions scielomanager/journalmanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.urlresolvers import resolve
Expand Down Expand Up @@ -63,6 +64,72 @@ def get_first_letter(objects_all):
return sorted(list(letters_set))


def get_users_by_group(group):
"""
Get all users from group, return None if group doesnt exists.
"""
try:
editor_group = Group.objects.get(name=group)
except ObjectDoesNotExist:
return None
else:
return editor_group.user_set.all()


def get_editor(request, journal_id):
"""
Get the editor of the journal.
"""
users_editor = None

journal = get_object_or_404(models.Journal, id=journal_id)

if not journal.editor:
if not get_users_by_group('Editors'):
messages.error(request, _("Does not exist the group 'Editors'"))
else:
users_editor = get_users_by_group('Editors')

return render_to_response('journalmanager/editor.html',
{'editor': journal.editor,
'journal': journal,
'users_editor': users_editor},
context_instance=RequestContext(request))


def add_editor(request, journal_id):
"""
Set any user from Editors as editor of any journal.
"""
journal = get_object_or_404(models.Journal, id=journal_id)

if request.method == "POST":
editor_pk = request.POST.get('editor', None)
if editor_pk:
editor = User.objects.get(pk=editor_pk)
journal.editor = editor
journal.save()
messages.success(request, _("Successfully selected %s as editor of this Journal" % editor.get_full_name()))
else:
#Remove editor
journal.editor = None
journal.save()
messages.success(request, _("No user selected as editor of this journal!"))
else:
editors_group = get_users_by_group('Editors')
if not editors_group:
messages.error(request, _("Does not exist the group 'Editors'"))
else:
users_editor = editors_group

return render_to_response('journalmanager/includes/form_add_editor.html',
{'journal': journal,
'users_editor': users_editor},
context_instance=RequestContext(request))

return HttpResponseRedirect(reverse('editor.index', args=[journal.id]))


def index(request):

if not request.user.is_authenticated():
Expand Down

0 comments on commit 7e39798

Please sign in to comment.