diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-06-12 20:55:20 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-06-12 20:55:20 +0200 |
commit | 8a8b9f5a0b174225230c2ddb2dc9a0cecb33208e (patch) | |
tree | c1ba1ed6f42be001dd19758b6fd2f10510538ad8 /hyperkitty | |
parent | a195f1b150d2b17cdefd64038528b53035d585f7 (diff) | |
download | hyperkitty-8a8b9f5a0b174225230c2ddb2dc9a0cecb33208e.tar.gz hyperkitty-8a8b9f5a0b174225230c2ddb2dc9a0cecb33208e.tar.xz hyperkitty-8a8b9f5a0b174225230c2ddb2dc9a0cecb33208e.zip |
Paginate the list of liked messages in the user profile
Diffstat (limited to 'hyperkitty')
-rw-r--r-- | hyperkitty/static/js/hyperkitty.js | 24 | ||||
-rw-r--r-- | hyperkitty/templates/ajax/last_views.html | 2 | ||||
-rw-r--r-- | hyperkitty/templates/ajax/votes.html | 44 | ||||
-rw-r--r-- | hyperkitty/templates/user_profile.html | 42 | ||||
-rw-r--r-- | hyperkitty/urls.py | 1 | ||||
-rw-r--r-- | hyperkitty/views/accounts.py | 38 |
6 files changed, 89 insertions, 62 deletions
diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js index 5545cb9..ffdf5e1 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty.js @@ -451,10 +451,10 @@ function update_list_properties(url) { /* - * Last viewed threads in the user's profile + * Last viewed threads and votes in the user's profile */ -function update_last_views(base_url) { - var container = $(".views"); +function update_user_profile_part(container, base_url) { + container = $(container); var loader = container.prev(".ajaxloader"); function _update(url) { loader.show(); @@ -466,6 +466,24 @@ function update_last_views(base_url) { e.preventDefault(); _update(base_url + $(this).attr("href")); }); + // setup cancellation links + container.find("a.cancel").click(function(e) { + e.preventDefault(); + var form = $(this).parents("form").first(); + var data = form_to_json(form); + $.ajax({ + type: "POST", + url: form.attr("action"), + data: data, + dataType: "json", + success: function(response) { + form.parents("tr").remove(); + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(jqXHR.responseText); + } + }); + }); }, error: function(jqXHR, textStatus, errorThrown) { //alert(jqXHR.responseText); diff --git a/hyperkitty/templates/ajax/last_views.html b/hyperkitty/templates/ajax/last_views.html index a3e1786..0a6d97a 100644 --- a/hyperkitty/templates/ajax/last_views.html +++ b/hyperkitty/templates/ajax/last_views.html @@ -7,6 +7,7 @@ <thead> <tr> <th></th> + <th>List</th> <th>Subject</th> <th>Original author</th> <th>Start date</th> @@ -22,6 +23,7 @@ <i class="unread icon-eye-close" title="New comments"></i> {% endif %} </td> + <td>{{ lv.list_address }}</td> <td><a href="{% url 'thread' mlist_fqdn=lv.list_address threadid=lv.threadid %}" >{{ lv.thread.starting_email.subject }}</a></td> <td>{{ lv.thread.starting_email.sender_name }}</td> diff --git a/hyperkitty/templates/ajax/votes.html b/hyperkitty/templates/ajax/votes.html new file mode 100644 index 0000000..abe512e --- /dev/null +++ b/hyperkitty/templates/ajax/votes.html @@ -0,0 +1,44 @@ +{% load url from future %} +{% load i18n %} +{% load hk_generic %} + + {% if votes %} + <table class="table table-striped table-bordered table-condensed"> + <thead> + <tr> + <th>List</th> + <th>Subject</th> + <th>Author</th> + <th>Date</th> + <th>Vote</th> + </tr> + </thead> + <tbody> + {% for vote in votes %} + <tr> + <td>{{ vote.list_address }}</td> + <td><a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}" + >{{ vote.message.subject }}</a></td> + <td>{{ vote.message.sender_name }}</td> + <td>{{ vote.message|get_date|date:"l, j F Y H:i:s" }}</td> + <td> + <form method="post" class="likeform" + action="{% url 'message_vote' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}"> + {% csrf_token %} + <input type="hidden" name="vote" value="0" /> + {% if vote.vote == 1 %} + <span class="youlike">You like it + {% elif vote.vote == -1 %} + <span class="youdislike">You dislike it + {% endif %} + (<a href="#cancelvote" class="cancel">cancel</a>)</span> + </form> + </td> + </tr> + {% endfor %} + </tbody> + </table> + {% include "paginator.html" with pager=votes page_key="vpage" %} + {% else %} + <p>No vote yet.</p> + {% endif %} diff --git a/hyperkitty/templates/user_profile.html b/hyperkitty/templates/user_profile.html index a057fe2..f82f92d 100644 --- a/hyperkitty/templates/user_profile.html +++ b/hyperkitty/templates/user_profile.html @@ -75,43 +75,8 @@ <h3>Votes</h3> - <h4>Up Votes</h4> - {% if votes_up %} - <ul> - {% for vote in votes_up %} - <li> - {% if vote.message.content|trimString|length > 0 %} - <a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}" - >{{ vote.message.subject }}</a> by {{ vote.message.sender_name }} - ({{ vote.message|get_date|date:"l, j F Y H:i:s" }}) - {% else %} - <a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}">Message is empty</a> - {% endif %} - </li> - {% endfor %} - </ul> - {% else %} - <p>No up vote yet.</p> - {% endif %} - - <h4>Down Votes</h4> - {% if votes_down %} - <ul> - {% for vote in votes_down %} - <li> - {% if vote.message.content|trimString|length > 0 %} - <a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}" - >{{ vote.message.subject }}</a> by {{ vote.message.sender_name }} - ({{ vote.message|get_date|date:"l, j F Y H:i:s" }}) - {% else %} - <a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}">Message is empty</a> - {% endif %} - </li> - {% endfor %} - </ul> - {% else %} - <p>No down vote yet.</p> - {% endif %} + <img alt="Loading..." class="ajaxloader" src="{{ STATIC_URL }}img/ajax-loader.gif" /> + <div class="votes"></div> </div> @@ -122,7 +87,8 @@ <script type="text/javascript"> $(document).ready(function() { // Load the last views - update_last_views("{% url 'user_last_views' %}"); + update_user_profile_part(".views", "{% url 'user_last_views' %}"); + update_user_profile_part(".votes", "{% url 'user_votes' %}"); }); </script> diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py index b75632b..10143b1 100644 --- a/hyperkitty/urls.py +++ b/hyperkitty/urls.py @@ -46,6 +46,7 @@ urlpatterns = patterns('hyperkitty.views', url(r'^accounts/logout/$', logout_view, {'next_page': '/'}, name='user_logout'), url(r'^accounts/profile/$', 'accounts.user_profile', name='user_profile'), url(r'^accounts/profile/last_views$', 'accounts.last_views', name='user_last_views'), + url(r'^accounts/profile/votes$', 'accounts.votes', name='user_votes'), url(r'^accounts/register/$', 'accounts.user_registration', {'SSL': True}, name='user_registration'), diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py index d7e35c2..9e1c4aa 100644 --- a/hyperkitty/views/accounts.py +++ b/hyperkitty/views/accounts.py @@ -87,25 +87,6 @@ def user_profile(request, user_email=None): "timezone": get_current_timezone(), }) - # Votes - try: - votes = Rating.objects.filter(user=request.user) - except Rating.DoesNotExist: - votes = [] - votes_up = [] - votes_down = [] - for vote in votes: - message = store.get_message_by_hash_from_list( - vote.list_address, vote.messageid) - vote_data = {"list_address": vote.list_address, - "messageid": vote.messageid, - "message": message, - } - if vote.vote == 1: - votes_up.append(vote_data) - elif vote.vote == -1: - votes_down.append(vote_data) - # Favorites try: favorites = Favorite.objects.filter(user=request.user) @@ -126,8 +107,6 @@ def user_profile(request, user_email=None): context = { 'user_profile' : user_profile, 'form': form, - 'votes_up': votes_up, - 'votes_down': votes_down, 'favorites': favorites, 'flash_messages': flash_messages, } @@ -195,3 +174,20 @@ def last_views(request): return render(request, 'ajax/last_views.html', { "last_views": last_views, }) + + +@login_required +def votes(request): + store = get_store(request) + # Votes + try: + votes = Rating.objects.filter(user=request.user) + except Rating.DoesNotExist: + votes = [] + votes = paginate(votes, request.GET.get('vpage')) + for vote in votes: + vote.message = store.get_message_by_hash_from_list( + vote.list_address, vote.messageid) + return render(request, 'ajax/votes.html', { + "votes": votes, + }) |