Skip to content

Commit

Permalink
#212 Send mail to project watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Dec 30, 2013
1 parent ce49ad0 commit 27904b3
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 9 deletions.
1 change: 1 addition & 0 deletions djangoproject/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def to_json(self):
return json.dumps({
'id': self.id,
'name': self.name,
'description': self.description,
'homeURL': self.homeURL,
'trackerURL': self.trackerURL,
'image3x1': self.image3x1.url if self.image3x1 else None,
Expand Down
2 changes: 1 addition & 1 deletion djangoproject/core/services/bitcoin_frespo_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _notify_payment_finished_if_applicable(payment_id):
break
if is_finished:
payment.offer.paid()
watches = watch_services.find_issue_watches(payment.offer.issue)
watches = watch_services.find_issue_and_project_watches(payment.offer.issue)
mail_services.notify_payment_parties_and_watchers_paymentconfirmed(payment, watches)
ActionLog.log_pay(payment)
msg = 'payment_id=%s, value=%s, issue=%s' % (
Expand Down
12 changes: 6 additions & 6 deletions djangoproject/core/services/issue_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def sponsor_existing_issue(issue_id, dict, user):
issue.is_public_suggestion = False
issue.save()
issue.update_redundant_fields()
watches = watch_services.find_issue_watches(issue)
watches = watch_services.find_issue_and_project_watches(issue)
notifyWatchers_offeradded(offer, watches)
msg = "offer: " + str(offer.price) + "\n<br>" +\
"issue key: " + offer.issue.key + "\n<br>" +\
Expand All @@ -107,7 +107,7 @@ def change_existing_offer(offer_id, offerdict, user):
offer.issue.update_redundant_fields()
old_offer = offer.clone()
offer.changeOffer(offerdict)
watches = watch_services.find_issue_watches(offer.issue)
watches = watch_services.find_issue_and_project_watches(offer.issue)
notifyWatchers_offerchanged(old_offer, offer, watches)
return offer

Expand All @@ -126,7 +126,7 @@ def add_solution_to_existing_issue(issue_id, comment_content, accepting_payments
if(comment_content):
comment = IssueComment.newComment(issue, user, comment_content)
comment.save()
watches = watch_services.find_issue_watches(solution.issue)
watches = watch_services.find_issue_and_project_watches(solution.issue)
notifyWatchers_workbegun(solution, comment, watches)
if(accepting_payments):
notifyWatchers_acceptingpayments(solution, watches)
Expand All @@ -143,7 +143,7 @@ def abort_existing_solution(solution_id, comment_content, user):
if(comment_content):
comment = IssueComment.newComment(solution.issue, user, comment_content)
comment.save()
watches = watch_services.find_issue_watches(solution.issue)
watches = watch_services.find_issue_and_project_watches(solution.issue)
notifyWatchers_workstopped(solution, comment, watches)

return solution, comment
Expand All @@ -159,7 +159,7 @@ def revoke_existing_offer(offer_id, comment_content, user):
if(comment_content):
comment = IssueComment.newComment(offer.issue, user, comment_content)
comment.save()
watches = watch_services.find_issue_watches(offer.issue)
watches = watch_services.find_issue_and_project_watches(offer.issue)
notifyWatchers_offerrevoked(offer, comment, watches)
return offer, comment

Expand All @@ -174,7 +174,7 @@ def resolve_existing_solution(solution_id, comment_content, user):
if(comment_content):
comment = IssueComment.newComment(solution.issue, user, comment_content)
comment.save()
watches = watch_services.find_issue_watches(solution.issue)
watches = watch_services.find_issue_and_project_watches(solution.issue)
notifyWatchers_workdone(solution, comment, watches)
return solution, comment

Expand Down
21 changes: 21 additions & 0 deletions djangoproject/core/services/mail_services.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging

from django.core.mail import EmailMultiAlternatives
Expand Down Expand Up @@ -66,6 +67,26 @@ def send_func(watch):
_notify_watchers(send_func, watches)


def notifyWatchers_project_edited(user, project, old_json, watches):
old_dic = json.loads(old_json)
changed_description = old_dic['description'] != project.description
changed_image = old_dic['image3x1'] != project.image3x1.url
def send_func(watch):
if watch.user.id != user.id:
_send_mail_to_user(user=watch.user,
subject=user.getUserInfo().screenName + " edited project [%s]" % project.name,
templateName='email/project_edited.html',
contextData={"project": project,
"user": user,
"you": watch.user,
"SITE_HOME": settings.SITE_HOME,
"changed_description": changed_description,
"changed_image": changed_image,
"old_dic": old_dic},
whentrue='receiveEmail_issue_work')
_notify_watchers(send_func, watches)


def notifyWatchers_acceptingpayments(solution, watches):
def send_func(watch):
if(watch.user.id != solution.programmer.id):
Expand Down
2 changes: 1 addition & 1 deletion djangoproject/core/services/paypal_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process_ipn_return(paykey, status, tracking_id):
payment.confirm_ipn()
payment.offer.paid()
payment.offer.issue.touch()
watches = watch_services.find_issue_watches(payment.offer.issue)
watches = watch_services.find_issue_and_project_watches(payment.offer.issue)
notify_payment_parties_and_watchers_paymentconfirmed(payment, watches)
notify_admin_payment_confirmed(payment)
ActionLog.log_pay(payment)
Expand Down
14 changes: 14 additions & 0 deletions djangoproject/core/services/watch_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ def find_issue_watches(issue):
return Watch.objects.filter(entity='ISSUE', objid=issue.id)


def find_project_watches(project):
return Watch.objects.filter(entity='PROJECT', objid=project.id)


def find_issue_and_project_watches(issue):
iwatches = Watch.objects.filter(entity='ISSUE', objid=issue.id)
watches = []
watches.extend(iwatches)
user_ids = set([w.user.id for w in watches])
pwatches = Watch.objects.filter(entity='PROJECT', objid=issue.project.id)
watches.extend([w for w in pwatches if not w.user.id in user_ids])
return watches


def watch_issue(user, issue_id, reason):
watch = _findWatchOrNone(user, 'ISSUE', issue_id)
if not watch:
Expand Down
4 changes: 3 additions & 1 deletion djangoproject/core/views/project_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from core.models import Project, ActionLog
from core.services import stats_services, issue_services, watch_services
from core.services import stats_services, issue_services, watch_services, mail_services
from core.views import template_folder
from django.contrib.auth.decorators import login_required

Expand Down Expand Up @@ -49,6 +49,8 @@ def edit(request):
project.image3x1 = request.FILES['image3x1']
project.description = request.POST.get('description')
project.save()
watches = watch_services.find_project_watches(project)
mail_services.notifyWatchers_project_edited(request.user, project, old_json, watches)
ActionLog.log_edit_project(project=project, user=request.user, old_json=old_json)
return redirect('core.views.project_views.view', project_id=project.id)

Expand Down
27 changes: 27 additions & 0 deletions djangoproject/templates/email/project_edited.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "email/base.html" %}
{% block mainContent%}
Hello {{ you.getUserInfo.screenName }}<br>
<a href="{{SITE_HOME}}{{ user.get_view_link }}" style="color: #08C;text-decoration: none;cursor: auto;">
{{ user.getUserInfo.screenName }}
</a>
has edited the
<a href="{{SITE_HOME}}/project/{{ project.id }}">{{ project.name }}</a>
project. Details below<br><br>

Old project settings
<div style="background-color: #D9EDF7;border-bottom-color: #BCE8F1;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;border-bottom-style: solid;border-bottom-width: 1px;border-left-color: #BCE8F1;border-left-style: solid;border-left-width: 1px;border-right-color: #BCE8F1;border-right-style: solid;border-right-width: 1px;border-top-color: #BCE8F1;border-top-left-radius: 4px;border-top-right-radius: 4px;border-top-style: solid;border-top-width: 1px;color: #3A87AD;line-height: 18px;margin-bottom: 18px;margin-left: 0px;margin-right: 0px;margin-top: 0px;padding-bottom: 8px;padding-left: 14px;padding-right: 35px;padding-top: 8px;">
<strong>description:</strong> {{old_dic.description|linebreaks}}<br>
<strong>image:</strong> {{old_dic.image3x1}}
</div>
New project settings
<div style="background-color: #D9EDF7;border-bottom-color: #BCE8F1;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;border-bottom-style: solid;border-bottom-width: 1px;border-left-color: #BCE8F1;border-left-style: solid;border-left-width: 1px;border-right-color: #BCE8F1;border-right-style: solid;border-right-width: 1px;border-top-color: #BCE8F1;border-top-left-radius: 4px;border-top-right-radius: 4px;border-top-style: solid;border-top-width: 1px;color: #3A87AD;line-height: 18px;margin-bottom: 18px;margin-left: 0px;margin-right: 0px;margin-top: 0px;padding-bottom: 8px;padding-left: 14px;padding-right: 35px;padding-top: 8px;">
<strong>description:</strong> {{project.description|linebreaks}}<br>
<strong>image:</strong> {{project.image3x1.url}}
</div>
We will let you know if there are any updates.

<br><br>
{% include 'email/include/email_settings_notice.html' %}

{% endblock mainContent%}

0 comments on commit 27904b3

Please sign in to comment.