Skip to content

Commit

Permalink
#216 Dont show issues with 0 value in the home page
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Aug 1, 2014
1 parent 04b8403 commit f5ca907
Show file tree
Hide file tree
Showing 9 changed files with 620 additions and 32 deletions.

Large diffs are not rendered by default.

311 changes: 311 additions & 0 deletions djangoproject/core/migrations/0071_populate_is_sponsored.py

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions djangoproject/core/models.py
Expand Up @@ -130,7 +130,7 @@ def getSolutions(self):


def getKickstartingIssues(self):
return Issue.objects.filter(createdByUser=self, is_public_suggestion=True).order_by('-creationDate')
return Issue.objects.filter(createdByUser=self, is_sponsored=False, is_feedback=False).order_by('-creationDate')


def getWatchedIssues(self):
Expand Down Expand Up @@ -368,7 +368,7 @@ class Issue(models.Model):
trackerURL = models.URLField(null=True, blank=True)
trackerURL_noprotocol = models.URLField(null=True, blank=True)
is_feedback = models.BooleanField()
is_public_suggestion = models.BooleanField()
is_sponsored = models.BooleanField()
status = models.CharField(max_length=40)
logo = models.ImageField(null=True, blank=True, upload_to=upload_to('issue_images/logo'))

Expand All @@ -385,7 +385,7 @@ def newIssue(cls, project, key, title, description, createdByUser, trackerURL):
issue.trackerURL = trackerURL
issue.trackerURL_noprotocol = strip_protocol(trackerURL)
issue.is_feedback = False
issue.is_public_suggestion = False
issue.is_sponsored = False
issue.status = 'open'
return issue

Expand All @@ -399,6 +399,7 @@ def newIssueOrphan(cls, title, description, createdByUser):
issue.updatedDate = issue.creationDate
issue.createdByUser = createdByUser
issue.is_feedback = False
issue.is_sponsored = False
issue.status = 'open'
return issue

Expand All @@ -412,7 +413,7 @@ def newIssueFeedback(cls, title, description, createdByUser):
issue.updatedDate = issue.creationDate
issue.createdByUser = createdByUser
issue.is_feedback = True
issue.is_public_suggestion = False # to check with Tony
issue.is_sponsored = False
issue.status = 'open'
return issue

Expand Down Expand Up @@ -503,6 +504,7 @@ def get_card_image(self):

def update_redundant_fields(self):
self.status = self.get_status()
self.is_sponsored = self.get_sponsor_status()
self.touch()
self.save()

Expand All @@ -515,6 +517,15 @@ def get_status(self):
working = True
return 'working' if working else 'open'

def get_sponsor_status(self):
for offer in self.getOffers():
if offer.price > 0:
if offer.status == Offer.PAID:
return True
elif offer.status == Offer.OPEN and not offer.is_expired():
return True
return False

def __unicode__(self):
s = ''
if self.project:
Expand Down
25 changes: 12 additions & 13 deletions djangoproject/core/services/issue_services.py
Expand Up @@ -14,15 +14,15 @@
__author__ = 'tony'


def search_issues(project_id=None, project_name=None, search_terms='', is_public_suggestion=None):
def search_issues(project_id=None, project_name=None, search_terms='', is_sponsored=None):
if search_terms:
issue = _find_by_tracker_url(search_terms)
if issue:
return issue

issues = Issue.objects.filter(Q(is_feedback=False) | Q(offer__isnull=False)).distinct()
if is_public_suggestion != None:
issues = issues.filter(is_public_suggestion=is_public_suggestion)
if is_sponsored != None:
issues = issues.filter(is_sponsored=is_sponsored)
if project_id:
issues = issues.filter(project__id=project_id)
elif project_name:
Expand All @@ -40,25 +40,27 @@ def _find_by_tracker_url(url):

def sponsor_new_issue(dict, user):
offer = _buildOfferFromDictionary(dict, user)
if(offer.issue.project):
if offer.issue.project:
offer.issue.project.save()
offer.issue.project = offer.issue.project
if(not offer.issue.id):
if not offer.issue.id:
offer.issue.save()
offer.issue = offer.issue
offer.save()
offer.issue.update_redundant_fields()
msg = "offer: " + str(offer.price) + "\n<br>" +\
"issue key: " + offer.issue.key + "\n<br>" +\
"issue title: " + offer.issue.title + "\n<br>"
if(offer.issue.project):
if offer.issue.project:
msg += "project : " + offer.issue.project.name + "\n<br>" +\
"project.trackerURL: " + offer.issue.project.trackerURL + "\n<br>"
notify_admin("INFO: New issue sponsored", msg)
return offer


def kickstart_new_issue(dict, user):
issue = _buildIssueFromDictionary(dict, user);
issue.is_public_suggestion = True
issue = _buildIssueFromDictionary(dict, user)
issue.is_sponsored = False
if(issue.project):
issue.project.save()
issue.project = issue.project
Expand All @@ -78,9 +80,6 @@ def sponsor_existing_issue(issue_id, dict, user):
_throwIfAlreadySponsoring(issue, user)
offer = _buildOfferFromDictionary_and_issue(dict, user, issue);
offer.save()
if issue.is_public_suggestion:
issue.is_public_suggestion = False
issue.save()
issue.update_redundant_fields()
watches = watch_services.find_issue_and_project_watches(issue)
notifyWatchers_offeradded(offer, watches)
Expand All @@ -104,9 +103,9 @@ def change_existing_issue(issue_id, issuedict, logo, user):
def change_existing_offer(offer_id, offerdict, user):
offer = Offer.objects.get(pk=offer_id)
_throwIfNotOfferOwner(offer, user)
offer.issue.update_redundant_fields()
old_offer = offer.clone()
offer.changeOffer(offerdict)
offer.issue.update_redundant_fields()
watches = watch_services.find_issue_and_project_watches(offer.issue)
notifyWatchers_offerchanged(old_offer, offer, watches)
return offer
Expand Down Expand Up @@ -203,7 +202,7 @@ def to_card_dict(issues):
dic = {'id': issue.id,
'title': issue.title,
'status': issue.get_status(),
'sponsor_status': 'PROPOSED' if issue.is_public_suggestion else 'SPONSORED',
'sponsor_status': 'SPONSORED' if issue.is_sponsored else 'PROPOSED',
'project_link': '#',
'issue_link': issue.get_view_link(),
'description': strip_markdown(issue.description),
Expand Down
6 changes: 3 additions & 3 deletions djangoproject/core/services/stats_services.py
Expand Up @@ -58,8 +58,8 @@

COUNT_OFFERS = "select count(*) from core_offer"
COUNT_ISSUES = "select count(*) from core_issue where is_feedback = false"
COUNT_ISSUES_SPONSORING = "select count(*) from core_issue where is_feedback = false and is_public_suggestion = false"
COUNT_ISSUES_KICKSTARTING = "select count(*) from core_issue where is_feedback = false and is_public_suggestion = true"
COUNT_ISSUES_SPONSORING = "select count(*) from core_issue where is_feedback = false and is_sponsored = true"
COUNT_ISSUES_KICKSTARTING = "select count(*) from core_issue where is_feedback = false and is_sponsored = false"
COUNT_OFFERS_PAID = "select count(*) from core_offer where status = 'PAID'"
COUNT_OFFERS_OPEN = "select count(*) from core_offer where status = 'OPEN'"
COUNT_OFFERS_REVOKED = "select count(*) from core_offer where status = 'REVOKED'"
Expand All @@ -69,7 +69,7 @@
where i.project_id = %s
and i.status in ('open', 'working')
and i.is_feedback = false
and i.is_public_suggestion = false"""
and i.is_sponsored = true"""
COUNT_ISSUES_SPONSORING_DONE_BY_PROJECT = """select count(*) from core_issue i
where i.project_id = %s
and i.status = 'done'"""
Expand Down
14 changes: 8 additions & 6 deletions djangoproject/core/views/issue_views.py
Expand Up @@ -106,12 +106,12 @@ def _listIssues(request):
project_name = request.GET.get('project_name')
search_terms = request.GET.get('s')
operation = request.GET.get('operation', '')
is_public_suggestion = None
if(operation == 'SPONSOR'):
is_public_suggestion = False
elif(operation == 'KICKSTART'):
is_public_suggestion = True
issues = issue_services.search_issues(project_id, project_name, search_terms, is_public_suggestion)
is_sponsored = None
if operation == 'SPONSOR':
is_sponsored = True
elif operation == 'KICKSTART':
is_sponsored = False
issues = issue_services.search_issues(project_id, project_name, search_terms, is_sponsored)
return issues


Expand Down Expand Up @@ -227,6 +227,8 @@ def _actionbar(issue, myoffer, mysolution, user):
def viewIssue(request, issue_id):
try:
issue = Issue.objects.get(pk=issue_id)
if timezone.now() - issue.updatedDate > timedelta(hours=1):
issue.update_redundant_fields()
except:
return HttpResponse(status=404, content='Issue not found')
if issue.get_view_link() != request.path:
Expand Down
4 changes: 2 additions & 2 deletions djangoproject/core/views/json_views.py
Expand Up @@ -57,9 +57,9 @@ def list_issue_cards(request):
count = int(request.GET.get('count'))
if not count:
count = 3
sponsoring = request.GET.get('sponsoring').lower() == 'true'
is_sponsored = request.GET.get('sponsoring').lower() == 'true'
count = min(count, 100)
query = issue_services.search_issues(project_id=project_id, is_public_suggestion=not sponsoring)
query = issue_services.search_issues(project_id=project_id, is_sponsored=is_sponsored)
total_count = query.count()
issues = query[offset: offset + count]
issues = issue_services.to_card_dict(issues)
Expand Down
4 changes: 2 additions & 2 deletions djangoproject/core/views/main_views.py
Expand Up @@ -76,8 +76,8 @@ def mailtest(request):


def home(request):
issues_sponsoring = issue_services.search_issues(is_public_suggestion=False)[0:3]
issues_kickstarting = issue_services.search_issues(is_public_suggestion=True)[0:3]
issues_sponsoring = issue_services.search_issues(is_sponsored=True)[0:3]
issues_kickstarting = issue_services.search_issues(is_sponsored=False)[0:3]
crumbs = [HOME_CRUMB]
issues_sponsoring = json.dumps(issue_services.to_card_dict(issues_sponsoring))
issues_kickstarting = json.dumps(issue_services.to_card_dict(issues_kickstarting))
Expand Down
4 changes: 2 additions & 2 deletions djangoproject/core/views/project_views.py
Expand Up @@ -21,8 +21,8 @@ def view(request, project_id):
return redirect(project.redirectto_project.get_view_link())

stats = stats_services.project_stats(project)
issues_sponsoring = issue_services.search_issues(project_id=project_id, is_public_suggestion=False)[0:3]
issues_kickstarting = issue_services.search_issues(project_id=project_id, is_public_suggestion=True)[0:3]
issues_sponsoring = issue_services.search_issues(project_id=project_id, is_sponsored=True)[0:3]
issues_kickstarting = issue_services.search_issues(project_id=project_id, is_sponsored=False)[0:3]
issues_sponsoring = json.dumps(issue_services.to_card_dict(issues_sponsoring))
issues_kickstarting = json.dumps(issue_services.to_card_dict(issues_kickstarting))
top_sponsors = stats_services.project_top_sponsors(project_id)[0:5]
Expand Down

0 comments on commit f5ca907

Please sign in to comment.