summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAamir Khan <syst3m.w0rm@gmail.com>2012-08-10 06:21:15 +0530
committerAamir Khan <syst3m.w0rm@gmail.com>2012-08-10 06:21:15 +0530
commite5dc1c48ea48177e21cff6670a2dbf0c4c4cf262 (patch)
tree8dd57320e742394034515158c013915595877c1a
parent6da4589cf562033fba6e1f5d910a28dbe39dc313 (diff)
downloadhyperkitty-e5dc1c48ea48177e21cff6670a2dbf0c4c4cf262.tar.gz
hyperkitty-e5dc1c48ea48177e21cff6670a2dbf0c4c4cf262.tar.xz
hyperkitty-e5dc1c48ea48177e21cff6670a2dbf0c4c4cf262.zip
Feature : Add tag to email threads
-rw-r--r--hyperkitty/models.py15
-rw-r--r--hyperkitty/templates/thread.html19
-rw-r--r--hyperkitty/templates/threads/add_tag_form.html2
-rw-r--r--hyperkitty/templates/threads/right_col.html3
-rw-r--r--hyperkitty/urls.py4
-rw-r--r--hyperkitty/views/list.py27
-rw-r--r--hyperkitty/views/thread.py37
7 files changed, 74 insertions, 33 deletions
diff --git a/hyperkitty/models.py b/hyperkitty/models.py
index f1bc196..dc1bcb4 100644
--- a/hyperkitty/models.py
+++ b/hyperkitty/models.py
@@ -59,7 +59,7 @@ class UserProfile(models.Model):
"Returns all the votes by a user"
# Extract all the votes by this user
try:
- votes = Rating.objects.filter(user = self.user)
+ votes = Rating.objects.filter(user=self.user)
except Rating.DoesNotExist:
votes = {}
@@ -75,3 +75,16 @@ class UserProfile(models.Model):
def __unicode__(self):
"""Unicode representation"""
return u'%s' % (unicode(self.user))
+
+class Tag(models.Model):
+ # @TODO: instead of list_address, user list model from kittystore?
+ list_address = models.CharField(max_length=50)
+
+ # @TODO: instead of threadid, use thread model from kittystore?
+ threadid = models.CharField(max_length=100)
+
+ tag = models.CharField(max_length=255)
+
+ def __unicode__(self):
+ """Unicode representation"""
+ return u'threadid = %s , tag = %s ' % (unicode(self.list_address), unicode(self.threadid))
diff --git a/hyperkitty/templates/thread.html b/hyperkitty/templates/thread.html
index a1bc38c..20248f1 100644
--- a/hyperkitty/templates/thread.html
+++ b/hyperkitty/templates/thread.html
@@ -93,7 +93,24 @@
});
+ $("#add_tag_form").submit( function () {
+
+ {% if user.is_authenticated %}
+ $.ajax({
+ type: "POST",
+ data : $(this).serialize(),
+ url: "{% url add_tag mlist_fqdn=list_address, email_id=first_mail.message_id %}",
+ success: function(data){
+ console.log('Tag is added successfully');
+ }
+ });
+ return false;
+ {% else %}
+ alert('You need to login in order to add tag');
+ {% endif %}
+ });
+
+
});
</script>
-
{% endblock %}
diff --git a/hyperkitty/templates/threads/add_tag_form.html b/hyperkitty/templates/threads/add_tag_form.html
index 65f6577..9df2196 100644
--- a/hyperkitty/templates/threads/add_tag_form.html
+++ b/hyperkitty/templates/threads/add_tag_form.html
@@ -3,7 +3,7 @@
{% block header %} {% endblock %}
{% block content %}
-<form action="/addtag/{{list_address}}/{{email_id}}/" method="post">
+<form id="addtag" action="{% url add_tag mlist_fqdn=list_address, email_id=first_mail.message_id %}" method="post">
{% csrf_token %}
{{ addtag_form }}
<button type="submit">
diff --git a/hyperkitty/templates/threads/right_col.html b/hyperkitty/templates/threads/right_col.html
index 9a1e448..f50bc46 100644
--- a/hyperkitty/templates/threads/right_col.html
+++ b/hyperkitty/templates/threads/right_col.html
@@ -37,7 +37,7 @@
</ul>
</div>
<div id="add_tag">
- <form action="/addtag/{{list_address}}/{{first_mail.message_id}}/" method="post">
+ <form id="add_tag_form" name="addtag" action="{% url add_tag mlist_fqdn=list_address, email_id=first_mail.message_id %}" method="post">
{% csrf_token %}
{{ addtag_form.as_p }}
<button type="submit">
@@ -58,3 +58,4 @@
</div>
</section>
+
diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py
index ebf757a..a1a711a 100644
--- a/hyperkitty/urls.py
+++ b/hyperkitty/urls.py
@@ -59,7 +59,7 @@ urlpatterns = patterns('hyperkitty.views',
### MESSAGE LEVEL VIEWS ###
# Vote a message
url(r'^message/(?P<mlist_fqdn>.*@.*)/(?P<messageid>.+)/$',
- 'message.index'),
+ 'message.index', name='message_index'),
url(r'^vote/(?P<mlist_fqdn>.*@.*)/$',
'message.vote', name='message_vote'),
@@ -74,7 +74,7 @@ urlpatterns = patterns('hyperkitty.views',
# Add Tag to a thread
url(r'^addtag/(?P<mlist_fqdn>.*@.*)\/(?P<email_id>.*)/$',
- 'thread.add_tag'),
+ 'thread.add_tag', name='add_tag'),
### THREAD LEVEL VIEW ENDS ###
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index df745a2..843cd97 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import re
import os
import json
@@ -17,7 +18,7 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from kittystore.kittysastore import KittySAStore
-from hyperkitty.models import Rating
+from hyperkitty.models import Rating, Tag
from hyperkitty.lib.mockup import *
from forms import *
from hyperkitty.utils import log
@@ -64,7 +65,7 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
if not end_date:
today = datetime.utcnow()
begin_date = datetime(today.year, today.month, 1)
- end_date = datetime(today.year, today.month+1, 1)
+ end_date = datetime(today.year, today.month + 1, 1)
month_string = 'Past thirty days'
list_name = mlist_fqdn.split('@')[0]
@@ -125,7 +126,7 @@ 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,
+ threads = STORE.get_archives(list_name=list_name, start=begin_date,
end=end_date)
participants = set()
@@ -281,11 +282,19 @@ def search_keyword(request, mlist_fqdn, target, keyword, page=1):
def search_tag(request, mlist_fqdn, tag=None, page=1):
- '''Searches both tag and topic'''
- if tag:
- query_string = {'Category': tag.capitalize()}
- else:
- query_string = None
- return _search_results_page(request, mlist_fqdn, query_string,
+ '''Returns emails having a particular tag'''
+
+ list_name = mlist_fqdn.split('@')[0]
+
+ try:
+ thread_ids = Tag.objects.filter(tag=tag)
+ except Tag.DoesNotExist:
+ thread_ids = {}
+
+ for thread in thread_ids:
+ threads = STORE.get_thread(list_name, thread.threadid)
+
+
+ return _search_results_page(request, mlist_fqdn, threads,
'Tag search', page, limit=50)
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index dc62ad1..c352297 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -9,7 +9,7 @@ from django.contrib.auth.decorators import (login_required,
user_passes_test)
from kittystore.kittysastore import KittySAStore
-from hyperkitty.models import Rating
+from hyperkitty.models import Rating, Tag
from hyperkitty.lib.mockup import *
from forms import *
from hyperkitty.utils import log
@@ -43,7 +43,7 @@ def thread_index (request, mlist_fqdn, threadid):
# Extract all the votes for this message
try:
- votes = Rating.objects.filter(messageid = message.message_id)
+ votes = Rating.objects.filter(messageid=message.message_id)
except Rating.DoesNotExist:
votes = {}
@@ -67,7 +67,7 @@ def thread_index (request, mlist_fqdn, threadid):
cnt = cnt + 1
archives_length = STORE.get_archives_length(list_name)
- from_url = '/thread/%s/%s/' %(mlist_fqdn, threadid)
+ from_url = '/thread/%s/%s/' % (mlist_fqdn, threadid)
tag_form = AddTagForm(initial={'from_url' : from_url})
c = RequestContext(request, {
@@ -92,22 +92,23 @@ def thread_index (request, mlist_fqdn, threadid):
@login_required
def add_tag(request, mlist_fqdn, email_id):
""" Add a tag to a given thread. """
- t = loader.get_template('threads/add_tag_form.html')
+
if request.method == 'POST':
form = AddTagForm(request.POST)
if form.is_valid():
- print "THERE WE ARE"
- # TODO: Add the logic to add the tag
- if form.data['from_url']:
- return HttpResponseRedirect(form.data['from_url'])
- else:
- return HttpResponseRedirect('/')
- else:
- form = AddTagForm()
- c = RequestContext(request, {
- 'list_address': mlist_fqdn,
- 'email_id': email_id,
- 'addtag_form': form,
- })
- return HttpResponse(t.render(c))
+ print "Adding tag..."
+
+ tag = form.data['tag']
+
+ try:
+ tag_obj = Tag.objects.get(threadid=email_id, list_address=mlist_fqdn, tag=tag)
+ except Tag.DoesNotExist:
+ tag_obj = Tag(list_address=mlist_fqdn, threadid=email_id, tag=tag)
+
+ tag_obj.save()
+ response_dict = { }
+ else:
+ response_dict = {'error' : 'Error adding tag, enter valid data' }
+
+ return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')