Skip to content

Commit

Permalink
active bounties list in admin (#3486)
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki authored and danlipert committed Jul 3, 2019
1 parent 81e8e76 commit 36ba6b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<a href='{bounty.url}'>{bounty.title_or_desc}</a>")
html = format_html("<BR>".join(htmls))
return html


class VerificationAdmin(admin.ModelAdmin):
Expand Down
5 changes: 5 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'),
Expand Down

0 comments on commit 36ba6b8

Please sign in to comment.