blob: 4bdcd272f126b125b26a1c7b24a72b06c9d06b9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# mongodb/api.py
from djangorestframework.views import View
from django.conf.urls.defaults import url
from django.http import HttpResponseNotModified, HttpResponse
from lib import mongo
import pymongo
import json
connection = pymongo.Connection('localhost', 27017)
class EmailResource(View):
""" Resource used to retrieve emails from the archives using the
REST API.
"""
def get(self, request, mlist_fqdn, messageid):
list_name = mlist_fqdn.split('@')[0]
email = mongo.get_email(list_name, messageid)
if not email:
return HttpResponse(status=404)
else:
return email
class ThreadResource(View):
""" Resource used to retrieve threads from the archives using the
REST API.
"""
def get(self, request, mlist_fqdn, threadid):
list_name = mlist_fqdn.split('@')[0]
thread = mongo.get_thread_list(list_name, threadid)
if not thread:
return HttpResponse(status=404)
else:
return thread
|