Skip to content
Snippets Groups Projects
Unverified Commit 143893f3 authored by Fredrik Jonsson's avatar Fredrik Jonsson Committed by GitHub
Browse files

Merge pull request #1318 from OpenTechFund/link-rounds-to-related-items

Link Rounds to Related Items
parents 88ebccbc 7bfea125
No related branches found
No related tags found
No related merge requests found
from django.urls import reverse
from django.utils.safestring import mark_safe
from wagtail.contrib.modeladmin.helpers import PermissionHelper
from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup
......@@ -16,7 +18,6 @@ from opentech.apply.categories.admin import CategoryAdmin, MetaCategoryAdmin
class BaseRoundAdmin(ModelAdmin):
choose_parent_view_class = RoundFundChooserView
choose_parent_template_name = 'funds/admin/parent_chooser.html'
list_display = ('title', 'fund', 'start_date', 'end_date')
button_helper_class = ButtonsWithPreview
def fund(self, obj):
......@@ -26,6 +27,38 @@ class BaseRoundAdmin(ModelAdmin):
class RoundAdmin(BaseRoundAdmin):
model = Round
menu_icon = 'repeat'
list_display = ('title', 'fund', 'start_date', 'end_date', 'sealed', 'applications', 'review_forms')
def applications(self, obj):
def build_urls(applications):
for application in applications:
url = reverse('funds_applicationform_modeladmin_edit', args=[application.id])
yield f'<a href="{url}">{application}</a>'
urls = list(build_urls(obj.forms.all()))
if not urls:
return
return mark_safe('<br />'.join(urls))
def fund(self, obj):
url = self.url_helper.get_action_url('edit', obj.fund.id)
url_tag = f'<a href="{url}">{obj.fund}</a>'
return mark_safe(url_tag)
def review_forms(self, obj):
def build_urls(review_forms):
for review_form in review_forms:
url = reverse('funds_round_modeladmin_edit', args=[review_form.id])
yield f'<a href="{url}">{review_form}</a>'
urls = list(build_urls(obj.review_forms.all()))
if not urls:
return
return mark_safe('<br />'.join(urls))
class ScreeningStatusPermissionHelper(PermissionHelper):
......@@ -54,6 +87,7 @@ class SealedRoundAdmin(BaseRoundAdmin):
model = SealedRound
menu_icon = 'locked'
menu_label = 'Sealed Rounds'
list_display = ('title', 'fund', 'start_date', 'end_date')
class FundAdmin(ModelAdmin):
......
from django.contrib.auth.models import Group
from django.test import TestCase
from django.urls import reverse
from wagtail.tests.utils import WagtailTestUtils
from opentech.apply.users.tests.factories import SuperUserFactory
from opentech.apply.home.factories import ApplyHomePageFactory
from opentech.apply.users.groups import STAFF_GROUP_NAME
from opentech.apply.users.tests.factories import SuperUserFactory
from .factories.models import RoundFactory
from .test_admin_form import form_data
......@@ -42,3 +46,40 @@ class TestFundCreationView(TestCase):
fund = self.create_page(2, same_forms=True)
self.assertEqual(fund.forms.count(), 2)
self.assertEqual(fund.review_forms.count(), 2)
class TestRoundIndexView(WagtailTestUtils, TestCase):
def setUp(self):
user = self.create_test_user()
self.client.force_login(user)
group, _ = Group.objects.get_or_create(name=STAFF_GROUP_NAME)
group.user_set.add(user)
self.round = RoundFactory()
def test_application_links(self):
response = self.client.get('/admin/funds/round/', follow=True)
application_links = [
f'<a href="/admin/funds/applicationform/edit/{app.id}/">{app}</a>'
for app in self.round.forms.all()
]
applications_cell = f'<td class="field-applications">{"".join(application_links)}</td>'
self.assertContains(response, applications_cell, html=True)
def test_number_of_rounds(self):
response = self.client.get('/admin/funds/round/', follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context_data["result_count"], 1)
def test_review_form_links(self):
response = self.client.get('/admin/funds/round/', follow=True)
review_form_links = [
f'<a href="/admin/funds/round/edit/{review_form.id}/">{review_form}</a>'
for review_form in self.round.review_forms.all()
]
review_form_cell = f'<td class="field-review_forms">{"".join(review_form_links)}</td>'
self.assertContains(response, review_form_cell, html=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