From 36ba6b8f46747669933f89122f5769a1b4c46865 Mon Sep 17 00:00:00 2001 From: Kevin Owocki Date: Wed, 3 Jul 2019 06:19:30 -0600 Subject: [PATCH] active bounties list in admin (#3486) --- app/dashboard/admin.py | 10 ++++++++++ app/dashboard/models.py | 5 +++++ app/dashboard/views.py | 4 +--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/dashboard/admin.py b/app/dashboard/admin.py index 1b4a3258d3a..d08a9eff2f0 100644 --- a/app/dashboard/admin.py +++ b/app/dashboard/admin.py @@ -92,6 +92,16 @@ class ProfileAdmin(admin.ModelAdmin): ordering = ['-id'] search_fields = ['email', 'data'] list_display = ['handle', 'created_on'] + readonly_fields = ['active_bounties_list'] + + def active_bounties_list(self, instance): + interests = instance.active_bounties + htmls = [] + for interest in interests: + bounty = Bounty.objects.get(interested=interest, current_bounty=True) + htmls.append(f"{bounty.title_or_desc}") + html = format_html("
".join(htmls)) + return html class VerificationAdmin(admin.ModelAdmin): diff --git a/app/dashboard/models.py b/app/dashboard/models.py index d71270a7dd3..40e255e7508 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -2078,6 +2078,11 @@ def get_profile_referral_code(self): def job_status_verbose(self): return dict(Profile.JOB_SEARCH_STATUS)[self.job_search_status] + @property + def active_bounties(self): + active_bounties = Bounty.objects.current().filter(idx_status__in=['open', 'started']) + return Interest.objects.filter(profile_id=self.pk, bounty__in=active_bounties) + @property def is_org(self): try: diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 9f53d4ca923..af3f7bbd4f7 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -257,9 +257,7 @@ def new_interest(request, bounty_id): status=401) num_issues = profile.max_num_issues_start_work - active_bounties = Bounty.objects.current().filter(idx_status__in=['open', 'started']) - num_active = Interest.objects.filter(profile_id=profile_id, bounty__in=active_bounties).count() - is_working_on_too_much_stuff = num_active >= num_issues + is_working_on_too_much_stuff = profile.active_bounties.count() >= num_issues if is_working_on_too_much_stuff: return JsonResponse({ 'error': _(f'You may only work on max of {num_issues} issues at once.'),