SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 2cf2df83 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

fix delete work log action

change available statuses on stream
parent 5508a3d7
No related branches found
No related tags found
1 merge request!43Polish up new production page
{% load scipost_extras %}
{% for log in logs %}
<div id="log_{{ log.slug }}" class="row">
<div class="col">
<strong>{{ log.user.first_name }} {{ log.user.last_name }}</strong>
<br>
<span class="text-muted">{{ log.log_type }}</span>
<br>
{{ log.comments|linebreaksbr }}
</div>
<div class="text-muted text-end col-auto d-flex">
<div class="">
{{ log.work_date }}
<div class="container">
{% for log in logs %}
<div id="log_{{ log.slug }}" class="row">
<div class="col">
<strong>{{ log.user.first_name }} {{ log.user.last_name }}</strong>
<br>
<span class="text-muted">{{ log.log_type }}</span>
<br>
<strong>Duration: {{ log.duration|duration }}</strong>
{{ log.comments|linebreaksbr }}
</div>
<div class="ps-2">
<a class="text-danger" href="{% url 'finances:log_delete' log.slug %}"><span aria-hidden="true">
{% include 'bi/trash-fill.html' %}
</a>
<div class="text-muted text-end col-auto d-flex">
<div class="">
{{ log.work_date }}
<br>
<strong>Duration: {{ log.duration|duration }}</strong>
</div>
<div class="ps-2">
{% if log.user == request.user %}
<a id="log_{{ log.slug }}_delete_btn"
class="text-danger work_log_delete_btn"
hx-get="{% url 'finances:log_delete' log.slug %}"
hx-target="#log_{{ log.slug }}"
hx-confirm="Delete this log?">
<span aria-hidden="true">{% include 'bi/trash-fill.html' %}</span>
</a>
{% else %}
<span class="opacity-0">{% include 'bi/trash-fill.html' %}</span>
{% endif %}
</div>
</div>
</div>
</div>
{% empty %}
No logs were found.
{% endfor %}
{% empty %}
<div>No logs were found.</div>
{% endfor %}
</div>
......@@ -122,7 +122,7 @@ urlpatterns = [
# Timesheets
path("timesheets", views.timesheets, name="timesheets"),
path("timesheets/detailed", views.timesheets_detailed, name="timesheets_detailed"),
path("logs/<slug:slug>/delete", views.LogDeleteView.as_view(), name="log_delete"),
path("logs/<slug:slug>/delete", views._hx_worklog_delete, name="log_delete"),
# PeriodicReports
path("periodicreport/<int:pk>/file", views.periodicreport_file, name="periodicreport_file"),
]
......@@ -551,6 +551,18 @@ class LogDeleteView(LoginRequiredMixin, DeleteView):
return self.object.content.get_absolute_url()
@permission_required("scipost.can_view_production", raise_exception=True)
def _hx_worklog_delete(request, slug):
log = get_object_or_404(WorkLog, pk=slug_to_id(slug))
log.delete()
return HttpResponse(
r"""<div class="text-danger border border-danger p-3">
Work log has been deleted.
</div>"""
)
###################
# PeriodicReports #
###################
......
......@@ -71,7 +71,10 @@ class AssignOfficerForm(forms.ModelForm):
def save(self, commit=True):
stream = super().save(False)
if commit:
if stream.status == constants.PRODUCTION_STREAM_INITIATED:
if stream.status in [
constants.PRODUCTION_STREAM_INITIATED,
constants.PROOFS_SOURCE_REQUESTED,
]:
stream.status = constants.PROOFS_TASKED
stream.save()
return stream
......@@ -107,13 +110,15 @@ class StreamStatusForm(forms.ModelForm):
def get_available_statuses(self):
if self.instance.status in [
constants.PRODUCTION_STREAM_INITIATED,
constants.PRODUCTION_STREAM_COMPLETED,
constants.PROOFS_SOURCE_REQUESTED,
constants.PROOFS_ACCEPTED,
constants.PROOFS_CITED,
]:
# No status change can be made by User
return ()
elif self.instance.status == constants.PRODUCTION_STREAM_INITIATED:
return ((constants.PROOFS_SOURCE_REQUESTED, "Source files requested"),)
elif self.instance.status == constants.PROOFS_TASKED:
return ((constants.PROOFS_PRODUCED, "Proofs have been produced"),)
elif self.instance.status == constants.PROOFS_PRODUCED:
......@@ -125,6 +130,7 @@ class StreamStatusForm(forms.ModelForm):
return (
(constants.PROOFS_SENT, "Proofs sent to Authors"),
(constants.PROOFS_CORRECTED, "Corrections implemented"),
(constants.PROOFS_SOURCE_REQUESTED, "Source files requested"),
)
elif self.instance.status == constants.PROOFS_SENT:
return (
......
......@@ -6,7 +6,7 @@
<h3 class="col">Work Logs</h3>
{% include 'finances/_logs.html' with logs=productionstream.work_logs.all|dictsort:"created" %}
{% if productionstream.total_duration %}
{% if productionstream.total_duration and productionstream.work_logs.all.count > 1 %}
<div class="col-auto ms-auto me-5 border-primary border-top pt-2">
Total: <strong>{{ productionstream.total_duration|duration }}</strong>
</div>
......
......@@ -77,7 +77,7 @@
aria-expanded="false"
aria-controls="productionstream-{{ productionstream.id }}-work-log"
hx-get="{% url 'production:_hx_productionstream_actions_work_log' productionstream_id=productionstream.id %}"
hx-trigger="click once"
hx-trigger="load, htmx:trigger from:#productionstream-{{ productionstream.id }}-work-log-body target:a.work_log_delete_btn delay:1000"
hx-target="#productionstream-{{ productionstream.id }}-work-log-body">Work Log</button>
</h2>
<div id="productionstream-{{ productionstream.id }}-work-log"
......
......@@ -48,13 +48,6 @@
</div>
</details>
<div class="row">
<div class="col-auto"></div>
</div>
<div id="search-productionstreams-results" class="mt-2"></div>
{% endblock content %}
......@@ -2,6 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from functools import reduce
import random
from django import template
......@@ -97,3 +98,19 @@ def associated_contributors(draft):
return Contributor.objects.filter(
user__last_name__icontains=draft.last_name
).order_by("user__last_name")
@register.filter
def readable_str(value):
replacements = {
"_": " ",
}
return reduce(lambda a, kv: a.replace(*kv), replacements.items(), value)
@register.filter
def all_fields_have_choices(form):
for field in form.fields:
if len(form.fields[field].choices) == 0:
return False
return True
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