Commit 5b10ad00f2f67aa12a528b8a644e2a53a05fcc91
1 parent
cad76c55
Exists in
master
and in
5 other branches
ajustes para o usuário guest #387
Showing
7 changed files
with
120 additions
and
134 deletions
Show diff stats
core/templates/guest.html
1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
2 | 2 | ||
3 | 3 | ||
4 | -{% load i18n custom_filters %} | ||
5 | -{% load static i18n %} | ||
6 | -{% load pagination %} | 4 | +{% load static i18n custom_filters %} |
7 | 5 | ||
8 | <html> | 6 | <html> |
9 | <head> | 7 | <head> |
@@ -98,56 +96,33 @@ | @@ -98,56 +96,33 @@ | ||
98 | {% block content %} | 96 | {% block content %} |
99 | 97 | ||
100 | <div class="col-md-12 cards-content"> | 98 | <div class="col-md-12 cards-content"> |
101 | - {% for category in categorys_courses %} | ||
102 | - <div class="panel-group"> | ||
103 | - <div class="panel panel-default"> | ||
104 | - <div class="panel-heading"> | ||
105 | - <h4 class="panel-title"> | ||
106 | - <a class="category-course-link" data-toggle="collapse" href="#{{category.slug}}">{{category.name}}</a> | ||
107 | - </h4> | ||
108 | - | ||
109 | - </div> | ||
110 | - <div id="{{category.slug}}" class="panel-collapse collapse"> | ||
111 | - {% for course in category.course_category.all %} | ||
112 | - {%if course.public == True %} | ||
113 | - {% include "course/course_card.html" %} | ||
114 | - {% endif %} | ||
115 | - {% endfor %} | ||
116 | - </div> | ||
117 | - </div> | 99 | + {% for category in categorys_courses %} |
100 | + <div class="panel-group course-card-group"> | ||
101 | + <div class="panel panel-default"> | ||
102 | + <div class="panel-heading"> | ||
103 | + <div class="row"> | ||
104 | + <div class="col-md-12"> | ||
105 | + <h4 class="panel-title"> | ||
106 | + <a class="category-course-link" data-toggle="collapse" href="#{{category.slug}}">{{category.name}}</a> | ||
107 | + </h4> | ||
108 | + </div> | ||
118 | </div> | 109 | </div> |
119 | - {% endfor %} | 110 | + </div> |
111 | + <div id="{{category.slug}}" class="panel-collapse collapse"> | ||
112 | + {% for course in category.course_category %} | ||
113 | + {% include "course/course_card.html" %} | ||
114 | + {% endfor %} | ||
115 | + </div> | ||
116 | + </div> | ||
117 | + </div> | ||
118 | + {% endfor %} | ||
120 | </div> | 119 | </div> |
121 | - <div class="col-md-12"> | ||
122 | - <nav aria-label="Page navigation"> | ||
123 | - <ul class="pagination"> | ||
124 | - {% if page_obj.has_previous %} | ||
125 | - <li> | ||
126 | - <a href="?page={{ page_obj.previous_page_number }}"><span><<</span></a> | ||
127 | - </li> | ||
128 | - {% endif %} | ||
129 | - {% for page_number in paginator.page_range %} | ||
130 | - <li{% if page_obj.number == page_number %} class="active"{% endif %}> | ||
131 | - <a href="?page={{ page_number }}">{{ page_number }}</a> | ||
132 | - </li> | ||
133 | - {% endfor %} | ||
134 | - {% if page_obj.has_next %} | ||
135 | - <li> | ||
136 | - <a href="?page={{ page_obj.next_page_number }}"><span>>></span></a> | ||
137 | - </li> | ||
138 | - {% endif %} | ||
139 | - </ul> | ||
140 | - </nav> | ||
141 | - </div> | ||
142 | {% endblock %} | 120 | {% endblock %} |
143 | </div> | 121 | </div> |
144 | </div> | 122 | </div> |
145 | </div> | 123 | </div> |
146 | <script src="{% static 'js/main.js' %}"></script> | 124 | <script src="{% static 'js/main.js' %}"></script> |
147 | <script type="text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script> | 125 | <script type="text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script> |
148 | - {% block script_file %} | ||
149 | - | ||
150 | - {% endblock script_file %} | ||
151 | </body> | 126 | </body> |
152 | 127 | ||
153 | </html> | 128 | </html> |
core/views.py
@@ -28,6 +28,8 @@ from .decorators import log_decorator, notification_decorator | @@ -28,6 +28,8 @@ from .decorators import log_decorator, notification_decorator | ||
28 | from users.models import User | 28 | from users.models import User |
29 | from courses.models import Course, CourseCategory | 29 | from courses.models import Course, CourseCategory |
30 | 30 | ||
31 | +from courses.views import course_category | ||
32 | + | ||
31 | def index(request): | 33 | def index(request): |
32 | context = { | 34 | context = { |
33 | 'subscribed_courses': 'testando' | 35 | 'subscribed_courses': 'testando' |
@@ -106,23 +108,22 @@ class GuestView (ListView): | @@ -106,23 +108,22 @@ class GuestView (ListView): | ||
106 | template_name = 'guest.html' | 108 | template_name = 'guest.html' |
107 | context_object_name = 'courses' | 109 | context_object_name = 'courses' |
108 | queryset = CourseCategory.objects.all() | 110 | queryset = CourseCategory.objects.all() |
109 | - paginate_by = 3 | ||
110 | 111 | ||
111 | def get_context_data (self, **kwargs): | 112 | def get_context_data (self, **kwargs): |
112 | context = super(GuestView, self).get_context_data(**kwargs) | 113 | context = super(GuestView, self).get_context_data(**kwargs) |
113 | context['title'] = _("Guest") | 114 | context['title'] = _("Guest") |
114 | - queryset_list = CourseCategory.objects.all() | ||
115 | - | ||
116 | - paginator = Paginator(queryset_list, 3) | ||
117 | - page = self.request.GET.get('page') | ||
118 | - try: | ||
119 | - queryset_list = paginator.page(page) | ||
120 | - except PageNotAnInteger: | ||
121 | - queryset_list = paginator.page(1) | ||
122 | - except EmptyPage: | ||
123 | - queryset_list = paginator.page(paginator.num_pages) | ||
124 | - | ||
125 | - context['categorys_courses'] = queryset_list | 115 | + queryset_list = Course.objects.filter(public=True) |
116 | + | ||
117 | + # paginator = Paginator(queryset_list, 3) | ||
118 | + # page = self.request.GET.get('page') | ||
119 | + # try: | ||
120 | + # queryset_list = paginator.page(page) | ||
121 | + # except PageNotAnInteger: | ||
122 | + # queryset_list = paginator.page(1) | ||
123 | + # except EmptyPage: | ||
124 | + # queryset_list = paginator.page(paginator.num_pages) | ||
125 | + | ||
126 | + context['categorys_courses'] = course_category(queryset_list) | ||
126 | return context | 127 | return context |
127 | 128 | ||
128 | 129 |
courses/templates/course/view.html
courses/templates/subject/index.html
@@ -66,12 +66,6 @@ | @@ -66,12 +66,6 @@ | ||
66 | <div class="panel-group" id="topics" role="tablist" aria-multiselectable="true"> | 66 | <div class="panel-group" id="topics" role="tablist" aria-multiselectable="true"> |
67 | {% for topic in topics %} | 67 | {% for topic in topics %} |
68 | {% include "topic/index.html" %} | 68 | {% include "topic/index.html" %} |
69 | - {# {% professor_subject topic.subject user as topic_professor%}#} | ||
70 | - {# {% if topic_professor %}#} | ||
71 | - {# {% include "subject/form_view_teacher.html" %}#} | ||
72 | - {# {% else %}#} | ||
73 | - {# {% include "subject/form_view_student.html" %}#} | ||
74 | - {# {% endif %}#} | ||
75 | {% endfor %} | 69 | {% endfor %} |
76 | </div> | 70 | </div> |
77 | 71 |
courses/templates/topic/view.html
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | <h4>{% trans 'Material' %}</h4> | 15 | <h4>{% trans 'Material' %}</h4> |
16 | </div> | 16 | </div> |
17 | {% professor_subject topic.subject user as dropdown_topic %} | 17 | {% professor_subject topic.subject user as dropdown_topic %} |
18 | - {% if dropdown_topic %} | 18 | + {% if dropdown_topic %} |
19 | <div class="resource_inline"> | 19 | <div class="resource_inline"> |
20 | 20 | ||
21 | {# dropdown de create material #} | 21 | {# dropdown de create material #} |
@@ -35,13 +35,14 @@ | @@ -35,13 +35,14 @@ | ||
35 | </ul> | 35 | </ul> |
36 | </div> | 36 | </div> |
37 | 37 | ||
38 | + {% if user.is_authenticated %} | ||
38 | {# avaliações do topico #} | 39 | {# avaliações do topico #} |
39 | <div class="col-xs-6 col-md-6"> | 40 | <div class="col-xs-6 col-md-6"> |
40 | <div class="resource_inline"> | 41 | <div class="resource_inline"> |
41 | <h4>{% trans 'Activities' %}</h4> | 42 | <h4>{% trans 'Activities' %}</h4> |
42 | </div> | 43 | </div> |
43 | {% professor_subject topic.subject user as dropdown_topic %} | 44 | {% professor_subject topic.subject user as dropdown_topic %} |
44 | - {% if dropdown_topic %} | 45 | + {% if dropdown_topic %} |
45 | <div class="resource_inline"> | 46 | <div class="resource_inline"> |
46 | 47 | ||
47 | {# dropdown de avaliações #} | 48 | {# dropdown de avaliações #} |
@@ -63,4 +64,5 @@ | @@ -63,4 +64,5 @@ | ||
63 | {% list_topic_exercise request topic %} | 64 | {% list_topic_exercise request topic %} |
64 | </ul> | 65 | </ul> |
65 | </div> | 66 | </div> |
67 | + {% endif %} | ||
66 | </div> | 68 | </div> |
courses/views.py
@@ -7,7 +7,7 @@ from courses.models import Material | @@ -7,7 +7,7 @@ from courses.models import Material | ||
7 | from datetime import date, datetime | 7 | from datetime import date, datetime |
8 | from django.contrib import messages | 8 | from django.contrib import messages |
9 | from django.contrib.auth.decorators import login_required | 9 | from django.contrib.auth.decorators import login_required |
10 | -from django.contrib.auth.mixins import LoginRequiredMixin | 10 | +from django.contrib.auth.mixins import LoginRequiredMixin,AccessMixin |
11 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | 11 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
12 | from django.core.urlresolvers import reverse_lazy | 12 | from django.core.urlresolvers import reverse_lazy |
13 | from django.db.models import Q | 13 | from django.db.models import Q |
@@ -320,18 +320,24 @@ class DeleteCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Delet | @@ -320,18 +320,24 @@ class DeleteCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Delet | ||
320 | return reverse_lazy('course:manage') | 320 | return reverse_lazy('course:manage') |
321 | 321 | ||
322 | 322 | ||
323 | -class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.DetailView): | 323 | +class CourseView(AccessMixin, LogMixin, NotificationMixin, generic.DetailView): |
324 | log_component = "courses" | 324 | log_component = "courses" |
325 | log_action = "viewed" | 325 | log_action = "viewed" |
326 | log_resource = "course" | 326 | log_resource = "course" |
327 | log_context = {} | 327 | log_context = {} |
328 | 328 | ||
329 | + | ||
329 | login_url = reverse_lazy("core:home") | 330 | login_url = reverse_lazy("core:home") |
330 | redirect_field_name = 'next' | 331 | redirect_field_name = 'next' |
331 | model = Course | 332 | model = Course |
332 | context_object_name = 'course' | 333 | context_object_name = 'course' |
333 | template_name = 'course/view.html' | 334 | template_name = 'course/view.html' |
334 | 335 | ||
336 | + def dispatch(self, *args, **kwargs): | ||
337 | + course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | ||
338 | + if(not self.request.user.is_authenticated and not course.public): | ||
339 | + return self.handle_no_permission() | ||
340 | + return super(CourseView, self).dispatch(*args, **kwargs) | ||
335 | 341 | ||
336 | def get_context_data(self, **kwargs): | 342 | def get_context_data(self, **kwargs): |
337 | subjects = None | 343 | subjects = None |
@@ -339,16 +345,17 @@ class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.Detail | @@ -339,16 +345,17 @@ class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.Detail | ||
339 | context = super(CourseView, self).get_context_data(**kwargs) | 345 | context = super(CourseView, self).get_context_data(**kwargs) |
340 | course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | 346 | course = get_object_or_404(Course, slug = self.kwargs.get('slug')) |
341 | 347 | ||
342 | - self.log_context['course_id'] = course.id | ||
343 | - self.log_context['course_name'] = course.name | ||
344 | - self.log_context['course_slug'] = course.slug | ||
345 | - self.log_context['course_category_id'] = course.category.id | ||
346 | - self.log_context['course_category_name'] = course.category.name | ||
347 | - self.log_context['timestamp_start'] = str(int(time.time())) | 348 | + if (self.request.user.is_authenticated): |
349 | + self.log_context['course_id'] = course.id | ||
350 | + self.log_context['course_name'] = course.name | ||
351 | + self.log_context['course_slug'] = course.slug | ||
352 | + self.log_context['course_category_id'] = course.category.id | ||
353 | + self.log_context['course_category_name'] = course.category.name | ||
354 | + self.log_context['timestamp_start'] = str(int(time.time())) | ||
348 | 355 | ||
349 | - super(CourseView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 356 | + super(CourseView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
350 | 357 | ||
351 | - self.request.session['log_id'] = Log.objects.latest('id').id | 358 | + self.request.session['log_id'] = Log.objects.latest('id').id |
352 | 359 | ||
353 | category_sub = self.kwargs.get('category', None) | 360 | category_sub = self.kwargs.get('category', None) |
354 | 361 | ||
@@ -356,7 +363,7 @@ class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.Detail | @@ -356,7 +363,7 @@ class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.Detail | ||
356 | subjects = course.subjects.all() | 363 | subjects = course.subjects.all() |
357 | elif has_role(self.request.user,'professor'): | 364 | elif has_role(self.request.user,'professor'): |
358 | subjects = course.subjects.filter(professors__in=[self.request.user]) | 365 | subjects = course.subjects.filter(professors__in=[self.request.user]) |
359 | - elif has_role(self.request.user, 'student') or self.request.user is None: | 366 | + elif has_role(self.request.user, 'student') or course.public: |
360 | subjects = course.subjects.filter(visible=True) | 367 | subjects = course.subjects.filter(visible=True) |
361 | 368 | ||
362 | if not category_sub is None: | 369 | if not category_sub is None: |
@@ -389,6 +396,10 @@ class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.Detail | @@ -389,6 +396,10 @@ class CourseView(LoginRequiredMixin, LogMixin, NotificationMixin, generic.Detail | ||
389 | context['courses'] = courses | 396 | context['courses'] = courses |
390 | context['course'] = course | 397 | context['course'] = course |
391 | context['title'] = course.name | 398 | context['title'] = course.name |
399 | + if (self.request.user.is_authenticated): | ||
400 | + context['extend'] = 'course/index.html' | ||
401 | + else: | ||
402 | + context['extend'] = 'guest.html' | ||
392 | 403 | ||
393 | return context | 404 | return context |
394 | 405 | ||
@@ -558,7 +569,7 @@ class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | @@ -558,7 +569,7 @@ class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | ||
558 | messages.success(self.request, _('Category deleted successfully!')) | 569 | messages.success(self.request, _('Category deleted successfully!')) |
559 | return reverse_lazy('course:manage_cat') | 570 | return reverse_lazy('course:manage_cat') |
560 | 571 | ||
561 | -class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): | 572 | +class SubjectsView(AccessMixin, LogMixin, generic.ListView): |
562 | log_component = "course" | 573 | log_component = "course" |
563 | log_resource = "subject" | 574 | log_resource = "subject" |
564 | log_action = "viewed" | 575 | log_action = "viewed" |
@@ -573,22 +584,23 @@ class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): | @@ -573,22 +584,23 @@ class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): | ||
573 | def dispatch(self, *args, **kwargs): | 584 | def dispatch(self, *args, **kwargs): |
574 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) | 585 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) |
575 | 586 | ||
576 | - if(not has_object_permission('view_subject', self.request.user, subject)): | 587 | + if(not has_object_permission('view_subject', self.request.user, subject) and not subject.course.public): |
577 | return self.handle_no_permission() | 588 | return self.handle_no_permission() |
578 | 589 | ||
579 | - self.log_context['subject_id'] = subject.id | ||
580 | - self.log_context['subject_name'] = subject.name | ||
581 | - self.log_context['subject_slug'] = subject.slug | ||
582 | - self.log_context['course_id'] = subject.course.id | ||
583 | - self.log_context['course_name'] = subject.course.name | ||
584 | - self.log_context['course_slug'] = subject.course.slug | ||
585 | - self.log_context['course_category_id'] = subject.course.category.id | ||
586 | - self.log_context['course_category_name'] = subject.course.category.name | ||
587 | - self.log_context['timestamp_start'] = str(int(time.time())) | 590 | + if (self.request.user.is_authenticated): |
591 | + self.log_context['subject_id'] = subject.id | ||
592 | + self.log_context['subject_name'] = subject.name | ||
593 | + self.log_context['subject_slug'] = subject.slug | ||
594 | + self.log_context['course_id'] = subject.course.id | ||
595 | + self.log_context['course_name'] = subject.course.name | ||
596 | + self.log_context['course_slug'] = subject.course.slug | ||
597 | + self.log_context['course_category_id'] = subject.course.category.id | ||
598 | + self.log_context['course_category_name'] = subject.course.category.name | ||
599 | + self.log_context['timestamp_start'] = str(int(time.time())) | ||
588 | 600 | ||
589 | - super(SubjectsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 601 | + super(SubjectsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
590 | 602 | ||
591 | - self.request.session['log_id'] = Log.objects.latest('id').id | 603 | + self.request.session['log_id'] = Log.objects.latest('id').id |
592 | 604 | ||
593 | return super(SubjectsView, self).dispatch(*args, **kwargs) | 605 | return super(SubjectsView, self).dispatch(*args, **kwargs) |
594 | 606 | ||
@@ -610,8 +622,14 @@ class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): | @@ -610,8 +622,14 @@ class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): | ||
610 | context['title'] = subject.name | 622 | context['title'] = subject.name |
611 | if has_role(self.request.user,'professor') or has_role(self.request.user,'system_admin'): | 623 | if has_role(self.request.user,'professor') or has_role(self.request.user,'system_admin'): |
612 | context['files'] = TopicFile.objects.filter(professor__name = self.request.user.name) | 624 | context['files'] = TopicFile.objects.filter(professor__name = self.request.user.name) |
613 | - else: | 625 | + elif has_role(self.request.user,'student'): |
614 | context['files'] = TopicFile.objects.filter(students__name = self.request.user.name) | 626 | context['files'] = TopicFile.objects.filter(students__name = self.request.user.name) |
627 | + | ||
628 | + if (self.request.user.is_authenticated): | ||
629 | + context['extend'] = 'course/index.html' | ||
630 | + else: | ||
631 | + context['extend'] = 'guest.html' | ||
632 | + | ||
615 | return context | 633 | return context |
616 | 634 | ||
617 | 635 | ||
@@ -633,7 +651,7 @@ class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView): | @@ -633,7 +651,7 @@ class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView): | ||
633 | 651 | ||
634 | return self.success_url | 652 | return self.success_url |
635 | 653 | ||
636 | -class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): | 654 | +class TopicsView(AccessMixin,LogMixin, generic.TemplateView): |
637 | log_component = "course" | 655 | log_component = "course" |
638 | log_resource = "topic" | 656 | log_resource = "topic" |
639 | log_action = "viewed" | 657 | log_action = "viewed" |
@@ -647,7 +665,7 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): | @@ -647,7 +665,7 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): | ||
647 | def dispatch(self, *args, **kwargs): | 665 | def dispatch(self, *args, **kwargs): |
648 | topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | 666 | topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) |
649 | 667 | ||
650 | - if(not has_object_permission('view_topic', self.request.user, topic)): | 668 | + if(not has_object_permission('view_topic', self.request.user, topic) and not topic.subject.course.public): |
651 | return self.handle_no_permission() | 669 | return self.handle_no_permission() |
652 | 670 | ||
653 | return super(TopicsView, self).dispatch(*args, **kwargs) | 671 | return super(TopicsView, self).dispatch(*args, **kwargs) |
@@ -660,25 +678,23 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): | @@ -660,25 +678,23 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): | ||
660 | context = super(TopicsView, self).get_context_data(**kwargs) | 678 | context = super(TopicsView, self).get_context_data(**kwargs) |
661 | context['topic'] = topic | 679 | context['topic'] = topic |
662 | 680 | ||
663 | - if(not has_object_permission('view_topic', self.request.user, topic)): | ||
664 | - return self.handle_no_permission() | ||
665 | - | ||
666 | - self.log_context['topic_id'] = topic.id | ||
667 | - self.log_context['topic_name'] = topic.name | ||
668 | - self.log_context['topic_slug'] = topic.slug | ||
669 | - self.log_context['subject_id'] = topic.subject.id | ||
670 | - self.log_context['subject_name'] = topic.subject.name | ||
671 | - self.log_context['subject_slug'] = topic.subject.slug | ||
672 | - self.log_context['course_id'] = topic.subject.course.id | ||
673 | - self.log_context['course_name'] = topic.subject.course.name | ||
674 | - self.log_context['course_slug'] = topic.subject.course.slug | ||
675 | - self.log_context['course_category_id'] = topic.subject.course.category.id | ||
676 | - self.log_context['course_category_name'] = topic.subject.course.category.name | ||
677 | - self.log_context['timestamp_start'] = str(int(time.time())) | ||
678 | - | ||
679 | - super(TopicsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
680 | - | ||
681 | - context['topic_log_id'] = Log.objects.latest('id').id | 681 | + if (self.request.user.is_authenticated): |
682 | + self.log_context['topic_id'] = topic.id | ||
683 | + self.log_context['topic_name'] = topic.name | ||
684 | + self.log_context['topic_slug'] = topic.slug | ||
685 | + self.log_context['subject_id'] = topic.subject.id | ||
686 | + self.log_context['subject_name'] = topic.subject.name | ||
687 | + self.log_context['subject_slug'] = topic.subject.slug | ||
688 | + self.log_context['course_id'] = topic.subject.course.id | ||
689 | + self.log_context['course_name'] = topic.subject.course.name | ||
690 | + self.log_context['course_slug'] = topic.subject.course.slug | ||
691 | + self.log_context['course_category_id'] = topic.subject.course.category.id | ||
692 | + self.log_context['course_category_name'] = topic.subject.course.category.name | ||
693 | + self.log_context['timestamp_start'] = str(int(time.time())) | ||
694 | + | ||
695 | + super(TopicsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
696 | + | ||
697 | + context['topic_log_id'] = Log.objects.latest('id').id | ||
682 | 698 | ||
683 | return context | 699 | return context |
684 | 700 |
links/views.py
@@ -220,38 +220,36 @@ class UpdateLink(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView) | @@ -220,38 +220,36 @@ class UpdateLink(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView) | ||
220 | self.success_url = reverse_lazy('course:links:render_link', args = (self.object.slug, )) | 220 | self.success_url = reverse_lazy('course:links:render_link', args = (self.object.slug, )) |
221 | return self.success_url | 221 | return self.success_url |
222 | 222 | ||
223 | -class ViewLink(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.DetailView): | 223 | +class ViewLink(LogMixin, generic.DetailView): |
224 | log_component = 'link' | 224 | log_component = 'link' |
225 | log_resource = 'link' | 225 | log_resource = 'link' |
226 | log_action = 'viewed' | 226 | log_action = 'viewed' |
227 | log_context = {} | 227 | log_context = {} |
228 | - | ||
229 | - allowed_roles = ['professor', 'system_admin','student'] | 228 | + |
230 | template_name = 'links/view_link.html' | 229 | template_name = 'links/view_link.html' |
231 | - success_url = reverse_lazy('course:links:render_link') | ||
232 | - context_object_name = 'link' | ||
233 | 230 | ||
234 | def get_context_data(self,**kwargs): | 231 | def get_context_data(self,**kwargs): |
235 | context = {} | 232 | context = {} |
236 | link = Link.objects.get(slug = self.kwargs.get('slug')) | 233 | link = Link.objects.get(slug = self.kwargs.get('slug')) |
237 | context['link'] = link | 234 | context['link'] = link |
238 | 235 | ||
239 | - self.log_context['link_id'] = link.id | ||
240 | - self.log_context['link_name'] = link.name | ||
241 | - self.log_context['topic_id'] = link.topic.id | ||
242 | - self.log_context['topic_name'] = link.topic.name | ||
243 | - self.log_context['topic_slug'] = link.topic.slug | ||
244 | - self.log_context['subject_id'] = link.topic.subject.id | ||
245 | - self.log_context['subject_name'] = link.topic.subject.name | ||
246 | - self.log_context['subject_slug'] = link.topic.subject.slug | ||
247 | - self.log_context['course_id'] = link.topic.subject.course.id | ||
248 | - self.log_context['course_name'] = link.topic.subject.course.name | ||
249 | - self.log_context['course_slug'] = link.topic.subject.course.slug | ||
250 | - self.log_context['course_category_id'] = link.topic.subject.course.category.id | ||
251 | - self.log_context['course_category_name'] = link.topic.subject.course.category.name | ||
252 | - self.log_context['timestamp_start'] = str(int(time.time())) | ||
253 | - | ||
254 | - super(ViewLink, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 236 | + if (self.request.user.is_authenticated): |
237 | + self.log_context['link_id'] = link.id | ||
238 | + self.log_context['link_name'] = link.name | ||
239 | + self.log_context['topic_id'] = link.topic.id | ||
240 | + self.log_context['topic_name'] = link.topic.name | ||
241 | + self.log_context['topic_slug'] = link.topic.slug | ||
242 | + self.log_context['subject_id'] = link.topic.subject.id | ||
243 | + self.log_context['subject_name'] = link.topic.subject.name | ||
244 | + self.log_context['subject_slug'] = link.topic.subject.slug | ||
245 | + self.log_context['course_id'] = link.topic.subject.course.id | ||
246 | + self.log_context['course_name'] = link.topic.subject.course.name | ||
247 | + self.log_context['course_slug'] = link.topic.subject.course.slug | ||
248 | + self.log_context['course_category_id'] = link.topic.subject.course.category.id | ||
249 | + self.log_context['course_category_name'] = link.topic.subject.course.category.name | ||
250 | + self.log_context['timestamp_start'] = str(int(time.time())) | ||
251 | + | ||
252 | + super(ViewLink, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
255 | 253 | ||
256 | return context | 254 | return context |
257 | 255 |