Add ability in the API to get just messages with attachments
authorMagnus Hagander <magnus@hagander.net>
Sat, 24 Aug 2013 13:21:01 +0000 (15:21 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 24 Aug 2013 13:21:01 +0000 (15:21 +0200)
django/archives/mailarchives/api.py

index 9ef2193d50fa1f9e1f585b06cf2dc1d665fdcc97..95eb9683bcb19578fe38360bc3df24edb68d1989 100644 (file)
@@ -25,10 +25,18 @@ def latest(request, listname):
        if limit <= 0 or limit > 100:
                limit = 50
 
+       extrawhere=[]
+
+       # Return only messages that have attachments?
+       if request.GET.has_key('a'):
+               if request.GET['a'] == '1':
+                       extrawhere.append("has_attachment")
+
        list = get_object_or_404(List, listname=listname)
-       mlist = Message.objects.defer('bodytxt', 'cc', 'to').select_related().extra(where=["threadid IN (SELECT threadid FROM list_threads WHERE listid=%s)" % list.listid]).order_by('date')[:limit]
+       extrawhere.append("threadid IN (SELECT threadid FROM list_threads WHERE listid=%s)" % list.listid)
+       mlist = Message.objects.defer('bodytxt', 'cc', 'to').select_related().extra(where=extrawhere).order_by('date')[:limit]
        allyearmonths = set([(m.date.year, m.date.month) for m in mlist])
-       
+
        resp = HttpResponse(content_type='application/json')
        json.dump([
                {'msgid': m.messageid,