summaryrefslogtreecommitdiffstats
path: root/hyperkitty
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-09-06 11:08:10 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-09-06 11:08:10 +0200
commit9877360a7f81943239d852de14eebf8be7674ad5 (patch)
tree835d3adec2ec9eba46233f5d7724aea9af4ceece /hyperkitty
parent54f6eb7982a562a3526ee3b9be62fa6e9344dbdb (diff)
downloadhyperkitty-9877360a7f81943239d852de14eebf8be7674ad5.tar.gz
hyperkitty-9877360a7f81943239d852de14eebf8be7674ad5.tar.xz
hyperkitty-9877360a7f81943239d852de14eebf8be7674ad5.zip
Move the store pool to HyperKitty
Diffstat (limited to 'hyperkitty')
-rw-r--r--hyperkitty/api.py15
-rw-r--r--hyperkitty/lib/__init__.py19
-rw-r--r--hyperkitty/lib/archiver.py5
-rw-r--r--hyperkitty/models.py6
-rw-r--r--hyperkitty/views/list.py45
-rw-r--r--hyperkitty/views/message.py6
-rw-r--r--hyperkitty/views/pages.py5
-rw-r--r--hyperkitty/views/thread.py9
8 files changed, 48 insertions, 62 deletions
diff --git a/hyperkitty/api.py b/hyperkitty/api.py
index 1e8a05f..e085139 100644
--- a/hyperkitty/api.py
+++ b/hyperkitty/api.py
@@ -7,8 +7,9 @@ from django.http import HttpResponseNotModified, HttpResponse
import json
import re
+from kittystore import get_store
+
from hyperkitty.utils import log
-from hyperkitty.lib import ThreadSafeStorePool
class EmailResource(View):
@@ -18,8 +19,8 @@ class EmailResource(View):
def get(self, request, mlist_fqdn, messageid):
list_name = mlist_fqdn.split('@')[0]
- STORE = ThreadSafeStorePool().get()
- email = STORE.get_message_by_hash_from_list(list_name, messageid)
+ store = get_store(settings.KITTYSTORE_URL)
+ email = store.get_message_by_hash_from_list(list_name, messageid)
if not email:
return HttpResponse(status=404)
else:
@@ -33,8 +34,8 @@ class ThreadResource(View):
def get(self, request, mlist_fqdn, threadid):
list_name = mlist_fqdn.split('@')[0]
- STORE = ThreadSafeStorePool().get()
- thread = STORE.get_messages_in_thread(list_name, threadid)
+ store = get_store(settings.KITTYSTORE_URL)
+ thread = store.get_messages_in_thread(list_name, threadid)
if not thread:
return HttpResponse(status=404)
else:
@@ -62,8 +63,8 @@ class SearchResource(View):
re.compile(regex, re.IGNORECASE)}
#print query_string, field, keyword
- STORE = ThreadSafeStorePool().get()
- threads = STORE.search_archives(list_name, query_string)
+ store = get_store(settings.KITTYSTORE_URL)
+ threads = store.search_archives(list_name, query_string)
if not threads:
return HttpResponse(status=404)
else:
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py
index 9b541f9..be8e27d 100644
--- a/hyperkitty/lib/__init__.py
+++ b/hyperkitty/lib/__init__.py
@@ -2,31 +2,12 @@
import urllib
from hashlib import md5
-import threading
import datetime
from django.conf import settings
from hyperkitty.utils import log
-import kittystore
-
-
-class ThreadSafeStorePool(object):
- """
- http://unpythonic.blogspot.fr/2007/11/using-storm-and-sqlite-in-multithreaded.html
- """
-
- def __init__(self):
- self._local = threading.local()
-
- def get(self):
- try:
- return self._local.store
- except AttributeError:
- self._local.store = kittystore.get_store(settings.KITTYSTORE_URL, debug=False)
- return self._local.store
-
def gravatar_url(email):
'''Return a gravatar url for an email address'''
diff --git a/hyperkitty/lib/archiver.py b/hyperkitty/lib/archiver.py
index d0af7a2..6fcd2f9 100644
--- a/hyperkitty/lib/archiver.py
+++ b/hyperkitty/lib/archiver.py
@@ -6,7 +6,8 @@ Class implementation of Mailman's IArchiver interface
from mailman.interfaces.archiver import IArchiver
from django.core.urlresolvers import reverse
-from hyperkitty.lib import ThreadSafeStorePool
+from django.conf import settings
+from kittystore import get_store
class Archiver(object):
@@ -48,6 +49,6 @@ class Archiver(object):
be calculated.
"""
if self.store is None:
- self.store = ThreadSafeStorePool().get()
+ self.store = get_store(settings.KITTYSTORE_URL)
msg.message_id_hash = self.store.add_to_list(mlist.list_name, msg)
# Update karma
diff --git a/hyperkitty/models.py b/hyperkitty/models.py
index 0ed8f46..dae055a 100644
--- a/hyperkitty/models.py
+++ b/hyperkitty/models.py
@@ -23,9 +23,9 @@ from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
+from kittystore import get_store
from hyperkitty.utils import log
-from hyperkitty.lib import ThreadSafeStorePool
class Rating(models.Model):
@@ -61,10 +61,10 @@ class UserProfile(models.Model):
except Rating.DoesNotExist:
votes = {}
- STORE = ThreadSafeStorePool().get()
+ store = get_store(settings.KITTYSTORE_URL)
for vote in votes:
list_name = vote.list_address.split('@')[0]
- message = STORE.get_message_by_id_from_list(vote.list_address, vote.messageid)
+ message = store.get_message_by_id_from_list(vote.list_address, vote.messageid)
vote.message = message
return votes
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index eb3ecd5..8825511 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -16,10 +16,11 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, Invali
from django.contrib.auth.decorators import (login_required,
permission_required,
user_passes_test)
+from kittystore import get_store
from hyperkitty.models import Rating, Tag
#from hyperkitty.lib.mockup import *
-from hyperkitty.lib import ThreadSafeStorePool, get_months
+from hyperkitty.lib import get_months
from forms import *
from hyperkitty.utils import log
@@ -68,8 +69,8 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
search_form = SearchForm(auto_id=False)
t = loader.get_template('month_view.html')
- STORE = ThreadSafeStorePool().get()
- threads = STORE.get_threads(mlist_fqdn, start=begin_date,
+ store = get_store(settings.KITTYSTORE_URL)
+ threads = store.get_threads(mlist_fqdn, start=begin_date,
end=end_date)
participants = set()
@@ -77,9 +78,9 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
for thread in threads:
# Statistics on how many participants and threads this month
participants.add(thread.sender_name)
- thread.participants = STORE.get_thread_participants(mlist_fqdn,
+ thread.participants = store.get_thread_participants(mlist_fqdn,
thread.thread_id)
- thread.answers = STORE.get_thread_length(mlist_fqdn,
+ thread.answers = store.get_thread_length(mlist_fqdn,
thread.thread_id)
highestlike = 0
@@ -88,7 +89,7 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
totalvotes = 0
totallikes = 0
totaldislikes = 0
- messages = STORE.get_messages_in_thread(mlist_fqdn, thread.thread_id)
+ messages = store.get_messages_in_thread(mlist_fqdn, thread.thread_id)
for message in messages:
# Extract all the votes for this message
@@ -138,7 +139,7 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
threads = paginator.page(paginator.num_pages)
- archives_length = get_months(STORE, mlist_fqdn)
+ archives_length = get_months(store, mlist_fqdn)
c = RequestContext(request, {
'list_name' : list_name,
@@ -173,8 +174,8 @@ def list(request, mlist_fqdn=None):
end_date = datetime(today.year, today.month, today.day)
begin_date = end_date - timedelta(days=32)
- STORE = ThreadSafeStorePool().get()
- threads = STORE.get_threads(list_name=mlist_fqdn, start=begin_date,
+ store = get_store(settings.KITTYSTORE_URL)
+ threads = store.get_threads(list_name=mlist_fqdn, start=begin_date,
end=end_date)
participants = set()
@@ -194,9 +195,9 @@ def list(request, mlist_fqdn=None):
dates[key] = 1
# Statistics on how many participants and threads this month
participants.add(msg.sender_name)
- msg.participants = STORE.get_thread_participants(mlist_fqdn,
+ msg.participants = store.get_thread_participants(mlist_fqdn,
msg.thread_id)
- msg.answers = STORE.get_thread_length(mlist_fqdn,
+ msg.answers = store.get_thread_length(mlist_fqdn,
msg.thread_id)
threads[cnt] = msg
cnt = cnt + 1
@@ -207,7 +208,7 @@ def list(request, mlist_fqdn=None):
# active threads are the ones that have the most recent posting
active_threads = sorted(threads, key=lambda entry: entry.date, reverse=True)
- archives_length = get_months(STORE, mlist_fqdn)
+ archives_length = get_months(store, mlist_fqdn)
# top authors are the ones that have the most kudos. How do we determine
# that? Most likes for their post?
@@ -271,16 +272,16 @@ def _search_results_page(request, mlist_fqdn, threads, search_type,
except (EmptyPage, InvalidPage):
threads = paginator.page(paginator.num_pages)
- STORE = ThreadSafeStorePool().get()
+ store = get_store(settings.KITTYSTORE_URL)
cnt = 0
for msg in threads.object_list:
msg.email = msg.sender_email.strip()
# Statistics on how many participants and threads this month
participants.add(msg.sender_name)
if msg.thread_id:
- msg.participants = STORE.get_thread_participants(mlist_fqdn,
+ msg.participants = store.get_thread_participants(mlist_fqdn,
msg.thread_id)
- msg.answers = STORE.get_thread_length(mlist_fqdn,
+ msg.answers = store.get_thread_length(mlist_fqdn,
msg.thread_id)
else:
msg.participants = 0
@@ -317,7 +318,7 @@ def search(request, mlist_fqdn):
def search_keyword(request, mlist_fqdn, target, keyword, page=1):
## Should we remove the code below?
## If urls.py does it job we should never need it
- STORE = ThreadSafeStorePool().get()
+ store = get_store(settings.KITTYSTORE_URL)
if not keyword:
keyword = request.GET.get('keyword')
if not target:
@@ -327,13 +328,13 @@ def search_keyword(request, mlist_fqdn, target, keyword, page=1):
regex = '%%%s%%' % keyword
list_name = mlist_fqdn.split('@')[0]
if target.lower() == 'subjectcontent':
- threads = STORE.search_content_subject(mlist_fqdn, keyword)
+ threads = store.search_content_subject(mlist_fqdn, keyword)
elif target.lower() == 'subject':
- threads = STORE.search_subject(mlist_fqdn, keyword)
+ threads = store.search_subject(mlist_fqdn, keyword)
elif target.lower() == 'content':
- threads = STORE.search_content(mlist_fqdn, keyword)
+ threads = store.search_content(mlist_fqdn, keyword)
elif target.lower() == 'from':
- threads = STORE.search_sender(mlist_fqdn, keyword)
+ threads = store.search_sender(mlist_fqdn, keyword)
return _search_results_page(request, mlist_fqdn, threads, 'Search', page)
@@ -341,7 +342,7 @@ def search_keyword(request, mlist_fqdn, target, keyword, page=1):
def search_tag(request, mlist_fqdn, tag=None, page=1):
'''Returns emails having a particular tag'''
- STORE = ThreadSafeStorePool().get()
+ store = get_store(settings.KITTYSTORE_URL)
list_name = mlist_fqdn.split('@')[0]
try:
@@ -351,7 +352,7 @@ def search_tag(request, mlist_fqdn, tag=None, page=1):
threads = []
for thread in thread_ids:
- threads_tmp = STORE.get_messages_in_thread(mlist_fqdn, thread.threadid)
+ threads_tmp = store.get_messages_in_thread(mlist_fqdn, thread.threadid)
threads.append(threads_tmp[0])
return _search_results_page(request, mlist_fqdn, threads,
diff --git a/hyperkitty/views/message.py b/hyperkitty/views/message.py
index 089de81..86ae139 100644
--- a/hyperkitty/views/message.py
+++ b/hyperkitty/views/message.py
@@ -9,9 +9,9 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, Invali
from django.contrib.auth.decorators import (login_required,
permission_required,
user_passes_test)
+from kittystore import get_store
from hyperkitty.models import Rating
-from hyperkitty.lib import ThreadSafeStorePool
#from hyperkitty.lib.mockup import *
from forms import *
from hyperkitty.utils import log
@@ -26,8 +26,8 @@ def index (request, mlist_fqdn, hashid):
search_form = SearchForm(auto_id=False)
t = loader.get_template('message.html')
- STORE = ThreadSafeStorePool().get()
- message = STORE.get_message_by_hash_from_list(mlist_fqdn, hashid)
+ store = get_store(settings.KITTYSTORE_URL)
+ message = store.get_message_by_hash_from_list(mlist_fqdn, hashid)
message.sender_email = message.sender_email.strip()
# Extract all the votes for this message
try:
diff --git a/hyperkitty/views/pages.py b/hyperkitty/views/pages.py
index 29945b4..a3de806 100644
--- a/hyperkitty/views/pages.py
+++ b/hyperkitty/views/pages.py
@@ -17,9 +17,10 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, Invali
from django.contrib.auth.decorators import (login_required,
permission_required,
user_passes_test)
+from kittystore import get_store
+
from hyperkitty.models import Rating
#from hyperkitty.lib.mockup import *
-from hyperkitty.lib import ThreadSafeStorePool
from forms import *
from hyperkitty.utils import log
@@ -30,7 +31,7 @@ def index(request):
base_url = settings.MAILMAN_API_URL % {
'username': settings.MAILMAN_USER, 'password': settings.MAILMAN_PASS}
- store = ThreadSafeStorePool().get()
+ store = get_store(settings.KITTYSTORE_URL)
list_data = store.get_list_names()
log("warn", repr(list_data))
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index f8820c9..fd0d466 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -7,13 +7,14 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, Invali
from django.contrib.auth.decorators import (login_required,
permission_required,
user_passes_test)
+from kittystore import get_store
from hyperkitty.models import Rating, Tag
#from hyperkitty.lib.mockup import *
from forms import *
from hyperkitty.utils import log
+from hyperkitty.lib import get_months
-from hyperkitty.lib import ThreadSafeStorePool, get_months
def thread_index (request, mlist_fqdn, threadid):
@@ -22,8 +23,8 @@ def thread_index (request, mlist_fqdn, threadid):
search_form = SearchForm(auto_id=False)
t = loader.get_template('thread.html')
- STORE = ThreadSafeStorePool().get()
- threads = STORE.get_messages_in_thread(mlist_fqdn, threadid)
+ store = get_store(settings.KITTYSTORE_URL)
+ threads = store.get_messages_in_thread(mlist_fqdn, threadid)
#prev_thread = mongo.get_thread_name(list_name, int(threadid) - 1)
prev_thread = []
if len(prev_thread) > 30:
@@ -65,7 +66,7 @@ def thread_index (request, mlist_fqdn, threadid):
participants[message.sender_name] = {'email': message.sender_email}
cnt = cnt + 1
- archives_length = get_months(STORE, mlist_fqdn)
+ archives_length = get_months(store, mlist_fqdn)
from_url = '/thread/%s/%s/' % (mlist_fqdn, threadid)
tag_form = AddTagForm(initial={'from_url' : from_url})