diff --git a/finance/templates/finance/timesheets.html b/finance/templates/finance/timesheets.html index b4f436ae761d82e57751f2198f8c7eb87bc6c328..29ce3fa27a1acfd10e29e124f5d23712785c289e 100644 --- a/finance/templates/finance/timesheets.html +++ b/finance/templates/finance/timesheets.html @@ -25,11 +25,12 @@ <div class="col-12"> <h2 class="mb-2 mt-4">Team Timesheets</h2> {% for total in totals %} - <h3 class="mb-1">{{ total.events.0.noted_by }}</h3> + <h3 class="mb-1">{{ total.user }}</h3> <table class="table"> <thead class="thead-default"> <tr> <th>Date</th> + <th>By</th> <th>Stream</th> <th>Event</th> <th>Duration</th> @@ -40,13 +41,14 @@ {% for event in total.events %} <tr> <td>{{ event.noted_on }}</td> + <td>{{ event.noted_by }}</td> <td>{{ event.stream }}</td> <td>{{ event.get_event_display }}</td> <td>{{ event.duration }}</td> </tr> {% endfor %} <tr> - <td colspan="3"></td> + <td colspan="4"></td> <td><strong>{{ total.duration.total }}</strong></td> </tr> </tbody> diff --git a/production/forms.py b/production/forms.py index a7022678608820a8cc6ffacc3efcfb4b4d4f5a83..bba5be4e7f563fb618e88c2eee1f31e03791327a 100644 --- a/production/forms.py +++ b/production/forms.py @@ -34,6 +34,11 @@ class AssignSupervisorForm(forms.ModelForm): model = ProductionStream fields = ('supervisor',) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['supervisor'].queryset = self.fields['supervisor'].queryset.filter( + user__groups__name='Production Supervisor') + class UserToOfficerForm(forms.ModelForm): class Meta: @@ -59,8 +64,15 @@ class ProductionUserMonthlyActiveFilter(forms.Form): ).distinct() output = [] for user in users: - qs = self.get_events(user) - output.append({'events': qs, 'duration': qs.aggregate(total=Sum('duration'))}) + events = user.events.filter(duration__isnull=False, + noted_on__month=self.cleaned_data['month'], + noted_on__year=self.cleaned_data['year']) + output.append({ + 'events': events, + 'duration': events.aggregate(total=Sum('duration')), + 'user': user + }) + return output def get_events(self, officer=None): diff --git a/production/migrations/0020_auto_20170930_0156.py b/production/migrations/0020_auto_20170930_0156.py new file mode 100644 index 0000000000000000000000000000000000000000..305d366b3f494fe473189539b92ec9c49c0b0bca --- /dev/null +++ b/production/migrations/0020_auto_20170930_0156.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2017-09-29 23:56 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('production', '0019_auto_20170929_2310'), + ] + + operations = [ + migrations.AlterModelOptions( + name='productionstream', + options={'permissions': (('can_work_for_stream', 'Can work for stream'), ('can_perform_supervisory_actions', 'Can perform supervisory actions'))}, + ), + migrations.AlterField( + model_name='productionevent', + name='noted_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='production.ProductionUser'), + ), + ] diff --git a/production/models.py b/production/models.py index a851db1c186ca2249969d352d2657b9f02d2a87e..17f2d73c427e11c0ebfa04d2f3d77a7fca235400 100644 --- a/production/models.py +++ b/production/models.py @@ -36,6 +36,7 @@ class ProductionStream(models.Model): class Meta: permissions = ( + ('can_work_for_stream', 'Can work for stream'), ('can_perform_supervisory_actions', 'Can perform supervisory actions'), ) diff --git a/production/templates/production/partials/production_stream_card_completed.html b/production/templates/production/partials/production_stream_card_completed.html index 03a2d6995385a51747b988f1025fcb07803fdcc0..f31b37b1a2d379c05a24c49019c45c0fc7f81d06 100644 --- a/production/templates/production/partials/production_stream_card_completed.html +++ b/production/templates/production/partials/production_stream_card_completed.html @@ -34,8 +34,8 @@ {% include 'production/partials/production_events.html' with events=stream.events.all non_editable=1 %} {% endblock %} - </div> - {% if prodevent_form %} + </div> + {% if prodevent_form and "can_work_for_stream" in sub_perms %} <div class="col-lg-5 mt-4 mt-lg-0"> <h3>Add an event to this production stream:</h3> <form action="{% url 'production:add_event' stream_id=stream.id %}" method="post"> diff --git a/production/templates/production/production.html b/production/templates/production/production.html index b61490c6a2572f28d32d1622b108eacb2afe5947..92e6e2c49717e9afb0d87f5d3de880bf28ea553a 100644 --- a/production/templates/production/production.html +++ b/production/templates/production/production.html @@ -124,7 +124,7 @@ {% if perms.scipost.can_promote_user_to_production_officer %} <div class="tab-pane" id="officers" role="tabpanel"> <h2 class="highlight">Production Officers</h2> - <h3>Current Production Officer</h3> + <h3>Current Production Officers</h3> <ul> {% for officer in production_officers %} <li>{{ officer }}</li> diff --git a/production/views.py b/production/views.py index 8ec7b75532e4574bf707b7e5662083692a969e91..bcafcdbe0da5502211e0825a37054690ba9f205d 100644 --- a/production/views.py +++ b/production/views.py @@ -119,6 +119,7 @@ def add_officer(request, stream_id): if form.is_valid(): form.save() officer = form.cleaned_data.get('officer') + assign_perm('can_work_for_stream', officer.user, stream) messages.success(request, 'Officer {officer} has been assigned.'.format(officer=officer)) notify_new_stream_assignment(request.user, stream, officer.user) else: @@ -153,6 +154,7 @@ def add_supervisor(request, stream_id): if form.is_valid(): form.save() supervisor = form.cleaned_data.get('supervisor') + assign_perm('can_work_for_stream', supervisor.user, stream) messages.success(request, 'Supervisor {supervisor} has been assigned.'.format( supervisor=supervisor)) notify_new_stream_assignment(request.user, stream, supervisor.user) diff --git a/submissions/views.py b/submissions/views.py index 64b3d778941acd281bc7cbf6a029ff6e93c2fd92..2a0c0c65e149cb1fab4d4df257c0ccbbbd42317c 100644 --- a/submissions/views.py +++ b/submissions/views.py @@ -1432,6 +1432,7 @@ def fix_College_decision(request, rec_id): prodstream.save() ed_admins = Group.objects.get(name='Editorial Administrators') assign_perm('can_perform_supervisory_actions', ed_admins, prodstream) + assign_perm('can_work_for_stream', ed_admins, prodstream) # Add SubmissionEvent for authors # Do not write a new event for minor/major modification: already done at moment of