-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sponsorship application detail view (#1733)
* Querset method and property shortcut to list user's visible sponsorships * New detail view to display sponsorship application data * Add sponsorship detail link in user's navbar * Detail sponsorship application data * Style user action buttons * Add missing .user-profile-controls class as a button * Do not display sponsorship fee if has customization * Introduce agreed_fee property to deal with internal display logics * Add unit tests to fix broken and naive implementation of agreed fee property
- Loading branch information
Showing
14 changed files
with
324 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
from django.db.models import Q, Subquery | ||
from django.db.models.query import QuerySet | ||
|
||
|
||
class SponsorshipQuerySet(QuerySet): | ||
def in_progress(self): | ||
status = [self.model.APPLIED, self.model.APPROVED] | ||
return self.filter(status__in=status) | ||
|
||
def visible_to(self, user): | ||
contacts = user.sponsorcontact_set.values_list('sponsor_id', flat=True) | ||
status = [self.model.APPLIED, self.model.APPROVED, self.model.FINALIZED] | ||
return self.filter( | ||
Q(submited_by=user) | Q(sponsor_id__in=Subquery(contacts)), | ||
status__in=status, | ||
).select_related('sponsor') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from model_bakery import baker | ||
|
||
from django.conf import settings | ||
from django.test import TestCase | ||
|
||
from ..models import Sponsorship | ||
|
||
|
||
class SponsorshipQuerySetTests(TestCase): | ||
|
||
def setUp(self): | ||
self.user = baker.make(settings.AUTH_USER_MODEL) | ||
self.contact = baker.make('sponsors.SponsorContact', user=self.user) | ||
|
||
def test_visible_to_user(self): | ||
visible = [ | ||
baker.make(Sponsorship, submited_by=self.user, status=Sponsorship.APPLIED), | ||
baker.make(Sponsorship, sponsor=self.contact.sponsor, status=Sponsorship.APPROVED), | ||
baker.make(Sponsorship, submited_by=self.user, status=Sponsorship.FINALIZED), | ||
] | ||
baker.make(Sponsorship) # should not be visible because it's from other sponsor | ||
baker.make(Sponsorship, submited_by=self.user, status=Sponsorship.REJECTED) # don't list rejected | ||
|
||
qs = Sponsorship.objects.visible_to(self.user) | ||
|
||
self.assertEqual(len(visible), qs.count()) | ||
for sp in visible: | ||
self.assertIn(sp, qs) | ||
self.assertEqual(list(qs), list(self.user.sponsorships)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.