Commit 1f6ecdb9cebe82f0d44f79cb6e1faa99b27c66fa
1 parent
8d54d0a4
Exists in
master
and in
5 other branches
modified template to support notifications from users with images, added new not…
…ifications for testing purposes, such as creating forum and topic #207
Showing
12 changed files
with
52 additions
and
16 deletions
Show diff stats
app/templates/home_teacher_student_content.html
@@ -15,8 +15,8 @@ | @@ -15,8 +15,8 @@ | ||
15 | </div> | 15 | </div> |
16 | <div class="col-xs-10 col-md-11"> | 16 | <div class="col-xs-10 col-md-11"> |
17 | <i class="fa fa-pencil-square-o" aria-hidden="true"></i> | 17 | <i class="fa fa-pencil-square-o" aria-hidden="true"></i> |
18 | - <a href=""><h4 class="resource_inline"><b>{{ notification.user }}</b></h4></a> | ||
19 | - <p class="resource_inline">{{notification.message}} em : <a href="{% url 'core:notification_read' notification.id %}">Recurso</a></p> | 18 | + <h4 class="resource_inline"><b>{{ notification.actor }}</b></h4> |
19 | + <p class="resource_inline">{{notification.message}} em : <a href="{% url 'core:notification_read' notification.id %}">{{ notification.action_resource.resource.name }}</a></p> | ||
20 | <p class="timePost"><i> {{ notification.datetime|timesince }} {% trans "ago" %} </i></p> | 20 | <p class="timePost"><i> {{ notification.datetime|timesince }} {% trans "ago" %} </i></p> |
21 | </div> | 21 | </div> |
22 | </div> | 22 | </div> |
core/decorators.py
@@ -60,7 +60,7 @@ def notification_decorator(read = False, message = '', actor = None, users = [], | @@ -60,7 +60,7 @@ def notification_decorator(read = False, message = '', actor = None, users = [], | ||
60 | if action.exists(): | 60 | if action.exists(): |
61 | action = action[0] | 61 | action = action[0] |
62 | else: | 62 | else: |
63 | - action = Action(name = not_action) | 63 | + action = Action(name = not_action) |
64 | action.save() | 64 | action.save() |
65 | 65 | ||
66 | if resource.exists(): | 66 | if resource.exists(): |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +# Generated by Django 1.10 on 2016-10-22 04:58 | ||
3 | +from __future__ import unicode_literals | ||
4 | + | ||
5 | +import autoslug.fields | ||
6 | +from django.db import migrations | ||
7 | + | ||
8 | + | ||
9 | +class Migration(migrations.Migration): | ||
10 | + | ||
11 | + dependencies = [ | ||
12 | + ('core', '0001_initial'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.AlterField( | ||
17 | + model_name='action', | ||
18 | + name='slug', | ||
19 | + field=autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True, verbose_name='Slug'), | ||
20 | + ), | ||
21 | + ] |
core/mixins.py
@@ -41,16 +41,16 @@ class LogMixin(object): | @@ -41,16 +41,16 @@ class LogMixin(object): | ||
41 | class NotificationMixin(object): | 41 | class NotificationMixin(object): |
42 | message = "" | 42 | message = "" |
43 | read = False | 43 | read = False |
44 | - action_name = '' | 44 | + action_slug = '' |
45 | resource_name = '' | 45 | resource_name = '' |
46 | 46 | ||
47 | - def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_name = '', resource_name='', resource_link=''): #the default will be a broadcast | ||
48 | - action = Action.objects.filter(name = action_name) | 47 | + def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_slug = '', resource_name='', resource_link=''): #the default will be a broadcast |
48 | + action = Action.objects.filter(slug = action_slug) | ||
49 | resource = Resource.objects.filter(slug = resource_slug) | 49 | resource = Resource.objects.filter(slug = resource_slug) |
50 | if action.exists(): | 50 | if action.exists(): |
51 | action = action[0] | 51 | action = action[0] |
52 | else: | 52 | else: |
53 | - action = Action(name = self.action_name) | 53 | + action = Action(name = self.action_slug) |
54 | action.save() | 54 | action.save() |
55 | 55 | ||
56 | if resource.exists(): | 56 | if resource.exists(): |
@@ -76,3 +76,9 @@ class NotificationMixin(object): | @@ -76,3 +76,9 @@ class NotificationMixin(object): | ||
76 | """ | 76 | """ |
77 | Not quite sure how to do about it""" | 77 | Not quite sure how to do about it""" |
78 | return super(NotificationMixin, self).dispatch(request, *args, **kwargs) | 78 | return super(NotificationMixin, self).dispatch(request, *args, **kwargs) |
79 | + | ||
80 | + def createorRetrieveAction(self, action_name): | ||
81 | + action = Action.objects.filter(name=action_name) | ||
82 | + if action is None: | ||
83 | + action = Action(name=action_name) | ||
84 | + return action | ||
79 | \ No newline at end of file | 85 | \ No newline at end of file |
core/models.py
@@ -25,6 +25,7 @@ class Action(models.Model): | @@ -25,6 +25,7 @@ class Action(models.Model): | ||
25 | """ | 25 | """ |
26 | 26 | ||
27 | name = models.CharField(_('Name'), max_length = 100) | 27 | name = models.CharField(_('Name'), max_length = 100) |
28 | + slug = AutoSlugField(_("Slug"), populate_from=('name'), unique=True) | ||
28 | created_date = models.DateField(_('Created Date'), auto_now_add=True) | 29 | created_date = models.DateField(_('Created Date'), auto_now_add=True) |
29 | 30 | ||
30 | class Meta: | 31 | class Meta: |
@@ -84,7 +85,7 @@ class Notification(models.Model): | @@ -84,7 +85,7 @@ class Notification(models.Model): | ||
84 | @action_resource: The Object that holds the information about which action was perfomed on the Resource | 85 | @action_resource: The Object that holds the information about which action was perfomed on the Resource |
85 | @actor: The user who applied the action | 86 | @actor: The user who applied the action |
86 | """ | 87 | """ |
87 | - | 88 | + |
88 | message = models.TextField(_('Message')) | 89 | message = models.TextField(_('Message')) |
89 | user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User')) | 90 | user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User')) |
90 | read = models.BooleanField(_('Read'), default = False) | 91 | read = models.BooleanField(_('Read'), default = False) |
core/static/css/base/amadeus.css
core/templates/notifications.html
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | <a href="{% url 'core:notification_read' notification.id %}"><div class="list-group-item"> | 6 | <a href="{% url 'core:notification_read' notification.id %}"><div class="list-group-item"> |
7 | <div class="row-picture"> | 7 | <div class="row-picture"> |
8 | <img class="circle" src="http://lorempixel.com/56/56/people/1" alt="icon"> | 8 | <img class="circle" src="http://lorempixel.com/56/56/people/1" alt="icon"> |
9 | - <div class="least-content pull-right">{{ notification.datetime }}</div> | 9 | + <div class="least-content ">{{ notification.datetime }}</div> |
10 | </div> | 10 | </div> |
11 | <div class="row-content"> | 11 | <div class="row-content"> |
12 | <p class="list-group-item-text">{{ notification.message }}</p> | 12 | <p class="list-group-item-text">{{ notification.message }}</p> |
core/views.py
@@ -68,7 +68,7 @@ def remember_password(request): | @@ -68,7 +68,7 @@ def remember_password(request): | ||
68 | context['danger'] = 'E-mail does not send' | 68 | context['danger'] = 'E-mail does not send' |
69 | return render(request, "remember_password.html",context) | 69 | return render(request, "remember_password.html",context) |
70 | 70 | ||
71 | -@notification_decorator(message='just connected') | 71 | +@notification_decorator(message='just connected', not_action="logged in", not_resource="") |
72 | @log_decorator('Acessar', 'Sistema') | 72 | @log_decorator('Acessar', 'Sistema') |
73 | def login(request): | 73 | def login(request): |
74 | context = {} | 74 | context = {} |
courses/models.py
@@ -7,6 +7,7 @@ from core.models import Resource, MimeType | @@ -7,6 +7,7 @@ from core.models import Resource, MimeType | ||
7 | from s3direct.fields import S3DirectField | 7 | from s3direct.fields import S3DirectField |
8 | 8 | ||
9 | from django.core.urlresolvers import reverse | 9 | from django.core.urlresolvers import reverse |
10 | +from core.models import Resource | ||
10 | 11 | ||
11 | class CourseCategory(models.Model): | 12 | class CourseCategory(models.Model): |
12 | 13 |
courses/templates/subject/form_view_teacher.html
@@ -178,7 +178,7 @@ | @@ -178,7 +178,7 @@ | ||
178 | </div> | 178 | </div> |
179 | <div class="modal-footer"> | 179 | <div class="modal-footer"> |
180 | 180 | ||
181 | - <a href="http://localhost:8080/html/screens/users/profile_user.html" target="_self"><button type="button" class="btn btn-primary">Confirm</button></a> | 181 | + <a href="" target="_self"><button type="button" class="btn btn-primary">Confirm</button></a> |
182 | 182 | ||
183 | </div> | 183 | </div> |
184 | </div> | 184 | </div> |
courses/views.py
@@ -429,7 +429,11 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener | @@ -429,7 +429,11 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener | ||
429 | self.object.subject = subject | 429 | self.object.subject = subject |
430 | self.object.owner = self.request.user | 430 | self.object.owner = self.request.user |
431 | self.object.save() | 431 | self.object.save() |
432 | - | 432 | + action = super(CreateTopicView, self).createorRetrieveAction("create Topic") |
433 | + super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created", | ||
434 | + resource_name=self.object.name, resource_link= 'topics/'+self.object.slug, | ||
435 | + actor=self.request.user, users = self.object.subject.course.students.all() ) | ||
436 | + | ||
433 | return super(CreateTopicView, self).form_valid(form) | 437 | return super(CreateTopicView, self).form_valid(form) |
434 | 438 | ||
435 | class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | 439 | class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): |
forum/views.py
@@ -10,6 +10,7 @@ from django.http import Http404 | @@ -10,6 +10,7 @@ from django.http import Http404 | ||
10 | from .models import Forum, Post, PostAnswer | 10 | from .models import Forum, Post, PostAnswer |
11 | from courses.models import Topic | 11 | from courses.models import Topic |
12 | from core.mixins import NotificationMixin | 12 | from core.mixins import NotificationMixin |
13 | +from core.models import Action, Resource | ||
13 | 14 | ||
14 | from .forms import ForumForm, PostForm, PostAnswerForm | 15 | from .forms import ForumForm, PostForm, PostAnswerForm |
15 | 16 | ||
@@ -52,10 +53,12 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView, NotificationM | @@ -52,10 +53,12 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView, NotificationM | ||
52 | 53 | ||
53 | def get_success_url(self): | 54 | def get_success_url(self): |
54 | self.success_url = reverse('course:forum:render_forum', args = (self.object.id, )) | 55 | self.success_url = reverse('course:forum:render_forum', args = (self.object.id, )) |
55 | - print(self.object) | ||
56 | - print(self) | ||
57 | - #super(CreateForumView, self).createNotification(message="The Forum",action_name="create forum", ) | 56 | + |
58 | 57 | ||
58 | + action = super(CreateForumView, self).createorRetrieveAction("create Topic") | ||
59 | + super(CreateForumView, self).createNotification("Forum "+ self.object.name + " was created", | ||
60 | + resource_name=self.object.name, resource_link= 'topics/'+self.object.slug, | ||
61 | + actor=self.request.user, users = self.object.topic.subject.course.students.all() ) | ||
59 | return self.success_url | 62 | return self.success_url |
60 | 63 | ||
61 | def render_forum(request, forum): | 64 | def render_forum(request, forum): |