SciPost Code Repository

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

add notes creation/view for subsidies

fixes #214
parent 92283ca6
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,9 @@
</a>
</td>
<td>
{% if subsidy.nr_visible_notes %}
<span class="text-primary me-1" data-bs-placement='bottom' data-bs-toggle="tooltip" data-bs-html="true" title="There exist {{ subsidy.nr_visible_notes }} notes related to this Subsidy.">{% include 'bi/info-circle-fill.html' %}</span>
{% endif %}
<a href="{{ subsidy.get_absolute_url }}">
{{ subsidy.get_subsidy_type_display }}
</a>
......
......@@ -110,6 +110,9 @@
</div>
</div>
<!-- Notes -->
{% include "pins/_hx_notes_list.html" with object=subsidy %}
{% if 'edadmin' in user_roles %}
{% if subsidy.amount_publicly_shown %}
......
......@@ -7,7 +7,10 @@ from itertools import accumulate
import mimetypes
from dal import autocomplete
from django.db.models import Q
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import Q, Count, OuterRef, Subquery
from django.db.models.functions import Coalesce
from django.template.response import TemplateResponse
from django.utils.html import format_html
import matplotlib
......@@ -49,6 +52,7 @@ from journals.models import Journal, Publication
from organizations.models import Organization
from scipost.mixins import PermissionsMixin
from scipost.permissions import HTMXPermissionsDenied, HTMXResponse
from pins.models import Note
def publishing_years():
......@@ -406,6 +410,21 @@ def _hx_subsidy_list(request):
subsidies = form.search_results(request.user)
else:
subsidies = Subsidy.objects.all()
content_type = ContentType.objects.get_for_model(Subsidy)
subsidies = subsidies.annotate(
nr_visible_notes=Coalesce(
Subquery(
Note.objects.visible_for(request.user, content_type.id, OuterRef("id"))
.values("regarding_object_id")
.annotate(nr=Count("id"))
.values("nr"),
output_field=models.IntegerField(),
),
0,
)
)
paginator = Paginator(subsidies, 16)
page_nr = request.GET.get("page")
page_obj = paginator.get_page(page_nr)
......@@ -421,7 +440,7 @@ def _hx_subsidy_list(request):
@permission_required("scipost.can_manage_subsidies", raise_exception=True)
def allocate_subsidy(request, subsidy_id:int):
def allocate_subsidy(request, subsidy_id: int):
subsidy = get_object_or_404(Subsidy, pk=subsidy_id)
subsidy.allocate()
return redirect(reverse("finances:subsidy_details", kwargs={"pk": subsidy.id}))
......
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