Commit 9c696e78459982be3b189ddaea341afc3eaccd66
1 parent
fbaec8c4
Exists in
master
and in
3 other branches
Adding mural favorites table
Showing
4 changed files
with
60 additions
and
3 deletions
Show diff stats
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +# Generated by Django 1.10 on 2017-02-06 16:48 | ||
3 | +from __future__ import unicode_literals | ||
4 | + | ||
5 | +from django.conf import settings | ||
6 | +from django.db import migrations, models | ||
7 | +import django.db.models.deletion | ||
8 | + | ||
9 | + | ||
10 | +class Migration(migrations.Migration): | ||
11 | + | ||
12 | + dependencies = [ | ||
13 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
14 | + ('mural', '0003_auto_20170204_1625'), | ||
15 | + ] | ||
16 | + | ||
17 | + operations = [ | ||
18 | + migrations.CreateModel( | ||
19 | + name='MuralFavorites', | ||
20 | + fields=[ | ||
21 | + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
22 | + ], | ||
23 | + ), | ||
24 | + migrations.AlterField( | ||
25 | + model_name='mural', | ||
26 | + name='action', | ||
27 | + field=models.CharField(choices=[('comment', 'Comment'), ('help', 'Ask for Help')], default='comment', max_length=100, verbose_name='Action'), | ||
28 | + ), | ||
29 | + migrations.AddField( | ||
30 | + model_name='muralfavorites', | ||
31 | + name='post', | ||
32 | + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='favorites_post', to='mural.Mural', verbose_name='Post'), | ||
33 | + ), | ||
34 | + migrations.AddField( | ||
35 | + model_name='muralfavorites', | ||
36 | + name='user', | ||
37 | + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='favorites_user', to=settings.AUTH_USER_MODEL, verbose_name='User'), | ||
38 | + ), | ||
39 | + ] |
mural/models.py
@@ -45,4 +45,8 @@ class MuralVisualizations(models.Model): | @@ -45,4 +45,8 @@ class MuralVisualizations(models.Model): | ||
45 | viewed = models.BooleanField(_('Viewed'), default = False) | 45 | viewed = models.BooleanField(_('Viewed'), default = False) |
46 | post = models.ForeignKey(Mural, verbose_name = _('Post'), related_name = 'visualization_post', null = True) | 46 | post = models.ForeignKey(Mural, verbose_name = _('Post'), related_name = 'visualization_post', null = True) |
47 | comment = models.ForeignKey(Comment, verbose_name = _('Comment'), related_name = 'visualization_comment', null = True) | 47 | comment = models.ForeignKey(Comment, verbose_name = _('Comment'), related_name = 'visualization_comment', null = True) |
48 | - user = models.ForeignKey(User, verbose_name = _('User'), related_name = "visualization_user", null = True) | ||
49 | \ No newline at end of file | 48 | \ No newline at end of file |
49 | + user = models.ForeignKey(User, verbose_name = _('User'), related_name = "visualization_user", null = True) | ||
50 | + | ||
51 | +class MuralFavorites(models.Model): | ||
52 | + post = models.ForeignKey(Mural, verbose_name = _('Post'), related_name = 'favorites_post', null = True) | ||
53 | + user = models.ForeignKey(User, verbose_name = _('User'), related_name = "favorites_user", null = True) | ||
50 | \ No newline at end of file | 54 | \ No newline at end of file |
mural/templates/mural/_view.html
@@ -24,6 +24,11 @@ | @@ -24,6 +24,11 @@ | ||
24 | </ul> | 24 | </ul> |
25 | </span> | 25 | </span> |
26 | {% endif %} | 26 | {% endif %} |
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 }}"> | ||
29 | + <i class="fa fa-thumb-tack"></i> | ||
30 | + </button> | ||
31 | + </span> | ||
27 | </h4> | 32 | </h4> |
28 | <p class="time"> | 33 | <p class="time"> |
29 | <i class="fa fa-clock-o"></i> | 34 | <i class="fa fa-clock-o"></i> |
@@ -37,7 +42,6 @@ | @@ -37,7 +42,6 @@ | ||
37 | {% if post.image %} | 42 | {% if post.image %} |
38 | <img src="{{ post.image.url }}" class="img-responsive center-block" /> | 43 | <img src="{{ post.image.url }}" class="img-responsive center-block" /> |
39 | {% endif %} | 44 | {% endif %} |
40 | - | ||
41 | </div> | 45 | </div> |
42 | <div class="col-md-12 post-comment"> | 46 | <div class="col-md-12 post-comment"> |
43 | <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 user-img"> | 47 | <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 user-img"> |
mural/templatetags/mural_filters.py
1 | from django import template | 1 | from django import template |
2 | +from django.utils.translation import ugettext_lazy as _ | ||
3 | + | ||
4 | +from mural.models import MuralFavorites | ||
2 | 5 | ||
3 | register = template.Library() | 6 | register = template.Library() |
4 | 7 | ||
@@ -9,4 +12,11 @@ def action_icon(action): | @@ -9,4 +12,11 @@ def action_icon(action): | ||
9 | elif action == "help": | 12 | elif action == "help": |
10 | icon = "fa-comments-o" | 13 | icon = "fa-comments-o" |
11 | 14 | ||
12 | - return icon | ||
13 | \ No newline at end of file | 15 | \ No newline at end of file |
16 | + return icon | ||
17 | + | ||
18 | +@register.filter(name = 'fav_label') | ||
19 | +def fav_label(post, user): | ||
20 | + if MuralFavorites.objects.filter(post = post, user = user).exists(): | ||
21 | + return _('Unfavorite') | ||
22 | + | ||
23 | + return _('Favorite') | ||
14 | \ No newline at end of file | 24 | \ No newline at end of file |