Commit fe8a347921f2abb937b8d559eff7f66ed37df900

Authored by fbormann
1 parent 3b391774

notification for poll creation was created #207

app/templates/home_teacher_student_content.html
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 </div> 11 </div>
12 <div class="col-xs-10 col-md-11"> 12 <div class="col-xs-10 col-md-11">
13 <i class="fa fa-pencil-square-o" aria-hidden="true"></i> 13 <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
14 - <h4 class="resource_inline"><b>{{ notification.actor }}</b></h4> 14 + <h4 class="resource_inline"><b>{{ notification.actor.username }}</b></h4>
15 <p class="resource_inline">{{notification.message}} em : <a href="{% url 'core:notification_read' notification.id %}">{{ notification.action_resource.resource.name }}</a></p> 15 <p class="resource_inline">{{notification.message}} em : <a href="{% url 'core:notification_read' notification.id %}">{{ notification.action_resource.resource.name }}</a></p>
16 <p class="timePost"><i> {{ notification.datetime|timesince }} {% trans "ago" %} </i></p> 16 <p class="timePost"><i> {{ notification.datetime|timesince }} {% trans "ago" %} </i></p>
17 </div> 17 </div>
core/mixins.py
@@ -44,7 +44,8 @@ class NotificationMixin(object): @@ -44,7 +44,8 @@ class NotificationMixin(object):
44 action_slug = '' 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_slug = '', resource_name='', resource_link=''): #the default will be a broadcast 47 + def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_slug = '',
  48 + resource_name='', resource_link=''): #the default will be a broadcast
48 action = Action.objects.filter(slug = action_slug) 49 action = Action.objects.filter(slug = action_slug)
49 resource = Resource.objects.filter(slug = resource_slug) 50 resource = Resource.objects.filter(slug = resource_slug)
50 if action.exists(): 51 if action.exists():
forum/views.py
@@ -58,7 +58,7 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView, NotificationM @@ -58,7 +58,7 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView, NotificationM
58 action = super(CreateForumView, self).createorRetrieveAction("create Topic") 58 action = super(CreateForumView, self).createorRetrieveAction("create Topic")
59 super(CreateForumView, self).createNotification("Forum "+ self.object.name + " was created", 59 super(CreateForumView, self).createNotification("Forum "+ self.object.name + " was created",
60 resource_name=self.object.name, resource_link= 'topics/'+self.object.slug, 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() ) 61 + actor=self.request.user, users = self.object.topic.subject.students.all() )
62 return self.success_url 62 return self.success_url
63 63
64 def render_forum(request, forum): 64 def render_forum(request, forum):
@@ -162,8 +162,8 @@ class CreatePostView(LoginRequiredMixin, generic.edit.CreateView, NotificationMi @@ -162,8 +162,8 @@ class CreatePostView(LoginRequiredMixin, generic.edit.CreateView, NotificationMi
162 self.object.user = self.request.user 162 self.object.user = self.request.user
163 163
164 self.object.save() 164 self.object.save()
165 - #super(CreatePostView, self).createNotification(self.object.user.username + " posted on " + self.object.forum,name,  
166 - #resource_slug = self.object.forum.slug, actor=self.request.user, users= self.object.forum.topic.) 165 + super(CreatePostView, self).createNotification(self.object.user.username + " posted on " + self.object.forum,name,
  166 + resource_slug = self.object.forum.slug, actor=self.request.user, users= self.object.forum.topic.subject.students.all())
167 167
168 return super(CreatePostView, self).form_valid(form) 168 return super(CreatePostView, self).form_valid(form)
169 169
poll/models.py
@@ -8,7 +8,6 @@ from courses.models import Activity @@ -8,7 +8,6 @@ from courses.models import Activity
8 class Poll(Activity): 8 class Poll(Activity):
9 9
10 class Meta: 10 class Meta:
11 - #ordering = ('create_date','name')  
12 verbose_name = _('Poll') 11 verbose_name = _('Poll')
13 verbose_name_plural = _('Polls') 12 verbose_name_plural = _('Polls')
14 13
@@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _ @@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _
9 from rolepermissions.verifications import has_role 9 from rolepermissions.verifications import has_role
10 from rolepermissions.verifications import has_object_permission 10 from rolepermissions.verifications import has_object_permission
11 from django.db.models import Q 11 from django.db.models import Q
12 -# from django.views.generic.edit import FormMixin 12 +from django.urls import reverse
13 13
14 from .forms import PollForm 14 from .forms import PollForm
15 from .models import Poll, Answer, AnswersStudent 15 from .models import Poll, Answer, AnswersStudent
@@ -41,7 +41,7 @@ class ViewPoll(LoginRequiredMixin,generic.DetailView): @@ -41,7 +41,7 @@ class ViewPoll(LoginRequiredMixin,generic.DetailView):
41 return context 41 return context
42 42
43 43
44 -class CreatePoll(LoginRequiredMixin,HasRoleMixin,generic.CreateView): 44 +class CreatePoll(LoginRequiredMixin,HasRoleMixin, NotificationMixin,generic.CreateView):
45 45
46 allowed_roles = ['professor', 'system_admin'] 46 allowed_roles = ['professor', 'system_admin']
47 login_url = reverse_lazy("core:home") 47 login_url = reverse_lazy("core:home")
@@ -63,15 +63,19 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin,generic.CreateView): @@ -63,15 +63,19 @@ class CreatePoll(LoginRequiredMixin,HasRoleMixin,generic.CreateView):
63 context.context_data['keys'] = keys 63 context.context_data['keys'] = keys
64 context.context_data['form'] = form 64 context.context_data['form'] = form
65 context.status_code = 400 65 context.status_code = 400
66 - # return self.render_to_response(context, status = 400) 66 + s
67 return context 67 return context
68 68
69 def form_valid(self, form): 69 def form_valid(self, form):
70 self.object = form.save(commit = False) 70 self.object = form.save(commit = False)
71 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) 71 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
72 self.object.topic = topic 72 self.object.topic = topic
  73 + self.object.name = str(self.object)
73 self.object.save() 74 self.object.save()
74 75
  76 + super(CreatePoll, self).createNotification(message="create a Poll "+ self.object.name, actor=self.request.user,
  77 + resource_name=self.object.name, resource_link= reverse('course:poll:view_poll', args=[self.object.slug]),
  78 + users=self.object.topic.subject.students.all())
75 for key in self.request.POST: 79 for key in self.request.POST:
76 if(key != 'csrfmiddlewaretoken' and key != 'name' and key != 'limit_date' and key != 'all_students' and key != 'students'): 80 if(key != 'csrfmiddlewaretoken' and key != 'name' and key != 'limit_date' and key != 'all_students' and key != 'students'):
77 answer = Answer(answer=self.request.POST[key],order=key,poll=self.object) 81 answer = Answer(answer=self.request.POST[key],order=key,poll=self.object)