Commit bc06250eda786f21ec0c7ac9ae8f82a03b0dbbd5
Exists in
master
and in
5 other branches
Merge
Showing
4 changed files
with
45 additions
and
16 deletions
Show diff stats
courses/templates/subject/form_view_teacher.html
@@ -61,8 +61,8 @@ | @@ -61,8 +61,8 @@ | ||
61 | <div class="dropdown"> | 61 | <div class="dropdown"> |
62 | <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a> | 62 | <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a> |
63 | <ul class="dropdown-menu" aria-labelledby="dLabel"> | 63 | <ul class="dropdown-menu" aria-labelledby="dLabel"> |
64 | - <li><a href="javascript:modal.get('{% url 'course:links:create_link' topic.slug %}', '#createLinksModal','#divModalLink') ">{% trans 'Create a Link' %}</a></li> | ||
65 | - <li><a href="javascript:modal.get('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#divModalFile')">{% trans "Create a file" %}</a></li> | 64 | + <li><a href="javascript:get_modal_link('{% url 'course:links:create_link' topic.slug %}', '#createLinksModal','#divModalLink') ">{% trans 'Create a Link' %}</a></li> |
65 | + <li><a href="javascript:get_modal_file('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#divModalFile')">{% trans "Create a file" %}</a></li> | ||
66 | </ul> | 66 | </ul> |
67 | </div> | 67 | </div> |
68 | </div> | 68 | </div> |
files/views.py
@@ -10,13 +10,17 @@ from .forms import FileForm, UpdateFileForm | @@ -10,13 +10,17 @@ from .forms import FileForm, UpdateFileForm | ||
10 | from .models import TopicFile | 10 | from .models import TopicFile |
11 | from .utils import mime_type_to_material_icons | 11 | from .utils import mime_type_to_material_icons |
12 | from courses.models import Topic | 12 | from courses.models import Topic |
13 | + | ||
13 | from core.decorators import log_decorator | 14 | from core.decorators import log_decorator |
14 | from core.models import Log, MimeType | 15 | from core.models import Log, MimeType |
15 | from core.mixins import LogMixin, NotificationMixin | 16 | from core.mixins import LogMixin, NotificationMixin |
17 | + | ||
16 | from django.urls import reverse | 18 | from django.urls import reverse |
17 | from datetime import datetime | 19 | from datetime import datetime |
18 | 20 | ||
21 | + | ||
19 | # Create your views here. | 22 | # Create your views here. |
23 | + | ||
20 | class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.edit.CreateView): | 24 | class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.edit.CreateView): |
21 | log_component = 'file' | 25 | log_component = 'file' |
22 | log_resource = 'file' | 26 | log_resource = 'file' |
@@ -31,6 +35,11 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | @@ -31,6 +35,11 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | ||
31 | form_class = FileForm | 35 | form_class = FileForm |
32 | success_url = reverse_lazy('course:file:render_file') | 36 | success_url = reverse_lazy('course:file:render_file') |
33 | 37 | ||
38 | + log_component = "subject" | ||
39 | + log_resource = "file" | ||
40 | + log_action = "create" | ||
41 | + log_context = {} | ||
42 | + | ||
34 | def form_invalid(self, form, **kwargs): | 43 | def form_invalid(self, form, **kwargs): |
35 | context = super(CreateFile, self).form_invalid(form) | 44 | context = super(CreateFile, self).form_invalid(form) |
36 | context.status_code = 400 | 45 | context.status_code = 400 |
@@ -67,6 +76,18 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | @@ -67,6 +76,18 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | ||
67 | # self.object.file_type = MimeType.objects.get(id = 1) | 76 | # self.object.file_type = MimeType.objects.get(id = 1) |
68 | 77 | ||
69 | self.object.save() | 78 | self.object.save() |
79 | + #CREATE LOG | ||
80 | + self.log_context['topic_id'] = topic.id | ||
81 | + self.log_context['topic_name'] = topic.name | ||
82 | + self.log_context['topic_slug'] = topic.slug | ||
83 | + self.log_context['subject_id'] = topic.subject.id | ||
84 | + self.log_context['subject_name'] = topic.subject.name | ||
85 | + self.log_context['subject_slug'] = topic.subject.slug | ||
86 | + | ||
87 | + super(CreateFile, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
88 | + | ||
89 | + | ||
90 | + | ||
70 | #CREATE NOTIFICATION | 91 | #CREATE NOTIFICATION |
71 | super(CreateFile, self).createNotification(message="uploaded a File "+ self.object.name, actor=self.request.user, | 92 | super(CreateFile, self).createNotification(message="uploaded a File "+ self.object.name, actor=self.request.user, |
72 | resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), | 93 | resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), |
@@ -107,7 +128,8 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | @@ -107,7 +128,8 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | ||
107 | 128 | ||
108 | return self.success_url | 129 | return self.success_url |
109 | 130 | ||
110 | -@log_decorator("file", "viewed", "file") | 131 | + |
132 | +#@log_decorator("topic","acessar","file") | ||
111 | def render_file(request, id): | 133 | def render_file(request, id): |
112 | template_name = 'files/render_file.html' | 134 | template_name = 'files/render_file.html' |
113 | file = get_object_or_404(TopicFile, id = id) | 135 | file = get_object_or_404(TopicFile, id = id) |
requirements.txt
@@ -16,7 +16,6 @@ django-widget-tweaks==1.4.1 | @@ -16,7 +16,6 @@ django-widget-tweaks==1.4.1 | ||
16 | django-wysiwyg==0.8.0 | 16 | django-wysiwyg==0.8.0 |
17 | djangorestframework==3.4.6 | 17 | djangorestframework==3.4.6 |
18 | gunicorn==19.6.0 | 18 | gunicorn==19.6.0 |
19 | -itsdangerous==0.24 | ||
20 | Jinja2==2.8 | 19 | Jinja2==2.8 |
21 | lxml==3.6.4 | 20 | lxml==3.6.4 |
22 | MarkupSafe==0.23 | 21 | MarkupSafe==0.23 |
@@ -24,9 +23,7 @@ Pillow==3.3.1 | @@ -24,9 +23,7 @@ Pillow==3.3.1 | ||
24 | psycopg2==2.6.2 | 23 | psycopg2==2.6.2 |
25 | pycpfcnpj==1.0.2 | 24 | pycpfcnpj==1.0.2 |
26 | requests==2.11.1 | 25 | requests==2.11.1 |
27 | -six==1.10.0 | ||
28 | slugify==0.0.1 | 26 | slugify==0.0.1 |
29 | validators==0.11.0 | 27 | validators==0.11.0 |
30 | -virtualenv==15.0.3 | ||
31 | Werkzeug==0.11.11 | 28 | Werkzeug==0.11.11 |
32 | whitenoise==3.2.2 | 29 | whitenoise==3.2.2 |
users/views.py
@@ -176,6 +176,7 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -176,6 +176,7 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
176 | 176 | ||
177 | def get_context_data(self, **kwargs): | 177 | def get_context_data(self, **kwargs): |
178 | context = super(SearchView, self).get_context_data(**kwargs) | 178 | context = super(SearchView, self).get_context_data(**kwargs) |
179 | + #result_list = [] | ||
179 | search = self.request.GET.get('search', None) | 180 | search = self.request.GET.get('search', None) |
180 | link_list = [] | 181 | link_list = [] |
181 | file_list = [] | 182 | file_list = [] |
@@ -189,11 +190,11 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -189,11 +190,11 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
189 | polls = Poll.objects.all() | 190 | polls = Poll.objects.all() |
190 | exams = Exam.objects.all() | 191 | exams = Exam.objects.all() |
191 | forums = Forum.objects.all() | 192 | forums = Forum.objects.all() |
192 | - link_list = sorted([link for link in links for topic in topics if link.topic == topic]) | ||
193 | - exam_list = sorted([exam for exam in exams for topic in topics if exam.topic == topic]) | ||
194 | - file_list = sorted([arquivo for arquivo in files for topic in topics if arquivo.topic == topic]) | ||
195 | - poll_list = sorted([poll for poll in polls for topic in topics if poll.topic == topic]) | ||
196 | - forum_list = sorted([forum for forum in forums for topic in topics if forum.topic == topic]) | 193 | + link_list = sorted([link for link in links for topic in topics if link.topic == topic],key = lambda x:x.name) |
194 | + exam_list = sorted([exam for exam in exams for topic in topics if exam.topic == topic],key = lambda x:x.name) | ||
195 | + file_list = sorted([arquivo for arquivo in files for topic in topics if arquivo.topic == topic],key = lambda x:x.name) | ||
196 | + poll_list = sorted([poll for poll in polls for topic in topics if poll.topic == topic],key = lambda x:x.name) | ||
197 | + forum_list = sorted([forum for forum in forums for topic in topics if forum.topic == topic],key = lambda x:x.name) | ||
197 | elif has_role(self.request.user,'system_admin'): | 198 | elif has_role(self.request.user,'system_admin'): |
198 | link_list = Link.objects.filter( Q(name__icontains=search)).order_by('name') | 199 | link_list = Link.objects.filter( Q(name__icontains=search)).order_by('name') |
199 | file_list = TopicFile.objects.filter(Q(name__icontains=search)).order_by('name') | 200 | file_list = TopicFile.objects.filter(Q(name__icontains=search)).order_by('name') |
@@ -208,15 +209,23 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -208,15 +209,23 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
208 | forum_list = Forum.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name') | 209 | forum_list = Forum.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name') |
209 | 210 | ||
210 | ''' | 211 | ''' |
211 | - paginator = Paginator(list_links, self.paginate_by) | 212 | + result_list = list(chain(link_list,file_list,poll_list,exam_list,forum_list)) |
213 | + for x in result_list: | ||
214 | + if isinstance(x,Link): | ||
215 | + print(x) | ||
216 | + paginator = Paginator(result_list, self.paginate_by) | ||
217 | + print(paginator.num_pages) | ||
218 | + print(paginator.count) | ||
212 | page = self.request.GET.get('page') | 219 | page = self.request.GET.get('page') |
213 | - | ||
214 | try: | 220 | try: |
215 | - list_links = paginator.page(page) | 221 | + result_list = paginator.page(page) |
222 | + print (result_list) | ||
216 | except PageNotAnInteger: | 223 | except PageNotAnInteger: |
217 | - list_links = paginator.page(1) | 224 | + result_list = paginator.page(1) |
218 | except EmptyPage: | 225 | except EmptyPage: |
219 | - list_links = paginator.page(paginator.num_pages) | 226 | + #print ((paginator.num_pages)) |
227 | + result_list = paginator.page(paginator.num_pages) | ||
228 | + | ||
220 | ''' | 229 | ''' |
221 | 230 | ||
222 | context['link_list'] = link_list | 231 | context['link_list'] = link_list |
@@ -224,5 +233,6 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -224,5 +233,6 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
224 | context['poll_list'] = poll_list | 233 | context['poll_list'] = poll_list |
225 | context['exam_list'] = exam_list | 234 | context['exam_list'] = exam_list |
226 | context['forum_list'] = forum_list | 235 | context['forum_list'] = forum_list |
236 | + #context['result_list'] = result_list | ||
227 | 237 | ||
228 | return context | 238 | return context |