Commit e174643594f2d692638deb55cab08316693b6be8
1 parent
521741fe
Exists in
master
and in
2 other branches
colocando opção de enviar foto junto com o comentario em relatorios
Showing
5 changed files
with
520 additions
and
331 deletions
Show diff stats
webpage/forms.py
@@ -7,91 +7,122 @@ from subjects.models import Tag | @@ -7,91 +7,122 @@ from subjects.models import Tag | ||
7 | 7 | ||
8 | from .models import Webpage | 8 | from .models import Webpage |
9 | 9 | ||
10 | +from resubmit.widgets import ResubmitFileWidget | ||
11 | + | ||
10 | class WebpageForm(forms.ModelForm): | 12 | class WebpageForm(forms.ModelForm): |
11 | - subject = None | ||
12 | - | ||
13 | - def __init__(self, *args, **kwargs): | ||
14 | - super(WebpageForm, self).__init__(*args, **kwargs) | ||
15 | - | ||
16 | - self.subject = kwargs['initial'].get('subject', None) | ||
17 | - | ||
18 | - if self.instance.id: | ||
19 | - self.subject = self.instance.topic.subject | ||
20 | - self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) | ||
21 | - | ||
22 | - self.fields['students'].queryset = self.subject.students.all() | ||
23 | - self.fields['groups'].queryset = self.subject.group_subject.all() | ||
24 | - | ||
25 | - tags = forms.CharField(label = _('Tags'), required = False) | ||
26 | - | ||
27 | - class Meta: | ||
28 | - model = Webpage | ||
29 | - fields = ['name', 'content', 'brief_description', 'all_students', 'students', 'groups', 'show_window', 'visible'] | ||
30 | - labels = { | ||
31 | - 'name': _('Webpage name'), | ||
32 | - 'content': _('Webpage content'), | ||
33 | - } | ||
34 | - widgets = { | ||
35 | - 'content': forms.Textarea, | ||
36 | - 'brief_description': forms.Textarea, | ||
37 | - 'students': forms.SelectMultiple, | ||
38 | - 'groups': forms.SelectMultiple, | ||
39 | - } | ||
40 | - | ||
41 | - def clean_name(self): | ||
42 | - name = self.cleaned_data.get('name', '') | ||
43 | - | ||
44 | - topics = self.subject.topic_subject.all() | ||
45 | - | ||
46 | - for topic in topics: | ||
47 | - if self.instance.id: | ||
48 | - same_name = topic.resource_topic.filter(name__unaccent__iexact = name).exclude(id = self.instance.id).count() | ||
49 | - else: | ||
50 | - same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() | ||
51 | - | ||
52 | - if same_name > 0: | ||
53 | - self._errors['name'] = [_('This subject already has a webpage with this name')] | ||
54 | - | ||
55 | - return ValueError | ||
56 | - | ||
57 | - return name | ||
58 | - | ||
59 | - def clean_content(self): | ||
60 | - content = self.cleaned_data.get('content', '') | ||
61 | - cleaned_content = strip_tags(content) | ||
62 | - | ||
63 | - if cleaned_content == '': | ||
64 | - self._errors['content'] = [_('This field is required.')] | ||
65 | - | ||
66 | - return ValueError | ||
67 | - | ||
68 | - return content | ||
69 | - | ||
70 | - def save(self, commit = True): | ||
71 | - super(WebpageForm, self).save(commit = True) | ||
72 | - | ||
73 | - self.instance.save() | ||
74 | - | ||
75 | - previous_tags = self.instance.tags.all() | ||
76 | - | ||
77 | - tags = self.cleaned_data['tags'].split(",") | 13 | + subject = None |
14 | + | ||
15 | + def __init__(self, *args, **kwargs): | ||
16 | + super(WebpageForm, self).__init__(*args, **kwargs) | ||
17 | + | ||
18 | + self.subject = kwargs['initial'].get('subject', None) | ||
19 | + | ||
20 | + if self.instance.id: | ||
21 | + self.subject = self.instance.topic.subject | ||
22 | + self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) | ||
23 | + | ||
24 | + self.fields['students'].queryset = self.subject.students.all() | ||
25 | + self.fields['groups'].queryset = self.subject.group_subject.all() | ||
26 | + | ||
27 | + tags = forms.CharField(label = _('Tags'), required = False) | ||
28 | + | ||
29 | + class Meta: | ||
30 | + model = Webpage | ||
31 | + fields = ['name', 'content', 'brief_description', 'all_students', 'students', 'groups', 'show_window', 'visible'] | ||
32 | + labels = { | ||
33 | + 'name': _('Webpage name'), | ||
34 | + 'content': _('Webpage content'), | ||
35 | + } | ||
36 | + widgets = { | ||
37 | + 'content': forms.Textarea, | ||
38 | + 'brief_description': forms.Textarea, | ||
39 | + 'students': forms.SelectMultiple, | ||
40 | + 'groups': forms.SelectMultiple, | ||
41 | + } | ||
42 | + | ||
43 | + def clean_name(self): | ||
44 | + name = self.cleaned_data.get('name', '') | ||
45 | + | ||
46 | + topics = self.subject.topic_subject.all() | ||
47 | + | ||
48 | + for topic in topics: | ||
49 | + if self.instance.id: | ||
50 | + same_name = topic.resource_topic.filter(name__unaccent__iexact = name).exclude(id = self.instance.id).count() | ||
51 | + else: | ||
52 | + same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() | ||
53 | + | ||
54 | + if same_name > 0: | ||
55 | + self._errors['name'] = [_('This subject already has a webpage with this name')] | ||
56 | + | ||
57 | + return ValueError | ||
58 | + | ||
59 | + return name | ||
60 | + | ||
61 | + def clean_content(self): | ||
62 | + content = self.cleaned_data.get('content', '') | ||
63 | + cleaned_content = strip_tags(content) | ||
64 | + | ||
65 | + if cleaned_content == '': | ||
66 | + self._errors['content'] = [_('This field is required.')] | ||
67 | + | ||
68 | + return ValueError | ||
69 | + | ||
70 | + return content | ||
71 | + | ||
72 | + def save(self, commit = True): | ||
73 | + super(WebpageForm, self).save(commit = True) | ||
74 | + | ||
75 | + self.instance.save() | ||
76 | + | ||
77 | + previous_tags = self.instance.tags.all() | ||
78 | + | ||
79 | + tags = self.cleaned_data['tags'].split(",") | ||
78 | 80 | ||
79 | #Excluding unwanted tags | 81 | #Excluding unwanted tags |
80 | - for prev in previous_tags: | ||
81 | - if not prev.name in tags: | ||
82 | - self.instance.tags.remove(prev) | 82 | + for prev in previous_tags: |
83 | + if not prev.name in tags: | ||
84 | + self.instance.tags.remove(prev) | ||
83 | 85 | ||
84 | - for tag in tags: | ||
85 | - tag = tag.strip() | 86 | + for tag in tags: |
87 | + tag = tag.strip() | ||
88 | + | ||
89 | + exist = Tag.objects.filter(name = tag).exists() | ||
90 | + | ||
91 | + if exist: | ||
92 | + new_tag = Tag.objects.get(name = tag) | ||
93 | + else: | ||
94 | + new_tag = Tag.objects.create(name = tag) | ||
95 | + | ||
96 | + if not new_tag in self.instance.tags.all(): | ||
97 | + self.instance.tags.add(new_tag) | ||
98 | + | ||
99 | + return self.instance | ||
100 | + | ||
101 | +class FormModalMessage(forms.Form): | ||
102 | + MAX_UPLOAD_SIZE = 5*1024*1024 | ||
103 | + | ||
104 | + comment = forms.CharField(widget=forms.Textarea) | ||
105 | + image = forms.FileField(widget=ResubmitFileWidget(attrs={'accept':'image/*'})) | ||
106 | + | ||
107 | + def clean_comment(self): | ||
108 | + comment = self.cleaned_data.get('comment', '') | ||
109 | + cleaned_comment = strip_tags(comment) | ||
110 | + | ||
111 | + if cleaned_comment == '': | ||
112 | + self._errors['comment'] = [_('This field is required.')] | ||
113 | + | ||
114 | + return ValueError | ||
115 | + | ||
116 | + return comment | ||
86 | 117 | ||
87 | - exist = Tag.objects.filter(name = tag).exists() | 118 | + def clean_image(self): |
119 | + image = self.cleaned_data.get('image', False) | ||
88 | 120 | ||
89 | - if exist: | ||
90 | - new_tag = Tag.objects.get(name = tag) | ||
91 | - else: | ||
92 | - new_tag = Tag.objects.create(name = tag) | 121 | + if image: |
122 | + if hasattr(image, '_size'): | ||
123 | + if image._size > self.MAX_UPLOAD_SIZE: | ||
124 | + self._errors['image'] = [_("The image is too large. It should have less than 5MB.")] | ||
93 | 125 | ||
94 | - if not new_tag in self.instance.tags.all(): | ||
95 | - self.instance.tags.add(new_tag) | 126 | + return ValueError |
96 | 127 | ||
97 | - return self.instance | ||
98 | \ No newline at end of file | 128 | \ No newline at end of file |
129 | + return image | ||
99 | \ No newline at end of file | 130 | \ No newline at end of file |
webpage/templates/webpages/relatorios.html
@@ -9,9 +9,8 @@ | @@ -9,9 +9,8 @@ | ||
9 | <script type="text/javascript"> | 9 | <script type="text/javascript"> |
10 | var tabela_atual = true; | 10 | var tabela_atual = true; |
11 | 11 | ||
12 | - | ||
13 | var array_history = []; | 12 | var array_history = []; |
14 | - {%for data_json in json_history.data%} | 13 | + {%for data_json in json_history.data %} |
15 | array_history.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); | 14 | array_history.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); |
16 | {% endfor%} | 15 | {% endfor%} |
17 | var json_history = {"data":array_history}; | 16 | var json_history = {"data":array_history}; |
@@ -231,44 +230,14 @@ | @@ -231,44 +230,14 @@ | ||
231 | </div> | 230 | </div> |
232 | </div> | 231 | </div> |
233 | </div> | 232 | </div> |
234 | - | ||
235 | - <!-- Modal (remember to change the ids!!!) --> | ||
236 | - <div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | ||
237 | - <div class="modal-dialog" role="document"> | ||
238 | - <div class="modal-content"> | ||
239 | - <!-- Modal Body --> | ||
240 | - <div class="modal-body"> | ||
241 | - <!-- Put ONLY your content here!!! --> | ||
242 | - <h3>{% trans "Message: " %}</h3> | ||
243 | - <form id="text_chat_form" action="" method="GET"> | ||
244 | - <textarea id="message" name="message" rows="5" cols="80"></textarea> | ||
245 | - </form> | ||
246 | - </div> | ||
247 | - <!-- Modal Footer --> | ||
248 | - <div id="delete-category-footer"class="modal-footer"> | ||
249 | - <!-- Don't remove that!!! --> | ||
250 | - <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | ||
251 | - <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a> | ||
252 | - </div> | ||
253 | - </div> | ||
254 | - </div> | ||
255 | - </div> | 233 | + <div id="modal-message"></div> |
256 | <div class="row"> | 234 | <div class="row"> |
257 | <br><br> | 235 | <br><br> |
258 | </div> | 236 | </div> |
259 | </div> | 237 | </div> |
260 | 238 | ||
261 | <script type="text/javascript"> | 239 | <script type="text/javascript"> |
262 | - $('#message').summernote({ | ||
263 | - dialogsInBody: true, | ||
264 | - disableDragAndDrop: true, | ||
265 | - height: 150, | ||
266 | - toolbar: [ | ||
267 | - // [groupName, [list of button]] | ||
268 | - ['style', ['bold', 'italic']], | ||
269 | - ['insert', ['link']] | ||
270 | - ] | ||
271 | - }); | 240 | + |
272 | $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | 241 | $("#title-table").text(search.length + " {% trans 'record(s)' %}"); |
273 | function putpagination(data = json_history["data"], load_histoty = true){ | 242 | function putpagination(data = json_history["data"], load_histoty = true){ |
274 | var len = Math.ceil(data.length / 20); | 243 | var len = Math.ceil(data.length / 20); |
@@ -385,6 +354,15 @@ | @@ -385,6 +354,15 @@ | ||
385 | $(".active").removeClass("active"); | 354 | $(".active").removeClass("active"); |
386 | $("#" + pag).addClass("active"); | 355 | $("#" + pag).addClass("active"); |
387 | } | 356 | } |
357 | + | ||
358 | + function openmodal(){ | ||
359 | + $( "#modal-message" ).empty(); | ||
360 | + $.get( "{% url 'webpages:send_message' webpage.slug %}", function( data ) { | ||
361 | + $( "#modal-message" ).append( data ); | ||
362 | + $("#send-message-modal").modal("show"); | ||
363 | + }); | ||
364 | + } | ||
365 | + | ||
388 | function sendMessage(){ | 366 | function sendMessage(){ |
389 | $("#send-message-modal").modal("hide"); | 367 | $("#send-message-modal").modal("hide"); |
390 | var checked = $("#google-chart-checkbox").serializeArray(); | 368 | var checked = $("#google-chart-checkbox").serializeArray(); |
@@ -392,19 +370,40 @@ | @@ -392,19 +370,40 @@ | ||
392 | for (var i in checked){ | 370 | for (var i in checked){ |
393 | email.push(checkbox[checked[i]["name"]]); | 371 | email.push(checkbox[checked[i]["name"]]); |
394 | } | 372 | } |
395 | - var message = $("#text_chat_form").serializeArray()[0]["value"]; | 373 | + $('<input />').attr('type', 'hidden') |
374 | + .attr('name', "users[]") | ||
375 | + .attr('value', email) | ||
376 | + .appendTo('#text_chat_form'); | ||
377 | + | ||
378 | + var formData = new FormData($('#text_chat_form').get(0)); | ||
379 | + console.log("formData"); | ||
380 | + console.log(formData); | ||
396 | $.ajax({ | 381 | $.ajax({ |
397 | - type: "GET", | ||
398 | - data: {"message":message,"users[]":email}, | ||
399 | - url: "{% url 'webpages:send_message' subject.slug %}", | ||
400 | - success: function(msg){ | ||
401 | - console.log(msg); | ||
402 | - $('#message').summernote("reset"); | ||
403 | - } | ||
404 | - }); | ||
405 | - } | ||
406 | - function openmodal(){ | ||
407 | - $("#send-message-modal").modal("show"); | 382 | + url: "{% url 'webpages:send_message' webpage.slug %}", |
383 | + type: "POST", | ||
384 | + data: formData, | ||
385 | + cache: false, | ||
386 | + processData: false, | ||
387 | + contentType: false, | ||
388 | + success: function(data) { | ||
389 | + if (data["message"]){ | ||
390 | + console.log("success"); | ||
391 | + $("body").removeClass("modal-open"); | ||
392 | + $( "#modal-message" ).empty(); | ||
393 | + $(".modal-backdrop.fade.in").remove(); | ||
394 | + } else { | ||
395 | + console.log("teste"); | ||
396 | + $( "#modal-message" ).empty(); | ||
397 | + $(".modal-backdrop.fade.in").remove(); | ||
398 | + $( "#modal-message" ).append( data ); | ||
399 | + $("#send-message-modal").modal("show"); | ||
400 | + } | ||
401 | + }, | ||
402 | + error: function(data){ | ||
403 | + console.log("erro"); | ||
404 | + console.log(data); | ||
405 | + } | ||
406 | + }); | ||
408 | } | 407 | } |
409 | </script> | 408 | </script> |
410 | {% endblock %} | 409 | {% endblock %} |
@@ -0,0 +1,112 @@ | @@ -0,0 +1,112 @@ | ||
1 | + | ||
2 | + {% load widget_tweaks i18n %} | ||
3 | + <!-- Modal (remember to change the ids!!!) --> | ||
4 | +<div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | ||
5 | + <div class="modal-dialog" role="document"> | ||
6 | + <div class="modal-content"> | ||
7 | + <!-- Modal Body --> | ||
8 | + <div class="modal-body"> | ||
9 | + <form id="text_chat_form" action="" method="POST" enctype="multipart/form-data"> | ||
10 | + {% csrf_token %} | ||
11 | + {% comment %}Area para o Texto{% endcomment %} | ||
12 | + <div class="form-group{% if form.has_error %} has-error {% endif %}"> | ||
13 | + <label for="{{ form.comment.auto_id }}">{{ form.comment.label }}: <span>*</span></label> | ||
14 | + {% render_field form.comment class='form-control text_simple_wysiwyg' %} | ||
15 | + | ||
16 | + <span id="helpBlock" class="help-block">{{ form.comment.help_text }}</span> | ||
17 | + | ||
18 | + {% if form.comment.errors %} | ||
19 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
20 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
21 | + <span aria-hidden="true">×</span> | ||
22 | + </button> | ||
23 | + <ul> | ||
24 | + {% for error in form.comment.errors %} | ||
25 | + <li>{{ error }}</li> | ||
26 | + {% endfor %} | ||
27 | + </ul> | ||
28 | + </div> | ||
29 | + {% endif %} | ||
30 | + </div> | ||
31 | + {% comment %}Area para anexar a imagem {% endcomment %} | ||
32 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
33 | + {% render_field form.image %} | ||
34 | + | ||
35 | + <div class="filedrag"> | ||
36 | + {% trans 'Click or drop the picture here' %}<br /> | ||
37 | + | ||
38 | + <small>{% trans 'The picture could not exceed 5MB.' %}</small> | ||
39 | + </div> | ||
40 | + | ||
41 | + {% if form.image.errors %} | ||
42 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
43 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
44 | + <span aria-hidden="true">×</span> | ||
45 | + </button> | ||
46 | + <ul> | ||
47 | + {% for error in form.image.errors %} | ||
48 | + <li>{{ error }}</li> | ||
49 | + {% endfor %} | ||
50 | + </ul> | ||
51 | + </div> | ||
52 | + {% endif %} | ||
53 | + | ||
54 | + </div> | ||
55 | + </form> | ||
56 | + </div> | ||
57 | + <!-- Modal Footer --> | ||
58 | + <div id="delete-category-footer"class="modal-footer"> | ||
59 | + <!-- Don't remove that!!! --> | ||
60 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | ||
61 | + <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a> | ||
62 | + </div> | ||
63 | + </div> | ||
64 | + </div> | ||
65 | +</div> | ||
66 | + | ||
67 | +<script type="text/javascript"> | ||
68 | + | ||
69 | + $('.text_simple_wysiwyg').summernote({ | ||
70 | + dialogsInBody: true, | ||
71 | + disableDragAndDrop: true, | ||
72 | + height: 150, | ||
73 | + toolbar: [ | ||
74 | + // [groupName, [list of button]] | ||
75 | + ['style', ['bold', 'italic']], | ||
76 | + ['insert', ['link']] | ||
77 | + ] | ||
78 | + }); | ||
79 | + | ||
80 | + if (window.File && window.FileList && window.FileReader) { | ||
81 | + Init(); | ||
82 | + } | ||
83 | + | ||
84 | + function Init() { | ||
85 | + var small = $("#id_image"), | ||
86 | + filedrag = $(".filedrag"), | ||
87 | + common = $(".common-file-input"); | ||
88 | + | ||
89 | + // file select | ||
90 | + small.on("change", FileSelectHandler); | ||
91 | + | ||
92 | + // is XHR2 available? | ||
93 | + var xhr = new XMLHttpRequest(); | ||
94 | + if (xhr.upload) { | ||
95 | + // file drop | ||
96 | + filedrag.on("drop", FileSelectHandler); | ||
97 | + filedrag.attr('style', 'display:block'); | ||
98 | + common.attr('style', 'display:none'); | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + // file selection | ||
103 | + function FileSelectHandler(e) { | ||
104 | + var files = e.target.files || e.dataTransfer.files, | ||
105 | + parent = $(e.target.offsetParent); | ||
106 | + | ||
107 | + // process all File objects | ||
108 | + for (var i = 0, f; f = files[i]; i++) { | ||
109 | + parent.find('.filedrag').html(f.name); | ||
110 | + } | ||
111 | + } | ||
112 | +</script> | ||
0 | \ No newline at end of file | 113 | \ No newline at end of file |
webpage/urls.py
@@ -10,5 +10,5 @@ urlpatterns = [ | @@ -10,5 +10,5 @@ urlpatterns = [ | ||
10 | url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), | 10 | url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), |
11 | url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), | 11 | url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), |
12 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | 12 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), |
13 | - url(r'^send-message/(?P<slug>[\w_-]+)/$', views.sendMessage, name = 'send_message'), | 13 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), |
14 | ] | 14 | ] |
webpage/views.py
@@ -20,100 +20,107 @@ from pendencies.forms import PendenciesForm | @@ -20,100 +20,107 @@ from pendencies.forms import PendenciesForm | ||
20 | from .forms import WebpageForm | 20 | from .forms import WebpageForm |
21 | from .models import Webpage | 21 | from .models import Webpage |
22 | 22 | ||
23 | +from chat.models import Conversation, TalkMessages | ||
24 | +from users.models import User | ||
25 | +from subjects.models import Subject | ||
26 | + | ||
27 | +from .forms import FormModalMessage | ||
28 | + | ||
23 | class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): | 29 | class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): |
24 | - log_component = 'resources' | ||
25 | - log_action = 'view' | ||
26 | - log_resource = 'webpage' | ||
27 | - log_context = {} | 30 | + log_component = 'resources' |
31 | + log_action = 'view' | ||
32 | + log_resource = 'webpage' | ||
33 | + log_context = {} | ||
28 | 34 | ||
29 | - login_url = reverse_lazy("users:login") | ||
30 | - redirect_field_name = 'next' | 35 | + login_url = reverse_lazy("users:login") |
36 | + redirect_field_name = 'next' | ||
31 | 37 | ||
32 | - template_name = 'webpages/window_view.html' | ||
33 | - model = Webpage | ||
34 | - context_object_name = 'webpage' | 38 | + template_name = 'webpages/window_view.html' |
39 | + model = Webpage | ||
40 | + context_object_name = 'webpage' | ||
35 | 41 | ||
36 | - def dispatch(self, request, *args, **kwargs): | ||
37 | - slug = self.kwargs.get('slug', '') | ||
38 | - webpage = get_object_or_404(Webpage, slug = slug) | 42 | + def dispatch(self, request, *args, **kwargs): |
43 | + slug = self.kwargs.get('slug', '') | ||
44 | + webpage = get_object_or_404(Webpage, slug=slug) | ||
39 | 45 | ||
40 | - if not has_resource_permissions(request.user, webpage): | ||
41 | - return redirect(reverse_lazy('subjects:home')) | 46 | + if not has_resource_permissions(request.user, webpage): |
47 | + return redirect(reverse_lazy('subjects:home')) | ||
42 | 48 | ||
43 | - return super(NewWindowView, self).dispatch(request, *args, **kwargs) | 49 | + return super(NewWindowView, self).dispatch(request, *args, **kwargs) |
44 | 50 | ||
45 | - def get_context_data(self, **kwargs): | ||
46 | - context = super(NewWindowView, self).get_context_data(**kwargs) | 51 | + def get_context_data(self, **kwargs): |
52 | + context = super(NewWindowView, self).get_context_data(**kwargs) | ||
47 | 53 | ||
48 | - self.log_context['category_id'] = self.object.topic.subject.category.id | ||
49 | - self.log_context['category_name'] = self.object.topic.subject.category.name | ||
50 | - self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
51 | - self.log_context['subject_id'] = self.object.topic.subject.id | ||
52 | - self.log_context['subject_name'] = self.object.topic.subject.name | ||
53 | - self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
54 | - self.log_context['topic_id'] = self.object.topic.id | ||
55 | - self.log_context['topic_name'] = self.object.topic.name | ||
56 | - self.log_context['topic_slug'] = self.object.topic.slug | ||
57 | - self.log_context['webpage_id'] = self.object.id | ||
58 | - self.log_context['webpage_name'] = self.object.name | ||
59 | - self.log_context['webpage_slug'] = self.object.slug | ||
60 | - self.log_context['timestamp_start'] = str(int(time.time())) | 54 | + self.log_context['category_id'] = self.object.topic.subject.category.id |
55 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
56 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
57 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
58 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
59 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
60 | + self.log_context['topic_id'] = self.object.topic.id | ||
61 | + self.log_context['topic_name'] = self.object.topic.name | ||
62 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
63 | + self.log_context['webpage_id'] = self.object.id | ||
64 | + self.log_context['webpage_name'] = self.object.name | ||
65 | + self.log_context['webpage_slug'] = self.object.slug | ||
66 | + self.log_context['timestamp_start'] = str(int(time.time())) | ||
61 | 67 | ||
62 | - super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 68 | + super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, |
69 | + self.log_resource, self.log_context) | ||
63 | 70 | ||
64 | - self.request.session['log_id'] = Log.objects.latest('id').id | 71 | + self.request.session['log_id'] = Log.objects.latest('id').id |
65 | 72 | ||
66 | - return context | 73 | + return context |
67 | 74 | ||
68 | class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): | 75 | class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): |
69 | - log_component = 'resources' | ||
70 | - log_action = 'view' | ||
71 | - log_resource = 'webpage' | ||
72 | - log_context = {} | 76 | + log_component = 'resources' |
77 | + log_action = 'view' | ||
78 | + log_resource = 'webpage' | ||
79 | + log_context = {} | ||
73 | 80 | ||
74 | - login_url = reverse_lazy("users:login") | ||
75 | - redirect_field_name = 'next' | 81 | + login_url = reverse_lazy("users:login") |
82 | + redirect_field_name = 'next' | ||
76 | 83 | ||
77 | - template_name = 'webpages/view.html' | ||
78 | - model = Webpage | ||
79 | - context_object_name = 'webpage' | 84 | + template_name = 'webpages/view.html' |
85 | + model = Webpage | ||
86 | + context_object_name = 'webpage' | ||
80 | 87 | ||
81 | - def dispatch(self, request, *args, **kwargs): | ||
82 | - slug = self.kwargs.get('slug', '') | ||
83 | - webpage = get_object_or_404(Webpage, slug = slug) | 88 | + def dispatch(self, request, *args, **kwargs): |
89 | + slug = self.kwargs.get('slug', '') | ||
90 | + webpage = get_object_or_404(Webpage, slug=slug) | ||
84 | 91 | ||
85 | - if not has_resource_permissions(request.user, webpage): | ||
86 | - return redirect(reverse_lazy('subjects:home')) | 92 | + if not has_resource_permissions(request.user, webpage): |
93 | + return redirect(reverse_lazy('subjects:home')) | ||
87 | 94 | ||
88 | - return super(InsideView, self).dispatch(request, *args, **kwargs) | 95 | + return super(InsideView, self).dispatch(request, *args, **kwargs) |
89 | 96 | ||
90 | - def get_context_data(self, **kwargs): | ||
91 | - context = super(InsideView, self).get_context_data(**kwargs) | 97 | + def get_context_data(self, **kwargs): |
98 | + context = super(InsideView, self).get_context_data(**kwargs) | ||
92 | 99 | ||
93 | - context['title'] = self.object.name | 100 | + context['title'] = self.object.name |
94 | 101 | ||
95 | - context['topic'] = self.object.topic | ||
96 | - context['subject'] = self.object.topic.subject | 102 | + context['topic'] = self.object.topic |
103 | + context['subject'] = self.object.topic.subject | ||
97 | 104 | ||
98 | - self.log_context['category_id'] = self.object.topic.subject.category.id | ||
99 | - self.log_context['category_name'] = self.object.topic.subject.category.name | ||
100 | - self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
101 | - self.log_context['subject_id'] = self.object.topic.subject.id | ||
102 | - self.log_context['subject_name'] = self.object.topic.subject.name | ||
103 | - self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
104 | - self.log_context['topic_id'] = self.object.topic.id | ||
105 | - self.log_context['topic_name'] = self.object.topic.name | ||
106 | - self.log_context['topic_slug'] = self.object.topic.slug | ||
107 | - self.log_context['webpage_id'] = self.object.id | ||
108 | - self.log_context['webpage_name'] = self.object.name | ||
109 | - self.log_context['webpage_slug'] = self.object.slug | ||
110 | - self.log_context['timestamp_start'] = str(int(time.time())) | 105 | + self.log_context['category_id'] = self.object.topic.subject.category.id |
106 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
107 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
108 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
109 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
110 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
111 | + self.log_context['topic_id'] = self.object.topic.id | ||
112 | + self.log_context['topic_name'] = self.object.topic.name | ||
113 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
114 | + self.log_context['webpage_id'] = self.object.id | ||
115 | + self.log_context['webpage_name'] = self.object.name | ||
116 | + self.log_context['webpage_slug'] = self.object.slug | ||
117 | + self.log_context['timestamp_start'] = str(int(time.time())) | ||
111 | 118 | ||
112 | - super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 119 | + super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
113 | 120 | ||
114 | - self.request.session['log_id'] = Log.objects.latest('id').id | 121 | + self.request.session['log_id'] = Log.objects.latest('id').id |
115 | 122 | ||
116 | - return context | 123 | + return context |
117 | 124 | ||
118 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | 125 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
119 | log_component = 'resources' | 126 | log_component = 'resources' |
@@ -128,55 +135,55 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -128,55 +135,55 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
128 | form_class = WebpageForm | 135 | form_class = WebpageForm |
129 | 136 | ||
130 | def dispatch(self, request, *args, **kwargs): | 137 | def dispatch(self, request, *args, **kwargs): |
131 | - slug = self.kwargs.get('slug', '') | ||
132 | - topic = get_object_or_404(Topic, slug = slug) | ||
133 | - | ||
134 | - if not has_subject_permissions(request.user, topic.subject): | ||
135 | - return redirect(reverse_lazy('subjects:home')) | 138 | + slug = self.kwargs.get('slug', '') |
139 | + topic = get_object_or_404(Topic, slug = slug) | ||
140 | + | ||
141 | + if not has_subject_permissions(request.user, topic.subject): | ||
142 | + return redirect(reverse_lazy('subjects:home')) | ||
136 | 143 | ||
137 | - return super(CreateView, self).dispatch(request, *args, **kwargs) | 144 | + return super(CreateView, self).dispatch(request, *args, **kwargs) |
138 | 145 | ||
139 | def get(self, request, *args, **kwargs): | 146 | def get(self, request, *args, **kwargs): |
140 | - self.object = None | 147 | + self.object = None |
141 | 148 | ||
142 | - form_class = self.get_form_class() | ||
143 | - form = self.get_form(form_class) | 149 | + form_class = self.get_form_class() |
150 | + form = self.get_form(form_class) | ||
144 | 151 | ||
145 | - slug = self.kwargs.get('slug', '') | ||
146 | - topic = get_object_or_404(Topic, slug = slug) | 152 | + slug = self.kwargs.get('slug', '') |
153 | + topic = get_object_or_404(Topic, slug = slug) | ||
147 | 154 | ||
148 | - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | 155 | + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
149 | 156 | ||
150 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | 157 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
151 | 158 | ||
152 | def post(self, request, *args, **kwargs): | 159 | def post(self, request, *args, **kwargs): |
153 | - self.object = None | 160 | + self.object = None |
154 | 161 | ||
155 | - form_class = self.get_form_class() | ||
156 | - form = self.get_form(form_class) | 162 | + form_class = self.get_form_class() |
163 | + form = self.get_form(form_class) | ||
157 | 164 | ||
158 | - slug = self.kwargs.get('slug', '') | ||
159 | - topic = get_object_or_404(Topic, slug = slug) | 165 | + slug = self.kwargs.get('slug', '') |
166 | + topic = get_object_or_404(Topic, slug = slug) | ||
160 | 167 | ||
161 | - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | 168 | + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) |
162 | 169 | ||
163 | - if (form.is_valid() and pendencies_form.is_valid()): | ||
164 | - return self.form_valid(form, pendencies_form) | ||
165 | - else: | ||
166 | - return self.form_invalid(form, pendencies_form) | 170 | + if (form.is_valid() and pendencies_form.is_valid()): |
171 | + return self.form_valid(form, pendencies_form) | ||
172 | + else: | ||
173 | + return self.form_invalid(form, pendencies_form) | ||
167 | 174 | ||
168 | def get_initial(self): | 175 | def get_initial(self): |
169 | - initial = super(CreateView, self).get_initial() | 176 | + initial = super(CreateView, self).get_initial() |
170 | 177 | ||
171 | - slug = self.kwargs.get('slug', '') | 178 | + slug = self.kwargs.get('slug', '') |
172 | 179 | ||
173 | - topic = get_object_or_404(Topic, slug = slug) | ||
174 | - initial['subject'] = topic.subject | 180 | + topic = get_object_or_404(Topic, slug = slug) |
181 | + initial['subject'] = topic.subject | ||
175 | 182 | ||
176 | - return initial | 183 | + return initial |
177 | 184 | ||
178 | def form_invalid(self, form, pendencies_form): | 185 | def form_invalid(self, form, pendencies_form): |
179 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | 186 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
180 | 187 | ||
181 | def form_valid(self, form, pendencies_form): | 188 | def form_valid(self, form, pendencies_form): |
182 | self.object = form.save(commit = False) | 189 | self.object = form.save(commit = False) |
@@ -187,18 +194,18 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -187,18 +194,18 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
187 | self.object.order = topic.resource_topic.count() + 1 | 194 | self.object.order = topic.resource_topic.count() + 1 |
188 | 195 | ||
189 | if not self.object.topic.visible and not self.object.topic.repository: | 196 | if not self.object.topic.visible and not self.object.topic.repository: |
190 | - self.object.visible = False | 197 | + self.object.visible = False |
191 | 198 | ||
192 | 199 | ||
193 | - if form.cleaned_data["all_students"]: | ||
194 | - self.object.students.add(*self.object.topic.subject.students.all()) | 200 | + # if form.cleaned_data["all_students"]: |
201 | + # self.object.students.add(*self.object.topic.subject.students.all()) | ||
195 | self.object.save() | 202 | self.object.save() |
196 | 203 | ||
197 | pend_form = pendencies_form.save(commit = False) | 204 | pend_form = pendencies_form.save(commit = False) |
198 | pend_form.resource = self.object | 205 | pend_form.resource = self.object |
199 | 206 | ||
200 | if not pend_form.action == "": | 207 | if not pend_form.action == "": |
201 | - pend_form.save() | 208 | + pend_form.save() |
202 | 209 | ||
203 | self.log_context['category_id'] = self.object.topic.subject.category.id | 210 | self.log_context['category_id'] = self.object.topic.subject.category.id |
204 | self.log_context['category_name'] = self.object.topic.subject.category.name | 211 | self.log_context['category_name'] = self.object.topic.subject.category.name |
@@ -218,153 +225,153 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -218,153 +225,153 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
218 | return redirect(self.get_success_url()) | 225 | return redirect(self.get_success_url()) |
219 | 226 | ||
220 | def get_context_data(self, **kwargs): | 227 | def get_context_data(self, **kwargs): |
221 | - context = super(CreateView, self).get_context_data(**kwargs) | 228 | + context = super(CreateView, self).get_context_data(**kwargs) |
222 | 229 | ||
223 | - context['title'] = _('Create Webpage') | 230 | + context['title'] = _('Create Webpage') |
224 | 231 | ||
225 | - slug = self.kwargs.get('slug', '') | ||
226 | - topic = get_object_or_404(Topic, slug = slug) | 232 | + slug = self.kwargs.get('slug', '') |
233 | + topic = get_object_or_404(Topic, slug = slug) | ||
227 | 234 | ||
228 | - context['topic'] = topic | ||
229 | - context['subject'] = topic.subject | 235 | + context['topic'] = topic |
236 | + context['subject'] = topic.subject | ||
230 | 237 | ||
231 | - return context | 238 | + return context |
232 | 239 | ||
233 | def get_success_url(self): | 240 | def get_success_url(self): |
234 | - messages.success(self.request, _('The Webpage "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) | 241 | + messages.success(self.request, _('The Webpage "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) |
235 | 242 | ||
236 | - success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) | 243 | + success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) |
237 | 244 | ||
238 | - if self.object.show_window: | ||
239 | - self.request.session['resources'] = {} | ||
240 | - self.request.session['resources']['new_page'] = True | ||
241 | - self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) | 245 | + if self.object.show_window: |
246 | + self.request.session['resources'] = {} | ||
247 | + self.request.session['resources']['new_page'] = True | ||
248 | + self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) | ||
242 | 249 | ||
243 | - success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | 250 | + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
244 | 251 | ||
245 | - return success_url | 252 | + return success_url |
246 | 253 | ||
247 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | 254 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
248 | - log_component = 'resources' | ||
249 | - log_action = 'update' | ||
250 | - log_resource = 'webpage' | ||
251 | - log_context = {} | 255 | + log_component = 'resources' |
256 | + log_action = 'update' | ||
257 | + log_resource = 'webpage' | ||
258 | + log_context = {} | ||
252 | 259 | ||
253 | - login_url = reverse_lazy("users:login") | ||
254 | - redirect_field_name = 'next' | 260 | + login_url = reverse_lazy("users:login") |
261 | + redirect_field_name = 'next' | ||
255 | 262 | ||
256 | - template_name = 'webpages/update.html' | ||
257 | - model = Webpage | ||
258 | - form_class = WebpageForm | 263 | + template_name = 'webpages/update.html' |
264 | + model = Webpage | ||
265 | + form_class = WebpageForm | ||
259 | 266 | ||
260 | - def dispatch(self, request, *args, **kwargs): | ||
261 | - slug = self.kwargs.get('topic_slug', '') | ||
262 | - topic = get_object_or_404(Topic, slug = slug) | 267 | + def dispatch(self, request, *args, **kwargs): |
268 | + slug = self.kwargs.get('topic_slug', '') | ||
269 | + topic = get_object_or_404(Topic, slug = slug) | ||
263 | 270 | ||
264 | - if not has_subject_permissions(request.user, topic.subject): | ||
265 | - return redirect(reverse_lazy('subjects:home')) | 271 | + if not has_subject_permissions(request.user, topic.subject): |
272 | + return redirect(reverse_lazy('subjects:home')) | ||
266 | 273 | ||
267 | - return super(UpdateView, self).dispatch(request, *args, **kwargs) | 274 | + return super(UpdateView, self).dispatch(request, *args, **kwargs) |
268 | 275 | ||
269 | - def get(self, request, *args, **kwargs): | ||
270 | - self.object = self.get_object() | 276 | + def get(self, request, *args, **kwargs): |
277 | + self.object = self.get_object() | ||
271 | 278 | ||
272 | - form_class = self.get_form_class() | ||
273 | - form = self.get_form(form_class) | 279 | + form_class = self.get_form_class() |
280 | + form = self.get_form(form_class) | ||
274 | 281 | ||
275 | - slug = self.kwargs.get('topic_slug', '') | ||
276 | - topic = get_object_or_404(Topic, slug = slug) | 282 | + slug = self.kwargs.get('topic_slug', '') |
283 | + topic = get_object_or_404(Topic, slug = slug) | ||
277 | 284 | ||
278 | - pend_form = self.object.pendencies_resource.all() | 285 | + pend_form = self.object.pendencies_resource.all() |
279 | 286 | ||
280 | - if len(pend_form) > 0: | ||
281 | - pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
282 | - else: | ||
283 | - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | 287 | + if len(pend_form) > 0: |
288 | + pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
289 | + else: | ||
290 | + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
284 | 291 | ||
285 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | 292 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
286 | 293 | ||
287 | - def post(self, request, *args, **kwargs): | ||
288 | - self.object = self.get_object() | 294 | + def post(self, request, *args, **kwargs): |
295 | + self.object = self.get_object() | ||
289 | 296 | ||
290 | - form_class = self.get_form_class() | ||
291 | - form = self.get_form(form_class) | 297 | + form_class = self.get_form_class() |
298 | + form = self.get_form(form_class) | ||
292 | 299 | ||
293 | - slug = self.kwargs.get('topic_slug', '') | ||
294 | - topic = get_object_or_404(Topic, slug = slug) | 300 | + slug = self.kwargs.get('topic_slug', '') |
301 | + topic = get_object_or_404(Topic, slug = slug) | ||
295 | 302 | ||
296 | - pend_form = self.object.pendencies_resource.all() | 303 | + pend_form = self.object.pendencies_resource.all() |
297 | 304 | ||
298 | - if len(pend_form) > 0: | ||
299 | - pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
300 | - else: | ||
301 | - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | 305 | + if len(pend_form) > 0: |
306 | + pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
307 | + else: | ||
308 | + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
302 | 309 | ||
303 | - if (form.is_valid() and pendencies_form.is_valid()): | ||
304 | - return self.form_valid(form, pendencies_form) | ||
305 | - else: | ||
306 | - return self.form_invalid(form, pendencies_form) | 310 | + if (form.is_valid() and pendencies_form.is_valid()): |
311 | + return self.form_valid(form, pendencies_form) | ||
312 | + else: | ||
313 | + return self.form_invalid(form, pendencies_form) | ||
307 | 314 | ||
308 | - def form_invalid(self, form, pendencies_form): | ||
309 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | 315 | + def form_invalid(self, form, pendencies_form): |
316 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | ||
310 | 317 | ||
311 | - def form_valid(self, form, pendencies_form): | ||
312 | - self.object = form.save(commit = False) | 318 | + def form_valid(self, form, pendencies_form): |
319 | + self.object = form.save(commit = False) | ||
313 | 320 | ||
314 | - if not self.object.topic.visible and not self.object.topic.repository: | ||
315 | - self.object.visible = False | 321 | + if not self.object.topic.visible and not self.object.topic.repository: |
322 | + self.object.visible = False | ||
316 | 323 | ||
317 | - self.object.save() | 324 | + self.object.save() |
318 | 325 | ||
319 | - pend_form = pendencies_form.save(commit = False) | ||
320 | - pend_form.resource = self.object | 326 | + pend_form = pendencies_form.save(commit = False) |
327 | + pend_form.resource = self.object | ||
321 | 328 | ||
322 | - if not pend_form.action == "": | ||
323 | - pend_form.save() | 329 | + if not pend_form.action == "": |
330 | + pend_form.save() | ||
324 | 331 | ||
325 | - self.log_context['category_id'] = self.object.topic.subject.category.id | ||
326 | - self.log_context['category_name'] = self.object.topic.subject.category.name | ||
327 | - self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
328 | - self.log_context['subject_id'] = self.object.topic.subject.id | ||
329 | - self.log_context['subject_name'] = self.object.topic.subject.name | ||
330 | - self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
331 | - self.log_context['topic_id'] = self.object.topic.id | ||
332 | - self.log_context['topic_name'] = self.object.topic.name | ||
333 | - self.log_context['topic_slug'] = self.object.topic.slug | ||
334 | - self.log_context['webpage_id'] = self.object.id | ||
335 | - self.log_context['webpage_name'] = self.object.name | ||
336 | - self.log_context['webpage_slug'] = self.object.slug | 332 | + self.log_context['category_id'] = self.object.topic.subject.category.id |
333 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
334 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
335 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
336 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
337 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
338 | + self.log_context['topic_id'] = self.object.topic.id | ||
339 | + self.log_context['topic_name'] = self.object.topic.name | ||
340 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
341 | + self.log_context['webpage_id'] = self.object.id | ||
342 | + self.log_context['webpage_name'] = self.object.name | ||
343 | + self.log_context['webpage_slug'] = self.object.slug | ||
337 | 344 | ||
338 | - super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 345 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
339 | 346 | ||
340 | - return redirect(self.get_success_url()) | 347 | + return redirect(self.get_success_url()) |
341 | 348 | ||
342 | - def get_context_data(self, **kwargs): | ||
343 | - context = super(UpdateView, self).get_context_data(**kwargs) | 349 | + def get_context_data(self, **kwargs): |
350 | + context = super(UpdateView, self).get_context_data(**kwargs) | ||
344 | 351 | ||
345 | - context['title'] = _('Update Webpage') | 352 | + context['title'] = _('Update Webpage') |
346 | 353 | ||
347 | - slug = self.kwargs.get('topic_slug', '') | ||
348 | - topic = get_object_or_404(Topic, slug = slug) | 354 | + slug = self.kwargs.get('topic_slug', '') |
355 | + topic = get_object_or_404(Topic, slug = slug) | ||
349 | 356 | ||
350 | - context['topic'] = topic | ||
351 | - context['subject'] = topic.subject | 357 | + context['topic'] = topic |
358 | + context['subject'] = topic.subject | ||
352 | 359 | ||
353 | - return context | 360 | + return context |
354 | 361 | ||
355 | - def get_success_url(self): | ||
356 | - messages.success(self.request, _('The Webpage "%s" was updated successfully!')%(self.object.name)) | 362 | + def get_success_url(self): |
363 | + messages.success(self.request, _('The Webpage "%s" was updated successfully!')%(self.object.name)) | ||
357 | 364 | ||
358 | - success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) | 365 | + success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) |
359 | 366 | ||
360 | - if self.object.show_window: | ||
361 | - self.request.session['resources'] = {} | ||
362 | - self.request.session['resources']['new_page'] = True | ||
363 | - self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) | 367 | + if self.object.show_window: |
368 | + self.request.session['resources'] = {} | ||
369 | + self.request.session['resources']['new_page'] = True | ||
370 | + self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) | ||
364 | 371 | ||
365 | - success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | 372 | + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
366 | 373 | ||
367 | - return success_url | 374 | + return success_url |
368 | 375 | ||
369 | class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): | 376 | class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): |
370 | log_component = 'resources' | 377 | log_component = 'resources' |
@@ -474,6 +481,8 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -474,6 +481,8 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
474 | context["init_date"] = start_date | 481 | context["init_date"] = start_date |
475 | context["end_date"] = end_date | 482 | context["end_date"] = end_date |
476 | alunos = webpage.students.all() | 483 | alunos = webpage.students.all() |
484 | + if webpage.all_students : | ||
485 | + alunos = webpage.topic.subject.students.all() | ||
477 | 486 | ||
478 | vis_ou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) | 487 | vis_ou = Log.objects.filter(context__contains={'webpage_id':webpage.id},resource="webpage",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) |
479 | did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | 488 | did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) |
@@ -516,9 +525,47 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -516,9 +525,47 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
516 | return context | 525 | return context |
517 | 526 | ||
518 | 527 | ||
519 | -from chat.models import Conversation, TalkMessages | ||
520 | -from users.models import User | ||
521 | -from subjects.models import Subject | 528 | + |
529 | +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | ||
530 | + log_component = 'resources' | ||
531 | + log_action = 'send' | ||
532 | + log_resource = 'webpage' | ||
533 | + log_context = {} | ||
534 | + | ||
535 | + login_url = reverse_lazy("users:login") | ||
536 | + redirect_field_name = 'next' | ||
537 | + | ||
538 | + template_name = 'webpages/send_message.html' | ||
539 | + form_class = FormModalMessage | ||
540 | + | ||
541 | + def dispatch(self, request, *args, **kwargs): | ||
542 | + slug = self.kwargs.get('slug', '') | ||
543 | + webpage = get_object_or_404(Webpage, slug = slug) | ||
544 | + self.webpage = webpage | ||
545 | + | ||
546 | + if not has_subject_permissions(request.user, webpage.topic.subject): | ||
547 | + return redirect(reverse_lazy('subjects:home')) | ||
548 | + | ||
549 | + return super(SendMessage, self).dispatch(request, *args, **kwargs) | ||
550 | + | ||
551 | + def form_valid(self, form): | ||
552 | + message = form.cleaned_data.get('comment') | ||
553 | + image = form.cleaned_data.get("image") | ||
554 | + users = (self.request.POST.get('users[]','')).split(",") | ||
555 | + user = self.request.user | ||
556 | + subject = self.webpage.topic.subject | ||
557 | + for u in users: | ||
558 | + to_user = User.objects.get(email=u) | ||
559 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | ||
560 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | ||
561 | + return JsonResponse({"message":"ok"}) | ||
562 | + | ||
563 | + def get_context_data(self, **kwargs): | ||
564 | + context = super(SendMessage,self).get_context_data() | ||
565 | + context["webpage"] = get_object_or_404(Webpage, slug=self.kwargs.get('slug', '')) | ||
566 | + return context | ||
567 | + | ||
568 | + | ||
522 | def sendMessage(request, slug): | 569 | def sendMessage(request, slug): |
523 | message = request.GET.get('message','') | 570 | message = request.GET.get('message','') |
524 | users = request.GET.getlist('users[]','') | 571 | users = request.GET.getlist('users[]','') |