Commit 91e85324f74ba84d83fd1d7c98956e84f99ec518
1 parent
90d4aaa1
Exists in
master
and in
3 other branches
Adding favorite post function
Showing
8 changed files
with
75 additions
and
4 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
@@ -1069,4 +1069,8 @@ li.item .notify_badge { | @@ -1069,4 +1069,8 @@ li.item .notify_badge { | ||
1069 | font-size: 14px; | 1069 | font-size: 14px; |
1070 | font-style: italic; | 1070 | font-style: italic; |
1071 | cursor: text; | 1071 | cursor: text; |
1072 | +} | ||
1073 | + | ||
1074 | +.btn:focus, .btn:active:focus, .btn.active:focus, .btn.focus, .btn:active.focus, .btn.active.focus { | ||
1075 | + outline: none; | ||
1072 | } | 1076 | } |
1073 | \ No newline at end of file | 1077 | \ No newline at end of file |
amadeus/static/css/themes/green.css
@@ -534,6 +534,18 @@ a.add-row { | @@ -534,6 +534,18 @@ a.add-row { | ||
534 | background: #FFFFFF; | 534 | background: #FFFFFF; |
535 | } | 535 | } |
536 | 536 | ||
537 | +.btn_unfav { | ||
538 | + color: #FF0000 !important; | ||
539 | +} | ||
540 | + | ||
541 | +.btn_fav { | ||
542 | + color: #BBBBBB !important; | ||
543 | +} | ||
544 | + | ||
545 | +.btn:not(.btn-raised):not(.btn-link):focus, .btn:not(.btn-raised):not(.btn-link):hover, .input-group-btn .btn:not(.btn-raised):not(.btn-link):focus, .input-group-btn .btn:not(.btn-raised):not(.btn-link):hover { | ||
546 | + background-color: initial; | ||
547 | +} | ||
548 | + | ||
537 | @media(max-width: 768px) { | 549 | @media(max-width: 768px) { |
538 | .navbar .navbar-nav .dropdown .dropdown-menu li > a { | 550 | .navbar .navbar-nav .dropdown .dropdown-menu li > a { |
539 | color: #333333 !important; | 551 | color: #333333 !important; |
amadeus/static/js/main.js
@@ -14,7 +14,9 @@ $(function () { | @@ -14,7 +14,9 @@ $(function () { | ||
14 | height: 200 | 14 | height: 200 |
15 | }); | 15 | }); |
16 | 16 | ||
17 | - $('[data-toggle="tooltip"]').tooltip(); | 17 | + $('[data-toggle="tooltip"]').tooltip({ |
18 | + trigger: 'hover' | ||
19 | + }); | ||
18 | 20 | ||
19 | //Dropdown menu collapse | 21 | //Dropdown menu collapse |
20 | $('.dropdown-accordion').on('click', 'a[data-toggle="collapse"]', function (event) { | 22 | $('.dropdown-accordion').on('click', 'a[data-toggle="collapse"]', function (event) { |
mural/templates/mural/_view.html
@@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
25 | </span> | 25 | </span> |
26 | {% endif %} | 26 | {% endif %} |
27 | <span class="btn-group pull-right"> | 27 | <span class="btn-group pull-right"> |
28 | - <button class="btn btn-sm btn_menu" data-toggle="tooltip" data-placement="top" title="{{ post|fav_label:request.user }}"> | 28 | + <button class="btn btn-sm btn_menu {{ post|fav_class:request.user }}" onclick="favorite($(this))" data-url="{% url 'mural:favorite' post.mural_ptr_id %}" data-action="{{ post|fav_action:request.user }}" data-toggle="tooltip" data-placement="top" title="{{ post|fav_label:request.user }}"> |
29 | <i class="fa fa-thumb-tack"></i> | 29 | <i class="fa fa-thumb-tack"></i> |
30 | </button> | 30 | </button> |
31 | </span> | 31 | </span> |
mural/templates/mural/list.html
@@ -102,5 +102,28 @@ | @@ -102,5 +102,28 @@ | ||
102 | return false; | 102 | return false; |
103 | }); | 103 | }); |
104 | } | 104 | } |
105 | + | ||
106 | + function favorite(btn) { | ||
107 | + var action = btn.data('action'), | ||
108 | + url = btn.data('url'); | ||
109 | + | ||
110 | + $.ajax({ | ||
111 | + url: url, | ||
112 | + data: {'action': action}, | ||
113 | + dataType: 'json', | ||
114 | + success: function (response) { | ||
115 | + if (action == 'favorite') { | ||
116 | + btn.switchClass("btn_fav", "btn_unfav", 250, "easeInOutQuad"); | ||
117 | + btn.data('action', 'unfavorite'); | ||
118 | + } else { | ||
119 | + btn.switchClass("btn_unfav", "btn_fav", 250, "easeInOutQuad"); | ||
120 | + btn.data('action', 'favorite'); | ||
121 | + } | ||
122 | + | ||
123 | + btn.attr('data-original-title', response.label); | ||
124 | + } | ||
125 | + }); | ||
126 | + | ||
127 | + } | ||
105 | </script> | 128 | </script> |
106 | {% endblock %} | 129 | {% endblock %} |
107 | \ No newline at end of file | 130 | \ No newline at end of file |
mural/templatetags/mural_filters.py
@@ -19,4 +19,18 @@ def fav_label(post, user): | @@ -19,4 +19,18 @@ def fav_label(post, user): | ||
19 | if MuralFavorites.objects.filter(post = post, user = user).exists(): | 19 | if MuralFavorites.objects.filter(post = post, user = user).exists(): |
20 | return _('Unfavorite') | 20 | return _('Unfavorite') |
21 | 21 | ||
22 | - return _('Favorite') | ||
23 | \ No newline at end of file | 22 | \ No newline at end of file |
23 | + return _('Favorite') | ||
24 | + | ||
25 | +@register.filter(name = 'fav_action') | ||
26 | +def fav_action(post, user): | ||
27 | + if MuralFavorites.objects.filter(post = post, user = user).exists(): | ||
28 | + return "unfavorite" | ||
29 | + | ||
30 | + return "favorite" | ||
31 | + | ||
32 | +@register.filter(name = 'fav_class') | ||
33 | +def fav_class(post, user): | ||
34 | + if MuralFavorites.objects.filter(post = post, user = user).exists(): | ||
35 | + return "btn_unfav" | ||
36 | + | ||
37 | + return "btn_fav" | ||
24 | \ No newline at end of file | 38 | \ No newline at end of file |
mural/urls.py
@@ -5,4 +5,5 @@ urlpatterns = [ | @@ -5,4 +5,5 @@ urlpatterns = [ | ||
5 | url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), | 5 | url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), |
6 | url(r'^create_gen/$', views.GeneralCreate.as_view(), name='create_general'), | 6 | url(r'^create_gen/$', views.GeneralCreate.as_view(), name='create_general'), |
7 | url(r'^render_post/([\w_-]+)/$', views.render_gen_post, name='render_post_general'), | 7 | url(r'^render_post/([\w_-]+)/$', views.render_gen_post, name='render_post_general'), |
8 | + url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), | ||
8 | ] | 9 | ] |
9 | \ No newline at end of file | 10 | \ No newline at end of file |
mural/views.py
@@ -6,6 +6,7 @@ from django.template.loader import render_to_string | @@ -6,6 +6,7 @@ from django.template.loader import render_to_string | ||
6 | from django.core.urlresolvers import reverse, reverse_lazy | 6 | from django.core.urlresolvers import reverse, reverse_lazy |
7 | from django.utils.translation import ugettext_lazy as _ | 7 | from django.utils.translation import ugettext_lazy as _ |
8 | from django.contrib.auth.mixins import LoginRequiredMixin | 8 | from django.contrib.auth.mixins import LoginRequiredMixin |
9 | +from django.contrib.auth.decorators import login_required | ||
9 | from django.db.models import Q, Count | 10 | from django.db.models import Q, Count |
10 | 11 | ||
11 | from channels import Group | 12 | from channels import Group |
@@ -13,7 +14,7 @@ import json | @@ -13,7 +14,7 @@ import json | ||
13 | 14 | ||
14 | from users.models import User | 15 | from users.models import User |
15 | 16 | ||
16 | -from .models import GeneralPost, CategoryPost, SubjectPost, MuralVisualizations | 17 | +from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites |
17 | from .forms import GeneralPostForm | 18 | from .forms import GeneralPostForm |
18 | 19 | ||
19 | class GeneralIndex(LoginRequiredMixin, generic.ListView): | 20 | class GeneralIndex(LoginRequiredMixin, generic.ListView): |
@@ -103,3 +104,17 @@ def render_gen_post(request, post): | @@ -103,3 +104,17 @@ def render_gen_post(request, post): | ||
103 | html = render_to_string("mural/_view.html", context, request) | 104 | html = render_to_string("mural/_view.html", context, request) |
104 | 105 | ||
105 | return JsonResponse({'message': _('Your post was published successfully!'), 'view': html}) | 106 | return JsonResponse({'message': _('Your post was published successfully!'), 'view': html}) |
107 | + | ||
108 | +@login_required | ||
109 | +def favorite(request, post): | ||
110 | + action = request.GET.get('action', '') | ||
111 | + post = get_object_or_404(Mural, id = post) | ||
112 | + | ||
113 | + if action == 'favorite': | ||
114 | + MuralFavorites.objects.create(post = post, user = request.user) | ||
115 | + | ||
116 | + return JsonResponse({'label': _('Unfavorite')}) | ||
117 | + else: | ||
118 | + MuralFavorites.objects.filter(post = post, user = request.user).delete() | ||
119 | + | ||
120 | + return JsonResponse({'label': _('Favorite')}) | ||
106 | \ No newline at end of file | 121 | \ No newline at end of file |