diff options
author | Pierre-Yves Chibon <pingou@pingoured.fr> | 2012-06-10 16:45:39 +0200 |
---|---|---|
committer | Pierre-Yves Chibon <pingou@pingoured.fr> | 2012-06-10 16:45:39 +0200 |
commit | ef266b315341440006ac504dc24b688cdcdc2d51 (patch) | |
tree | ec6ecd0eb3282dd912b82fbd41b2a1bb8df38977 | |
parent | 934c141409dc632b2739d062a4badcbf87144774 (diff) | |
download | hyperkitty-ef266b315341440006ac504dc24b688cdcdc2d51.tar.gz hyperkitty-ef266b315341440006ac504dc24b688cdcdc2d51.tar.xz hyperkitty-ef266b315341440006ac504dc24b688cdcdc2d51.zip |
Start on the add tag and add category bits
-rw-r--r-- | templates/base_simple.html | 26 | ||||
-rw-r--r-- | templates/simple_form.html | 16 | ||||
-rw-r--r-- | urls.py | 22 | ||||
-rw-r--r-- | views/pages.py | 66 |
4 files changed, 122 insertions, 8 deletions
diff --git a/templates/base_simple.html b/templates/base_simple.html new file mode 100644 index 0000000..9af40b8 --- /dev/null +++ b/templates/base_simple.html @@ -0,0 +1,26 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="ROBOTS" content="INDEX, FOLLOW" /> + + <title>{% block title %}Mail app{% endblock %}</title> + <meta name="author" content="" /> + + <meta name="dc.language" content="en" /> + + <link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/style.css" /> + + {% block additional_headers %} + {% endblock %} +</head> + +<body> + + <div class="content"> + {% block content %} + {% endblock %} + </div> + +</body> +</html> diff --git a/templates/simple_form.html b/templates/simple_form.html new file mode 100644 index 0000000..70253ea --- /dev/null +++ b/templates/simple_form.html @@ -0,0 +1,16 @@ +{% extends "base_simple.html" %} +{% load gravatar %} + +{% block title %}{{ app_name }}{% endblock %} + + +{% block content %} + + <div class="content"> + <form action="/addtag/{{list_address}}/{{email_id}}/" method="post"> + {% csrf_token %} + {{ addtag_form }} + <button type="submit">Add</button> + </form> + </div> <!-- end of content --> +{% endblock %} @@ -9,11 +9,11 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns # admin.autodiscover() urlpatterns = patterns('', - ################# INDEX PAGE ################ + # Index url(r'^/$', 'views.pages.index'), url(r'^$', 'views.pages.index'), - ################# ARCHIVES ################### + # Archives url(r'^archives/(?P<mlist_fqdn>.*@.*)/(?P<year>\d{4})/(?P<month>\d\d?)/(?P<day>\d\d?)/$', 'views.pages.archives'), url(r'^archives/(?P<mlist_fqdn>.*@.*)/(?P<year>\d{4})/(?P<month>\d\d?)/$', @@ -21,23 +21,23 @@ urlpatterns = patterns('', url(r'^archives/(?P<mlist_fqdn>.*@.*)/$', 'views.pages.archives'), - ############### THREAD VIEW ################## + # Threads url(r'^thread/(?P<mlist_fqdn>.*@.*)/(?P<threadid>.+)/$', 'views.pages.thread'), - ############### LIST VIEW ################### + # Lists url(r'^list/$', 'views.pages.index'), url(r'^list/(?P<mlist_fqdn>.*@.*)/$', 'views.pages.list'), - ############### MESSAGE ######################## + # Message url(r'^message/(?P<mlist_fqdn>.*@.*)/(?P<messageid>.+)/$', 'views.pages.message'), - ############### SEARCH ################## + # Search # If page number is present in URL url(r'^search/(?P<mlist_fqdn>.*@.*)\/(?P<target>.*)\/(?P<keyword>.*)\/(?P<page>\d+)/$', 'views.pages.search_keyword'), @@ -47,14 +47,20 @@ urlpatterns = patterns('', url(r'^search/(?P<mlist_fqdn>.*@.*)/$', 'views.pages.search'), + # Category + url(r'^addcategory/(?P<mlist_fqdn>.*@.*)\/(?P<email_id>.*)/$', + 'views.pages.add_category'), - ############## TAG ###################### + + # Tag url(r'^tag/(?P<mlist_fqdn>.*@.*)\/(?P<tag>.*)\/(?P<page>\d+)/$', 'views.pages.search_tag'), url(r'^tag/(?P<mlist_fqdn>.*@.*)\/(?P<tag>.*)/$', 'views.pages.search_tag'), + url(r'^addtag/(?P<mlist_fqdn>.*@.*)\/(?P<email_id>.*)/$', + 'views.pages.add_tag'), - ############## REST API ##################### + # REST API url(r'^api/$', 'views.pages.api'), url(r'^api/email\/(?P<mlist_fqdn>.*@.*)\/(?P<messageid>.*)/', EmailResource.as_view()), diff --git a/views/pages.py b/views/pages.py index d7cb21e..2251c99 100644 --- a/views/pages.py +++ b/views/pages.py @@ -46,6 +46,24 @@ class SearchForm(forms.Form): ) +class AddTagForm(forms.Form): + tag = forms.CharField(label='', help_text=None, + widget=forms.TextInput( + attrs={'placeholder': 'Add a tag...'} + ) + ) + from_url = forms.CharField(widget=forms.HiddenInput, required=False) + + +class AddCategoryForm(forms.Form): + category = forms.CharField(label='', help_text=None, + widget=forms.TextInput( + attrs={'placeholder': 'Add a category...'} + ) + ) + from_url = forms.CharField(widget=forms.HiddenInput, required=False) + + def index(request): t = loader.get_template('index.html') search_form = SearchForm(auto_id=False) @@ -62,6 +80,50 @@ def index(request): return HttpResponse(t.render(c)) +def add_tag(request, mlist_fqdn, email_id): + """ Add a tag to a given message. """ + t = loader.get_template('simple_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, { + 'app_name': settings.APP_NAME, + 'list_address': mlist_fqdn, + 'email_id': email_id, + 'addtag_form': form, + }) + return HttpResponse(t.render(c)) + +def add_category(request, mlist_fqdn, email_id): + """ Add a category to a given message. """ + t = loader.get_template('simple_form.html') + if request.method == 'POST': + form = AddCategoryForm(request.POST) + if form.is_valid(): + print "THERE WE ARE" + # TODO: Add the logic to add the category + if form.data['from_url']: + return HttpResponseRedirect(form.data['from_url']) + else: + return HttpResponseRedirect('/') + else: + form = AddCategoryForm() + c = RequestContext(request, { + 'app_name': settings.APP_NAME, + 'list_address': mlist_fqdn, + 'email_id': email_id, + 'addtag_form': form, + }) + return HttpResponse(t.render(c)) + def api(request): t = loader.get_template('api.html') c = RequestContext(request, { @@ -355,12 +417,16 @@ def thread (request, mlist_fqdn, threadid): cnt = cnt + 1 archives_length = STORE.get_archives_length(list_name) + from_url = '/thread/%s/%s/' %(mlist_fqdn, threadid) + tag_form = AddTagForm(initial={'from_url' : from_url}) + print dir(search_form) c = RequestContext(request, { 'app_name': settings.APP_NAME, 'list_name' : list_name, 'list_address': mlist_fqdn, 'search_form': search_form, + 'addtag_form': tag_form, 'month': 'Thread', 'participants': participants, 'answers': cnt, |