summaryrefslogtreecommitdiff
path: root/pgcommitfest/commitfest/ajax.py
diff options
context:
space:
mode:
authorMagnus Hagander2015-02-14 12:07:48 +0000
committerMagnus Hagander2015-02-14 12:07:48 +0000
commit27cba025a501c9dbcfb08da0c4db95dc6111d647 (patch)
tree6c793f942597c9aee7cc31435baf8eaaabd9b3a9 /pgcommitfest/commitfest/ajax.py
parent4800696f20614bd2017d671a1b28df55f9952345 (diff)
Implement simple message annotations
This feature makes it possible to "pull in" a message in a thread and highlight it with an annotation (free text format). This will list the message in a table along with the annotation and who made it. Annotations have to be attached to a specific message - for a "generic" one it makes sense to attach it to the latest message available, as that will put it at the correct place in time.
Diffstat (limited to 'pgcommitfest/commitfest/ajax.py')
-rw-r--r--pgcommitfest/commitfest/ajax.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/pgcommitfest/commitfest/ajax.py b/pgcommitfest/commitfest/ajax.py
index 92c4575..bc6817d 100644
--- a/pgcommitfest/commitfest/ajax.py
+++ b/pgcommitfest/commitfest/ajax.py
@@ -19,7 +19,8 @@ class HttpResponseServiceUnavailable(HttpResponse):
class Http503(Exception):
pass
-from models import CommitFest, Patch, MailThread, MailThreadAttachment, PatchHistory
+from models import CommitFest, Patch, MailThread, MailThreadAttachment
+from models import MailThreadAnnotation, PatchHistory
def _archivesAPI(suburl, params=None):
try:
@@ -63,6 +64,56 @@ def getThreads(request):
r = _archivesAPI('/list/pgsql-hackers/latest.json', params)
return sorted(r, key=lambda x: x['date'], reverse=True)
+def getMessages(request):
+ threadid = request.GET['t']
+
+ thread = MailThread.objects.get(pk=threadid)
+
+ # Always make a call over to the archives api
+ r = _archivesAPI('/message-id.json/%s' % thread.messageid)
+ return sorted(r, key=lambda x: x['date'], reverse=True)
+
+def annotateMessage(request):
+ thread = get_object_or_404(MailThread, pk=int(request.POST['t']))
+ msgid = request.POST['msgid']
+ msg = request.POST['msg']
+
+ # Get the subject, author and date from the archives
+ # We only have an API call to get the whole thread right now, so
+ # do that, and then find our entry in it.
+ r = _archivesAPI('/message-id.json/%s' % thread.messageid)
+ for m in r:
+ if m['msgid'] == msgid:
+ annotation = MailThreadAnnotation(mailthread=thread,
+ user=request.user,
+ msgid=msgid,
+ annotationtext=msg,
+ mailsubject=m['subj'],
+ maildate=m['date'],
+ mailauthor=m['from'])
+ annotation.save()
+
+ for p in thread.patches.all():
+ PatchHistory(patch=p, by=request.user, what='Added annotation "%s" to %s' % (msg, msgid)).save()
+ p.set_modified()
+ p.save()
+
+ return 'OK'
+ return 'Message not found in thread!'
+
+def deleteAnnotation(request):
+ annotation = get_object_or_404(MailThreadAnnotation, pk=request.POST['id'])
+
+ for p in annotation.mailthread.patches.all():
+ PatchHistory(patch=p, by=request.user, what='Deleted annotation "%s" from %s' % (annotation.annotationtext, annotation.msgid)).save()
+ p.set_modified()
+ p.save()
+
+ annotation.delete()
+
+ return 'OK'
def parse_and_add_attachments(threadinfo, mailthread):
for t in threadinfo:
@@ -176,8 +227,11 @@ def importUser(request):
_ajax_map={
'getThreads': getThreads,
+ 'getMessages': getMessages,
'attachThread': attachThread,
'detachThread': detachThread,
+ 'annotateMessage': annotateMessage,
+ 'deleteAnnotation': deleteAnnotation,
'searchUsers': searchUsers,
'importUser': importUser,
}