Commit cfc1b1f9 authored by cermak's avatar cermak
Browse files

Automatic report request generation

parent d59d5e49
......@@ -22,6 +22,7 @@ class ProposalTable(tables.Table):
name = TruncatedTextColumn(linkify=True)
proposaltype = tables.Column(verbose_name='Type')
supervisor = tables.Column(empty_values=[])
reports = tables.Column(empty_values=[], order_by="report_deadline", verbose_name="Missing report")
proposer = tables.LinkColumn('app_contacts_detail', args=[A('proposer.contact.pk')], text=lambda record: record.proposer.contact.name, order_by = A('proposer.contact.name'))
pid = tables.Column(attrs={'td': {'class': 'font-weight-bold'}})
pdf = tables.LinkColumn('proposal_pdf_detail_view', args=[A('pid')], text="PDF", attrs={'a': {'target': '_blank'}}, orderable = False)
......@@ -45,9 +46,19 @@ class ProposalTable(tables.Table):
self.columns.hide('reporter')
if request.user.has_perm('app.view_proposals'): # typically user office
self.columns.show('grants')
self.columns.hide('supervisor')
else:
self.columns.hide('grants')
def render_reports(self, record):
if record.report_set.count() > 0:
report = record.report_set.order_by('-created')[0]
if record.report_deadline: #report.pdf:
return f"❗ {record.report_deadline:%d.%m.%Y}"
else:
return f"✓"
return ""
def render_supervisor(self, record):
if record.student:
return "✓ (%s)" % record.supervisor
......
......@@ -101,9 +101,11 @@
{% if perms.app.change_status and object.last_status in "S,U" %}
<a class="btn btn-secondary" href="{{object.get_update_url}}">Edit proposal type and/or local contact</a>
{% endif %}
{% if object.proposer == user and object.last_status == "A" %}
<a class="btn btn-secondary" href="{{object.get_update_url}}">Edit experimental team</a>
<a class="btn btn-danger" href="/proposals/changestatus/{{object.slug}}/F/">Finish proposal</a>
{% if object.last_status == "A" %}
{% if perms.app.change_status or object.proposer == user %}
<a class="btn btn-secondary" href="{{object.get_update_url}}">Edit experimental team</a>
<a class="btn btn-danger" href="/proposals/changestatus/{{object.slug}}/F/">Finish proposal</a>
{% endif %}
{% endif %}
{% if user.contact in object.local_contacts.all and object.last_status == "A" %}
<a class="btn btn-secondary" href="{{object.get_update_url}}">Edit local contacts</a>
......
......@@ -13,12 +13,14 @@ from django.contrib.auth.models import User, Group
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
from django.views.generic import DetailView, ListView, UpdateView, CreateView, DeleteView, TemplateView
from django.urls import reverse, reverse_lazy
from django.db.models import Q, Sum, Count
from django.db.models import Q, Sum, Count, OuterRef, Subquery
from django_tables2.views import SingleTableView, SingleTableMixin, MultiTableMixin
from django_filters.views import FilterView
class ProposalsListView(LoginRequiredMixin, SingleTableMixin, FilterView):
model = Proposals
table_class = ProposalTable
......@@ -28,7 +30,14 @@ class ProposalsListView(LoginRequiredMixin, SingleTableMixin, FilterView):
filterset_class = ProposalFilter
def get_queryset(self):
queryset = Proposals.objects.distinct()
#inner_qs = Report.objects.order_by('-deadline')
#queryset = Proposals.objects.prefetch_related(Prefetch("report_set", queryset=inner_qs, to_attr="report_list")).distinct()
latest_report = Subquery(Report.objects.filter(
proposal_id=OuterRef("id"),
pdf__exact=""
).order_by("-deadline").values('deadline')[:1])
queryset = Proposals.objects.annotate(report_deadline=latest_report).distinct()
if self.kwargs['filtering'] == "mine":
queryset = queryset.filter(
......@@ -72,7 +81,12 @@ class StatusCreateView(LoginRequiredMixin, CreateView):
def form_valid(self, form):
form.instance.user = self.request.user
return super().form_valid(form)
response = super().form_valid(form)
# if finished generate report request
if self.object.status == "F":
rr = Report(proposal = self.object.proposal)
rr.save()
return response
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment