summaryrefslogtreecommitdiffstats
path: root/hyperkitty
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty')
-rw-r--r--hyperkitty/api.py9
-rw-r--r--hyperkitty/lib/__init__.py22
-rw-r--r--hyperkitty/models.py7
-rw-r--r--hyperkitty/templates/messages/message.html4
-rw-r--r--hyperkitty/templates/month_view.html6
-rw-r--r--hyperkitty/templates/search.html6
-rw-r--r--hyperkitty/urls.py4
-rw-r--r--hyperkitty/views/list.py51
-rw-r--r--hyperkitty/views/message.py23
-rw-r--r--hyperkitty/views/pages.py6
-rw-r--r--hyperkitty/views/thread.py13
11 files changed, 88 insertions, 63 deletions
diff --git a/hyperkitty/api.py b/hyperkitty/api.py
index c39646e..1cea89c 100644
--- a/hyperkitty/api.py
+++ b/hyperkitty/api.py
@@ -8,9 +8,7 @@ import json
import re
from hyperkitty.utils import log
-
-import kittystore
-STORE = kittystore.get_store(settings.KITTYSTORE_URL)
+from hyperkitty.lib import ThreadSafeStorePool
class EmailResource(View):
@@ -20,6 +18,7 @@ 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)
if not email:
return HttpResponse(status=404)
@@ -34,6 +33,7 @@ class ThreadResource(View):
def get(self, request, mlist_fqdn, threadid):
list_name = mlist_fqdn.split('@')[0]
+ STORE = ThreadSafeStorePool().get()
thread = STORE.get_thread(list_name, threadid)
if not thread:
return HttpResponse(status=404)
@@ -61,7 +61,8 @@ class SearchResource(View):
query_string = {field.capitalize():
re.compile(regex, re.IGNORECASE)}
- print query_string, field, keyword
+ #print query_string, field, keyword
+ STORE = ThreadSafeStorePool().get()
threads = STORE.search_archives(list_name, query_string)
if not threads:
return HttpResponse(status=404)
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py
index aa5a3d9..d6ad4aa 100644
--- a/hyperkitty/lib/__init__.py
+++ b/hyperkitty/lib/__init__.py
@@ -1,7 +1,27 @@
#-*- coding: utf-8 -*-
-from hashlib import md5
import urllib
+from hashlib import md5
+import threading
+
+from django.conf import settings
+
+from hyperkitty.utils import log
+
+import kittystore
+
+
+class ThreadSafeStorePool(object):
+
+ 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):
diff --git a/hyperkitty/models.py b/hyperkitty/models.py
index 9389a05..00c5128 100644
--- a/hyperkitty/models.py
+++ b/hyperkitty/models.py
@@ -25,9 +25,7 @@ from django.conf import settings
from hyperkitty.utils import log
-
-import kittystore
-STORE = kittystore.get_store(settings.KITTYSTORE_URL)
+from hyperkitty.lib import ThreadSafeStorePool
class Rating(models.Model):
@@ -65,7 +63,8 @@ class UserProfile(models.Model):
for vote in votes:
list_name = vote.list_address.split('@')[0]
- message = STORE.get_message_by_id_from_list(list_name, vote.messageid)
+ STORE = ThreadSafeStorePool().get()
+ message = STORE.get_message_by_id_from_list(vote.list_address, vote.messageid)
vote.message = message
return votes
diff --git a/hyperkitty/templates/messages/message.html b/hyperkitty/templates/messages/message.html
index 67d5653..c32805e 100644
--- a/hyperkitty/templates/messages/message.html
+++ b/hyperkitty/templates/messages/message.html
@@ -3,7 +3,7 @@
<div class="email_header">
{% gravatar_img_for_email email.email 40 %}
<div class="email_author inline-block">
- <span class="name"> <a href="{% url message_index mlist_fqdn=list_address, messageid=email.stable_url_id %}">{{email.sender}}</a> </span>
+ <span class="name"> <a href="{% url message_index mlist_fqdn=list_address, hashid=email.hash_id %}">{{email.sender_name}}</a> </span>
<br />
<span class="rank">Rank 8</span>
</div>
@@ -20,7 +20,7 @@
{{email.content}}
</div>
-<ul class="email_info inline" messageid="{{email.stable_url_id}}">
+<ul class="email_info inline" messageid="{{email.hash_id}}">
<li class="neutral">
+{{email.likes}}/-{{email.dislikes}}
</li>
diff --git a/hyperkitty/templates/month_view.html b/hyperkitty/templates/month_view.html
index 600c206..24e4ae7 100644
--- a/hyperkitty/templates/month_view.html
+++ b/hyperkitty/templates/month_view.html
@@ -24,11 +24,11 @@
</div>
{% endif %}
<div class="inline-block gravatar">
- {% if email.email %}
- {% gravatar_img_for_email email.email 40 %}
+ {% if email.sender_email %}
+ {% gravatar_img_for_email email.sender_email 40 %}
<br />
{% endif %}
- {{email.sender}}
+ {{email.sender_name}}
</div>
<div class="inline-block thread_email">
<span class="expander"> {{email.content}} </span>
diff --git a/hyperkitty/templates/search.html b/hyperkitty/templates/search.html
index a11e87d..1727a79 100644
--- a/hyperkitty/templates/search.html
+++ b/hyperkitty/templates/search.html
@@ -28,11 +28,11 @@
</div>
{% endif %}
<div class="inline-block gravatar">
- {% if email.email %}
- {% gravatar_img_for_email email.email 40 %}
+ {% if email.sender_email %}
+ {% gravatar_img_for_email email.sender_email 40 %}
<br />
{% endif %}
- {{email.sender}}
+ {{email.sender_name}}
</div>
<div class="inline-block thread_email">
<span class="expander"> {{email.content}} </span>
diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py
index 13a6f3f..5091f51 100644
--- a/hyperkitty/urls.py
+++ b/hyperkitty/urls.py
@@ -58,7 +58,7 @@ urlpatterns = patterns('hyperkitty.views',
### MESSAGE LEVEL VIEWS ###
# Vote a message
- url(r'^message/(?P<mlist_fqdn>.*@.*)/(?P<messageid>.+)/$',
+ url(r'^message/(?P<mlist_fqdn>.*@.*)/(?P<hashid>.+)/$',
'message.index', name='message_index'),
url(r'^vote/(?P<mlist_fqdn>.*@.*)/$',
@@ -80,7 +80,7 @@ urlpatterns = patterns('hyperkitty.views',
# REST API
url(r'^api/$', 'api.api'),
- url(r'^api/email\/(?P<mlist_fqdn>.*@.*)\/(?P<messageid>.*)/',
+ url(r'^api/email\/(?P<mlist_fqdn>.*@.*)\/(?P<hashid>.*)/',
EmailResource.as_view()),
url(r'^api/thread\/(?P<mlist_fqdn>.*@.*)\/(?P<threadid>.*)/',
ThreadResource.as_view()),
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index 26bdbf1..d122c84 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -19,12 +19,10 @@ from django.contrib.auth.decorators import (login_required,
from hyperkitty.models import Rating, Tag
from hyperkitty.lib.mockup import *
+from hyperkitty.lib import ThreadSafeStorePool
from forms import *
from hyperkitty.utils import log
-import kittystore
-STORE = kittystore.get_store(settings.KITTYSTORE_URL)
-
# @TODO : Move this into settings.py
MONTH_PARTICIPANTS = 284
@@ -70,17 +68,18 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
search_form = SearchForm(auto_id=False)
t = loader.get_template('month_view.html')
- threads = STORE.get_archives(list_name, start=begin_date,
+ STORE = ThreadSafeStorePool().get()
+ threads = STORE.get_archives(mlist_fqdn, start=begin_date,
end=end_date)
participants = set()
cnt = 0
for thread in threads:
# Statistics on how many participants and threads this month
- participants.add(thread.sender)
- thread.participants = STORE.get_thread_participants(list_name,
+ participants.add(thread.sender_name)
+ thread.participants = STORE.get_thread_participants(mlist_fqdn,
thread.thread_id)
- thread.answers = STORE.get_thread_length(list_name,
+ thread.answers = STORE.get_thread_length(mlist_fqdn,
thread.thread_id)
highestlike = 0
@@ -89,7 +88,7 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
totalvotes = 0
totallikes = 0
totaldislikes = 0
- messages = STORE.get_thread(list_name, thread.thread_id)
+ messages = STORE.get_thread(mlist_fqdn, thread.thread_id)
for message in messages:
# Extract all the votes for this message
@@ -139,7 +138,7 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
threads = paginator.page(paginator.num_pages)
- archives_length = STORE.get_archives_length(list_name)
+ archives_length = STORE.get_archives_length(mlist_fqdn)
c = RequestContext(request, {
'list_name' : list_name,
@@ -174,7 +173,8 @@ def list(request, mlist_fqdn=None):
end_date = datetime(today.year, today.month, today.day)
begin_date = end_date - timedelta(days=32)
- threads = STORE.get_archives(list_name=list_name, start=begin_date,
+ STORE = ThreadSafeStorePool().get()
+ threads = STORE.get_archives(list_name=mlist_fqdn, start=begin_date,
end=end_date)
participants = set()
@@ -193,10 +193,10 @@ def list(request, mlist_fqdn=None):
else:
dates[key] = 1
# Statistics on how many participants and threads this month
- participants.add(msg.sender)
- msg.participants = STORE.get_thread_participants(list_name,
+ participants.add(msg.sender_name)
+ msg.participants = STORE.get_thread_participants(mlist_fqdn,
msg.thread_id)
- msg.answers = STORE.get_thread_length(list_name,
+ msg.answers = STORE.get_thread_length(mlist_fqdn,
msg.thread_id)
threads[cnt] = msg
cnt = cnt + 1
@@ -207,7 +207,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 = STORE.get_archives_length(list_name)
+ archives_length = STORE.get_archives_length(mlist_fqdn)
# top authors are the ones that have the most kudos. How do we determine
# that? Most likes for their post?
@@ -254,7 +254,7 @@ def _search_results_page(request, mlist_fqdn, threads, search_type,
participants = set()
for msg in threads:
- participants.add(msg.sender)
+ participants.add(msg.sender_name)
paginator = Paginator(threads, num_threads)
@@ -264,15 +264,16 @@ def _search_results_page(request, mlist_fqdn, threads, search_type,
except (EmptyPage, InvalidPage):
threads = paginator.page(paginator.num_pages)
+ STORE = ThreadSafeStorePool().get()
cnt = 0
for msg in threads.object_list:
- msg.email = msg.email.strip()
+ msg.email = msg.sender_email.strip()
# Statistics on how many participants and threads this month
- participants.add(msg.sender)
+ participants.add(msg.sender_name)
if msg.thread_id:
- msg.participants = STORE.get_thread_participants(list_name,
+ msg.participants = STORE.get_thread_participants(mlist_fqdn,
msg.thread_id)
- msg.answers = STORE.get_thread_length(list_name,
+ msg.answers = STORE.get_thread_length(mlist_fqdn,
msg.thread_id)
else:
msg.participants = 0
@@ -309,6 +310,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()
if not keyword:
keyword = request.GET.get('keyword')
if not target:
@@ -318,13 +320,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(list_name, keyword)
+ threads = STORE.search_content_subject(mlist_fqdn, keyword)
elif target.lower() == 'subject':
- threads = STORE.search_subject(list_name, keyword)
+ threads = STORE.search_subject(mlist_fqdn, keyword)
elif target.lower() == 'content':
- threads = STORE.search_content(list_name, keyword)
+ threads = STORE.search_content(mlist_fqdn, keyword)
elif target.lower() == 'from':
- threads = STORE.search_sender(list_name, keyword)
+ threads = STORE.search_sender(mlist_fqdn, keyword)
return _search_results_page(request, mlist_fqdn, threads, 'Search', page)
@@ -332,6 +334,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()
list_name = mlist_fqdn.split('@')[0]
try:
@@ -341,7 +344,7 @@ def search_tag(request, mlist_fqdn, tag=None, page=1):
threads = []
for thread in thread_ids:
- threads_tmp = STORE.get_thread(list_name, thread.threadid)
+ threads_tmp = STORE.get_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 194e3e9..9f0191a 100644
--- a/hyperkitty/views/message.py
+++ b/hyperkitty/views/message.py
@@ -11,25 +11,24 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from hyperkitty.models import Rating
+from hyperkitty.lib import ThreadSafeStorePool
from hyperkitty.lib.mockup import *
from forms import *
from hyperkitty.utils import log
-import kittystore
-STORE = kittystore.get_store(settings.KITTYSTORE_URL)
-
-def index (request, mlist_fqdn, messageid):
- ''' Displays a single message identified by its messageid '''
+def index (request, mlist_fqdn, hashid):
+ ''' Displays a single message identified by its hash_id (derived from message_id) '''
list_name = mlist_fqdn.split('@')[0]
search_form = SearchForm(auto_id=False)
t = loader.get_template('message.html')
- message = STORE.get_message_by_hash_from_list(list_name, messageid)
- message.email = message.email.strip()
+ STORE = ThreadSafeStorePool().get()
+ 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:
- votes = Rating.objects.filter(messageid = messageid)
+ votes = Rating.objects.filter(messageid = hashid)
except Rating.DoesNotExist:
votes = {}
@@ -52,7 +51,7 @@ def index (request, mlist_fqdn, messageid):
'list_name' : list_name,
'list_address': mlist_fqdn,
'message': message,
- 'messageid' : messageid,
+ 'hashid' : hashid,
})
return HttpResponse(t.render(c))
@@ -65,13 +64,13 @@ def vote (request, mlist_fqdn):
return redirect('user_login')
value = request.POST['vote']
- messageid = request.POST['messageid']
+ hashid = request.POST['hashid']
# Checks if the user has already voted for a this message. If yes modify db entry else create a new one.
try:
- v = Rating.objects.get(user = request.user, messageid = messageid, list_address = mlist_fqdn)
+ v = Rating.objects.get(user = request.user, messageid = hashid, list_address = mlist_fqdn)
except Rating.DoesNotExist:
- v = Rating(list_address=mlist_fqdn, messageid = messageid, vote = value)
+ v = Rating(list_address=mlist_fqdn, messageid = hashid, vote = value)
v.user = request.user
v.vote = value
diff --git a/hyperkitty/views/pages.py b/hyperkitty/views/pages.py
index 4d33a78..e8a5bd1 100644
--- a/hyperkitty/views/pages.py
+++ b/hyperkitty/views/pages.py
@@ -19,6 +19,7 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from hyperkitty.models import Rating
from hyperkitty.lib.mockup import *
+from hyperkitty.lib import ThreadSafeStorePool
from forms import *
from hyperkitty.utils import log
@@ -29,7 +30,10 @@ def index(request):
base_url = settings.MAILMAN_API_URL % {
'username': settings.MAILMAN_USER, 'password': settings.MAILMAN_PASS}
- list_data = ['devel@fp.o', 'packaging@fp.o', 'fr-users@fp.o']
+ store = ThreadSafeStorePool().get()
+ list_data = store.get_list_names()
+ print list_data
+ log("warn", repr(list_data))
c = RequestContext(request, {
'lists': list_data,
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index 48eba09..355dd39 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -13,9 +13,7 @@ from hyperkitty.lib.mockup import *
from forms import *
from hyperkitty.utils import log
-import kittystore
-STORE = kittystore.get_store(settings.KITTYSTORE_URL)
-
+from hyperkitty.lib import ThreadSafeStorePool
def thread_index (request, mlist_fqdn, threadid):
@@ -24,7 +22,8 @@ def thread_index (request, mlist_fqdn, threadid):
search_form = SearchForm(auto_id=False)
t = loader.get_template('thread.html')
- threads = STORE.get_thread(list_name, threadid)
+ STORE = ThreadSafeStorePool().get()
+ threads = STORE.get_thread(mlist_fqdn, threadid)
#prev_thread = mongo.get_thread_name(list_name, int(threadid) - 1)
prev_thread = []
if len(prev_thread) > 30:
@@ -39,7 +38,7 @@ def thread_index (request, mlist_fqdn, threadid):
for message in threads:
# @TODO: Move this logic inside KittyStore?
- message.email = message.email.strip()
+ message.sender_email = message.sender_email.strip()
# Extract all the votes for this message
try:
@@ -63,10 +62,10 @@ def thread_index (request, mlist_fqdn, threadid):
message.dislikes = dislikes
# Statistics on how many participants and threads this month
- participants[message.sender] = {'email': message.email}
+ participants[message.sender_name] = {'email': message.sender_email}
cnt = cnt + 1
- archives_length = STORE.get_archives_length(list_name)
+ archives_length = STORE.get_archives_length(mlist_fqdn)
from_url = '/thread/%s/%s/' % (mlist_fqdn, threadid)
tag_form = AddTagForm(initial={'from_url' : from_url})