SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit eccd567d authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Improve production page

parent 2d0b5caf
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,11 @@ class ProductionEventForm(forms.ModelForm): ...@@ -12,6 +12,11 @@ class ProductionEventForm(forms.ModelForm):
model = ProductionEvent model = ProductionEvent
exclude = ['stream', 'noted_on', 'noted_by'] exclude = ['stream', 'noted_on', 'noted_by']
def __init__(self, *args, **kwargs):
super(ProductionEventForm, self).__init__(*args, **kwargs)
self.fields['duration'].widget.attrs.update(
{'placeholder': 'HH:MM:SS'})
class InitiatePublicationForm(forms.Form): class InitiatePublicationForm(forms.Form):
accepted_submission = forms.ModelChoiceField( accepted_submission = forms.ModelChoiceField(
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-05-17 12:52
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('journals', '0020_auto_20170515_1829'),
]
operations = [
migrations.AlterField(
model_name='productionevent',
name='noted_by',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='scipost.Contributor'),
),
migrations.AlterField(
model_name='productionevent',
name='stream',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='journals.ProductionStream'),
),
migrations.AlterField(
model_name='productionstream',
name='submission',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='submissions.Submission'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-05-17 14:08
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('journals', '0021_auto_20170517_1452'),
]
operations = [
migrations.AlterField(
model_name='productionevent',
name='comments',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='productionevent',
name='noted_on',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
...@@ -22,17 +22,27 @@ from scipost.models import Contributor ...@@ -22,17 +22,27 @@ from scipost.models import Contributor
############## ##############
class ProductionStream(models.Model): class ProductionStream(models.Model):
submission = models.OneToOneField('submissions.Submission', related_name='stream') submission = models.OneToOneField('submissions.Submission', on_delete=models.CASCADE)
opened = models.DateTimeField() opened = models.DateTimeField()
def __str__(self):
return str(self.submission)
def total_duration(self):
totdur = self.productionevent_set.all().aggregate(models.Sum('duration'))
return totdur['duration__sum']
class ProductionEvent(models.Model): class ProductionEvent(models.Model):
stream = models.ForeignKey(ProductionStream, related_name='events') stream = models.ForeignKey(ProductionStream, on_delete=models.CASCADE)
event = models.CharField(max_length=64, choices=PRODUCTION_EVENTS) event = models.CharField(max_length=64, choices=PRODUCTION_EVENTS)
comments = models.TextField() comments = models.TextField(blank=True, null=True)
noted_on = models.DateTimeField() noted_on = models.DateTimeField(default=timezone.now)
noted_by = models.ForeignKey(Contributor, related_name='event') noted_by = models.ForeignKey(Contributor, on_delete=models.CASCADE)
duration = models.DurationField(blank=True, null=True) duration = models.DurationField(blank=True, null=True)
def __str__(self):
return '%s: %s' % (str(self.stream.submission), self.get_event_display())
################ ################
......
{% load scipost_extras %}
<li id="{{ event.id }}">
<div class="font-weight-bold">{{ event.get_event_display }} <small class="text-muted">noted {{ event.noted_on }} by {{ event.noted_by }}</small>
</div>
{% if event.duration %}
<div><small>Duration: {{ event.duration|duration }}</small></div>
{% endif %}
{% if event.comments %}
<div>{{ event.comments|linebreaks }}</div>
{% endif %}
</li>
{% load bootstrap %} {% load bootstrap %}
{% load scipost_extras %}
<div class="card-block"> <div class="card-block">
{% include 'submissions/_submission_card_content_sparse.html' with submission=stream.submission %} {% include 'submissions/_submission_card_content_sparse.html' with submission=stream.submission %}
<h3>Events</h3> <div class="row">
<ul> <div class="col-7">
{% for event in stream.events_set.all %} <h3>Events</h3>
<li>{{ event.get_event_display }}</li> <ul>
{% empty %} {% for event in stream.productionevent_set.all %}
<li>No events were found.</li> {% include 'journals/_production_event_li.html' with event=event %}
{% endfor %} {% empty %}
</ul> <li>No events were found.</li>
<form action="{% url 'journals:add_production_event' stream_id=stream.id %}" method="post"> {% endfor %}
{% csrf_token %} </ul>
{{ form|bootstrap }} <br/>
<input type="submit" name="submit" value="Submit"> {% if stream.total_duration %}
</form> <h3>Total duration for this stream: {{ stream.total_duration|duration }}</h3>
{% endif %}
</div>
<div class="col-5">
<h3>Add an event to this production stream:</h3>
<form action="{% url 'journals:add_production_event' stream_id=stream.id %}" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div> </div>
...@@ -15,6 +15,13 @@ register = template.Library() ...@@ -15,6 +15,13 @@ register = template.Library()
def sort_by(queryset, order): def sort_by(queryset, order):
return queryset.order_by(order) return queryset.order_by(order)
@register.filter(name='duration')
def duration(dur):
total_seconds = int(dur.total_seconds())
hours = total_seconds // 3600
minutes = (total_seconds % 3600) // 60
return '{}h {}m'.format(hours, minutes)
####################### #######################
# For scipost objects # # For scipost objects #
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment