Commit 7483f021b06798af8114bb603a615429bf80fc34
1 parent
e5ad39c7
Exists in
master
and in
3 other branches
Resolvendo bugs do tipo Um mesmo usuário pode ser professor e aluno ao mesmo tempo
Showing
5 changed files
with
146 additions
and
102 deletions
Show diff stats
amadeus/static/js/mural.js
@@ -32,7 +32,7 @@ function postHeightLimits() { | @@ -32,7 +32,7 @@ function postHeightLimits() { | ||
32 | if ($(this).outerHeight() > 500) { | 32 | if ($(this).outerHeight() > 500) { |
33 | var post = $(this), | 33 | var post = $(this), |
34 | btn = post.parent().find('.see-complete'); | 34 | btn = post.parent().find('.see-complete'); |
35 | - | 35 | + |
36 | post.attr('style', 'overflow:hidden;max-height:500px'); | 36 | post.attr('style', 'overflow:hidden;max-height:500px'); |
37 | 37 | ||
38 | btn.attr('style', 'display:block'); | 38 | btn.attr('style', 'display:block'); |
@@ -65,13 +65,13 @@ function setPostFormSubmit(post = "") { | @@ -65,13 +65,13 @@ function setPostFormSubmit(post = "") { | ||
65 | success: function (data) { | 65 | success: function (data) { |
66 | if (post != "") { | 66 | if (post != "") { |
67 | var old = $("#post-" + post); | 67 | var old = $("#post-" + post); |
68 | - | 68 | + |
69 | old.before(data.view); | 69 | old.before(data.view); |
70 | 70 | ||
71 | old.remove(); | 71 | old.remove(); |
72 | } else { | 72 | } else { |
73 | $('.posts:visible').prepend(data.view); | 73 | $('.posts:visible').prepend(data.view); |
74 | - | 74 | + |
75 | new_posts.push(data.new_id); | 75 | new_posts.push(data.new_id); |
76 | 76 | ||
77 | $('.no-subjects:visible').attr('style', 'display:none'); | 77 | $('.no-subjects:visible').attr('style', 'display:none'); |
@@ -95,7 +95,7 @@ function setPostFormSubmit(post = "") { | @@ -95,7 +95,7 @@ function setPostFormSubmit(post = "") { | ||
95 | return false; | 95 | return false; |
96 | }); | 96 | }); |
97 | } | 97 | } |
98 | - | 98 | + |
99 | function favorite(btn) { | 99 | function favorite(btn) { |
100 | var action = btn.data('action'), | 100 | var action = btn.data('action'), |
101 | url = btn.data('url'); | 101 | url = btn.data('url'); |
@@ -121,7 +121,7 @@ function favorite(btn) { | @@ -121,7 +121,7 @@ function favorite(btn) { | ||
121 | function editPost(btn) { | 121 | function editPost(btn) { |
122 | var url = btn.data('url'); | 122 | var url = btn.data('url'); |
123 | var post = btn.data('post'); | 123 | var post = btn.data('post'); |
124 | - | 124 | + |
125 | $.ajax({ | 125 | $.ajax({ |
126 | url: url, | 126 | url: url, |
127 | success: function (data) { | 127 | success: function (data) { |
@@ -163,7 +163,7 @@ function setPostDeleteSubmit (post) { | @@ -163,7 +163,7 @@ function setPostDeleteSubmit (post) { | ||
163 | 163 | ||
164 | $('#post-modal-form').modal('hide'); | 164 | $('#post-modal-form').modal('hide'); |
165 | 165 | ||
166 | - alertify.success(response.msg); | 166 | + alertify.success(response.msg); |
167 | }, | 167 | }, |
168 | error: function (data) { | 168 | error: function (data) { |
169 | console.log(data); | 169 | console.log(data); |
@@ -194,7 +194,7 @@ function editComment(btn) { | @@ -194,7 +194,7 @@ function editComment(btn) { | ||
194 | var url = btn.data('url'), | 194 | var url = btn.data('url'), |
195 | post = btn.data('post'), | 195 | post = btn.data('post'), |
196 | comment = btn.data('id'); | 196 | comment = btn.data('id'); |
197 | - | 197 | + |
198 | $.ajax({ | 198 | $.ajax({ |
199 | url: url, | 199 | url: url, |
200 | success: function (data) { | 200 | success: function (data) { |
@@ -222,7 +222,7 @@ function setCommentFormSubmit(post, comment = "") { | @@ -222,7 +222,7 @@ function setCommentFormSubmit(post, comment = "") { | ||
222 | success: function (data) { | 222 | success: function (data) { |
223 | if (comment != "") { | 223 | if (comment != "") { |
224 | var old = $("#comment-" + comment); | 224 | var old = $("#comment-" + comment); |
225 | - | 225 | + |
226 | old.before(data.view); | 226 | old.before(data.view); |
227 | 227 | ||
228 | old.remove(); | 228 | old.remove(); |
@@ -285,7 +285,7 @@ function setCommentDeleteSubmit (comment) { | @@ -285,7 +285,7 @@ function setCommentDeleteSubmit (comment) { | ||
285 | 285 | ||
286 | $('#post-modal-form').modal('hide'); | 286 | $('#post-modal-form').modal('hide'); |
287 | 287 | ||
288 | - alertify.success(response.msg); | 288 | + alertify.success(response.msg); |
289 | }, | 289 | }, |
290 | error: function (data) { | 290 | error: function (data) { |
291 | console.log(data); | 291 | console.log(data); |
@@ -327,4 +327,4 @@ function loadComments (btn) { | @@ -327,4 +327,4 @@ function loadComments (btn) { | ||
327 | btn.after(response.loaded); | 327 | btn.after(response.loaded); |
328 | } | 328 | } |
329 | }); | 329 | }); |
330 | -} | ||
331 | \ No newline at end of file | 330 | \ No newline at end of file |
331 | +} |
amadeus/templates/base.html
1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
2 | 2 | ||
3 | {% load static i18n django_bootstrap_breadcrumbs %} | 3 | {% load static i18n django_bootstrap_breadcrumbs %} |
4 | +{% get_current_language as LANGUAGE_CODE %} | ||
4 | 5 | ||
5 | <html> | 6 | <html> |
6 | <head> | 7 | <head> |
@@ -27,7 +28,7 @@ | @@ -27,7 +28,7 @@ | ||
27 | <link rel="stylesheet" type="text/css" href="{% static 'css/alertifyjs/alertify.min.css' %}"> | 28 | <link rel="stylesheet" type="text/css" href="{% static 'css/alertifyjs/alertify.min.css' %}"> |
28 | <link rel="stylesheet" type="text/css" href="{% static 'css/alertifyjs/themes/bootstrap.css' %}"> | 29 | <link rel="stylesheet" type="text/css" href="{% static 'css/alertifyjs/themes/bootstrap.css' %}"> |
29 | 30 | ||
30 | - <link rel="stylesheet" type="text/css" href="{% static 'css/jPages.css' %}"> | 31 | + <link rel="stylesheet" type="text/css" href="{% static 'css/jPages.css' %}"> |
31 | 32 | ||
32 | <script type="text/javascript" src="{% static 'bootstrap-3.3.7/js/bootstrap.min.js' %}"></script> | 33 | <script type="text/javascript" src="{% static 'bootstrap-3.3.7/js/bootstrap.min.js' %}"></script> |
33 | <!--<script type="text/javascript" src="{% static 'js/bootstrap-acessibility2.min.js' %}"></script>--> | 34 | <!--<script type="text/javascript" src="{% static 'js/bootstrap-acessibility2.min.js' %}"></script>--> |
@@ -46,7 +47,7 @@ | @@ -46,7 +47,7 @@ | ||
46 | <!-- Custom styles --> | 47 | <!-- Custom styles --> |
47 | <link rel="stylesheet" type="text/css" href="{% static 'css/base/amadeus_responsive.css' %}"> | 48 | <link rel="stylesheet" type="text/css" href="{% static 'css/base/amadeus_responsive.css' %}"> |
48 | <link rel="stylesheet" type="text/css" href="{% static 'css/base/amadeus.css' %}"> | 49 | <link rel="stylesheet" type="text/css" href="{% static 'css/base/amadeus.css' %}"> |
49 | - | 50 | + |
50 | {% block style %} | 51 | {% block style %} |
51 | {% endblock %} | 52 | {% endblock %} |
52 | {% block javascript %} | 53 | {% block javascript %} |
@@ -55,14 +56,14 @@ | @@ -55,14 +56,14 @@ | ||
55 | <!-- Summernote --> | 56 | <!-- Summernote --> |
56 | <script src="{% static 'summernote/summernote.js' %}" type="text/javascript"></script> | 57 | <script src="{% static 'summernote/summernote.js' %}" type="text/javascript"></script> |
57 | <link href="{% static 'summernote/summernote.css' %}" type="text/css" rel="stylesheet" /> | 58 | <link href="{% static 'summernote/summernote.css' %}" type="text/css" rel="stylesheet" /> |
58 | - | 59 | + |
59 | {% with 'css/themes/'|add:theme.css_style|add:'.css' as theme_selected %} | 60 | {% with 'css/themes/'|add:theme.css_style|add:'.css' as theme_selected %} |
60 | <link rel="stylesheet" type="text/css" href="{% static theme_selected %}"> | 61 | <link rel="stylesheet" type="text/css" href="{% static theme_selected %}"> |
61 | {% endwith %} | 62 | {% endwith %} |
62 | 63 | ||
63 | 64 | ||
64 | </head> | 65 | </head> |
65 | -<body> | 66 | +<body data-lang="{{ LANGUAGE_CODE }}"> |
66 | {% block nav %} | 67 | {% block nav %} |
67 | <div class="navbar navbar-default"> | 68 | <div class="navbar navbar-default"> |
68 | <div class="navbar-header"> | 69 | <div class="navbar-header"> |
@@ -76,7 +77,7 @@ | @@ -76,7 +77,7 @@ | ||
76 | <span class="pull-right project_name">{{ theme.title }}</span> | 77 | <span class="pull-right project_name">{{ theme.title }}</span> |
77 | </a> | 78 | </a> |
78 | 79 | ||
79 | - | 80 | + |
80 | </div> | 81 | </div> |
81 | <div class="navbar-collapse collapse navbar-responsive-collapse"> | 82 | <div class="navbar-collapse collapse navbar-responsive-collapse"> |
82 | <div class="col-md-7 col-md-offset-1 col-sm-6 col-sm-offset-1 col-lg-7 col-lg-offset-1 text-center"> | 83 | <div class="col-md-7 col-md-offset-1 col-sm-6 col-sm-offset-1 col-lg-7 col-lg-offset-1 text-center"> |
@@ -93,29 +94,29 @@ | @@ -93,29 +94,29 @@ | ||
93 | </div> | 94 | </div> |
94 | </form> | 95 | </form> |
95 | </div> | 96 | </div> |
96 | - | 97 | + |
97 | <ul class="nav navbar-nav navbar-right notifications"> | 98 | <ul class="nav navbar-nav navbar-right notifications"> |
98 | 99 | ||
99 | - <li class="dropdown language-selector-on-header {{ settings_menu_active }}" title data-original-title="{% trans 'Language Selector' %}"> | ||
100 | - {% get_current_language as LANGUAGE_CODE %} | 100 | + <li class="dropdown language-selector-on-header {{ settings_menu_active }}" title data-original-title="{% trans 'Language Selector' %}"> |
101 | + | ||
101 | 102 | ||
102 | <a href="#" class="dropdown-toggle title" data-toggle="dropdown" data-close-others="true"> | 103 | <a href="#" class="dropdown-toggle title" data-toggle="dropdown" data-close-others="true"> |
103 | <i class="fa fa-cog hidden-xs" aria-hidden="true"></i> | 104 | <i class="fa fa-cog hidden-xs" aria-hidden="true"></i> |
104 | <span class="visible-xs-inline">{% trans 'Language Selector' %}</span> | 105 | <span class="visible-xs-inline">{% trans 'Language Selector' %}</span> |
105 | - {% with 'img/'|add:LANGUAGE_CODE|add:'.png' as image_static %} | 106 | + {% with 'img/'|add:LANGUAGE_CODE|add:'.png' as image_static %} |
106 | <img src="{% static image_static %}" /> | 107 | <img src="{% static image_static %}" /> |
107 | - {% endwith %} | 108 | + {% endwith %} |
108 | </a> | 109 | </a> |
109 | <a href="#" class="dropdown-toggle no-title" data-toggle="dropdown" data-close-others="true"> | 110 | <a href="#" class="dropdown-toggle no-title" data-toggle="dropdown" data-close-others="true"> |
110 | 111 | ||
111 | {% with 'img/'|add:LANGUAGE_CODE|add:'.png' as image_static %} | 112 | {% with 'img/'|add:LANGUAGE_CODE|add:'.png' as image_static %} |
112 | <img src="{% static image_static %}" /> | 113 | <img src="{% static image_static %}" /> |
113 | {% endwith %} | 114 | {% endwith %} |
114 | - | 115 | + |
115 | </a> | 116 | </a> |
116 | <ul class="dropdown-menu"> | 117 | <ul class="dropdown-menu"> |
117 | 118 | ||
118 | - | 119 | + |
119 | {% get_available_languages as LANGUAGES %} | 120 | {% get_available_languages as LANGUAGES %} |
120 | {% get_language_info_list for LANGUAGES as languages %} | 121 | {% get_language_info_list for LANGUAGES as languages %} |
121 | {% for language in languages %} | 122 | {% for language in languages %} |
@@ -130,11 +131,11 @@ | @@ -130,11 +131,11 @@ | ||
130 | <span>{{language.code}}</span> | 131 | <span>{{language.code}}</span> |
131 | </a> | 132 | </a> |
132 | </li> | 133 | </li> |
133 | - | 134 | + |
134 | {% endfor %} | 135 | {% endfor %} |
135 | </ul> | 136 | </ul> |
136 | </li> | 137 | </li> |
137 | - | 138 | + |
138 | 139 | ||
139 | <li id="profile-menu" class="dropdown" data-toggle="tooltip" data-placement="bottom" title data-original-title="{{ user }}"> | 140 | <li id="profile-menu" class="dropdown" data-toggle="tooltip" data-placement="bottom" title data-original-title="{{ user }}"> |
140 | <a href="" data-toggle="dropdown" class="dropdown-toggle profile"> | 141 | <a href="" data-toggle="dropdown" class="dropdown-toggle profile"> |
@@ -155,7 +156,7 @@ | @@ -155,7 +156,7 @@ | ||
155 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | 156 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> |
156 | <i class="fa fa-cog hidden-xs" aria-hidden="true"></i> | 157 | <i class="fa fa-cog hidden-xs" aria-hidden="true"></i> |
157 | <span class="visible-xs-inline">{% trans 'Settings' %}</span> | 158 | <span class="visible-xs-inline">{% trans 'Settings' %}</span> |
158 | - </a> | 159 | + </a> |
159 | <ul class="dropdown-menu" role="menu"> | 160 | <ul class="dropdown-menu" role="menu"> |
160 | <li><a href="{% url 'users:manage' %}">{% trans 'Manage Users' %}</a></li> | 161 | <li><a href="{% url 'users:manage' %}">{% trans 'Manage Users' %}</a></li> |
161 | <li><a href="{% url 'categories:index' %}">{% trans 'Manage Categories' %}</a></li> | 162 | <li><a href="{% url 'categories:index' %}">{% trans 'Manage Categories' %}</a></li> |
@@ -269,7 +270,7 @@ | @@ -269,7 +270,7 @@ | ||
269 | </a> | 270 | </a> |
270 | </li> | 271 | </li> |
271 | <li class="item" data-toggle="tooltip" data-placement="top" title="{% trans "Analytics" %}"> | 272 | <li class="item" data-toggle="tooltip" data-placement="top" title="{% trans "Analytics" %}"> |
272 | - <i class="fa fa-bar-chart" aria-hidden="true"></i> | 273 | + <i class="fa fa-bar-chart" aria-hid{% get_current_language as LANGUAGE_CODE %}den="true"></i> |
273 | </li> | 274 | </li> |
274 | </ul> | 275 | </ul> |
275 | </div> | 276 | </div> |
@@ -288,11 +289,11 @@ | @@ -288,11 +289,11 @@ | ||
288 | 289 | ||
289 | <script> | 290 | <script> |
290 | $(".language-item").click(function(event) { | 291 | $(".language-item").click(function(event) { |
291 | - | 292 | + |
292 | change_language.post("{% url 'set_language' %}", {'language': $(this)[0].attributes[1].value, next: "{% url 'users:login' %}", csrfmiddlewaretoken: '{{ csrf_token }}' } ); | 293 | change_language.post("{% url 'set_language' %}", {'language': $(this)[0].attributes[1].value, next: "{% url 'users:login' %}", csrfmiddlewaretoken: '{{ csrf_token }}' } ); |
293 | - | 294 | + |
294 | }); | 295 | }); |
295 | </script> | 296 | </script> |
296 | </body> | 297 | </body> |
297 | 298 | ||
298 | -</html> | ||
299 | \ No newline at end of file | 299 | \ No newline at end of file |
300 | +</html> |
subjects/forms.py
@@ -175,7 +175,6 @@ class UpdateSubjectForm(forms.ModelForm): | @@ -175,7 +175,6 @@ class UpdateSubjectForm(forms.ModelForm): | ||
175 | def clean_subscribe_begin(self): | 175 | def clean_subscribe_begin(self): |
176 | subscribe_begin = self.cleaned_data['subscribe_begin'] | 176 | subscribe_begin = self.cleaned_data['subscribe_begin'] |
177 | 177 | ||
178 | - print (self.instance.subscribe_begin, "################################") | ||
179 | if subscribe_begin < datetime.datetime.today().date() and subscribe_begin < self.instance.subscribe_begin: | 178 | if subscribe_begin < datetime.datetime.today().date() and subscribe_begin < self.instance.subscribe_begin: |
180 | self._errors['subscribe_begin'] = [_('This date must be today or after')] | 179 | self._errors['subscribe_begin'] = [_('This date must be today or after')] |
181 | return ValueError | 180 | return ValueError |
subjects/templates/subjects/_form.html
@@ -98,6 +98,9 @@ | @@ -98,6 +98,9 @@ | ||
98 | $selectionSearch = that.$selectionUl.prev(), | 98 | $selectionSearch = that.$selectionUl.prev(), |
99 | selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | 99 | selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', |
100 | selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | 100 | selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; |
101 | + // console.log($selectableSearch); | ||
102 | + // alert("oi"); | ||
103 | + // console.log($eselectableSearch); | ||
101 | 104 | ||
102 | that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | 105 | that.qs1 = $selectableSearch.quicksearch(selectableSearchString) |
103 | .on('keydown', function(e){ | 106 | .on('keydown', function(e){ |
@@ -115,11 +118,18 @@ | @@ -115,11 +118,18 @@ | ||
115 | } | 118 | } |
116 | }); | 119 | }); |
117 | }, | 120 | }, |
118 | - afterSelect: function(){ | ||
119 | - this.qs1.cache(); | 121 | + afterSelect: function(values){ |
122 | + $("#id_students option[value='" + values[0] + "']").remove(); | ||
123 | + $('#id_students').multiSelect('refresh'); | ||
124 | + | ||
125 | + this.qs1.cache(); | ||
120 | this.qs2.cache(); | 126 | this.qs2.cache(); |
121 | }, | 127 | }, |
122 | - afterDeselect: function(){ | 128 | + afterDeselect: function(values){ |
129 | + var label = $("#id_professor option[value='" + values[0] + "']").text(); | ||
130 | + | ||
131 | + $("#id_students").multiSelect('addOption', {value: values[0], text: label}); | ||
132 | + | ||
123 | this.qs1.cache(); | 133 | this.qs1.cache(); |
124 | this.qs2.cache(); | 134 | this.qs2.cache(); |
125 | } | 135 | } |
@@ -135,6 +145,7 @@ | @@ -135,6 +145,7 @@ | ||
135 | selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | 145 | selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', |
136 | selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | 146 | selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; |
137 | 147 | ||
148 | + | ||
138 | that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | 149 | that.qs1 = $selectableSearch.quicksearch(selectableSearchString) |
139 | .on('keydown', function(e){ | 150 | .on('keydown', function(e){ |
140 | if (e.which === 40){ | 151 | if (e.which === 40){ |
@@ -151,11 +162,21 @@ | @@ -151,11 +162,21 @@ | ||
151 | } | 162 | } |
152 | }); | 163 | }); |
153 | }, | 164 | }, |
154 | - afterSelect: function(){ | 165 | + // afterInit: function(){ |
166 | + // | ||
167 | + // }, | ||
168 | + afterSelect: function(values){ | ||
169 | + $("#id_professor option[value='" + values[0] + "']").remove(); | ||
170 | + $('#id_professor').multiSelect('refresh'); | ||
171 | + | ||
155 | this.qs1.cache(); | 172 | this.qs1.cache(); |
156 | this.qs2.cache(); | 173 | this.qs2.cache(); |
157 | }, | 174 | }, |
158 | - afterDeselect: function(){ | 175 | + afterDeselect: function(values){ |
176 | + var label = $("#id_students option[value='" + values[0] + "']").text(); | ||
177 | + | ||
178 | + $("#id_professor").multiSelect('addOption', {value: values[0], text: label}); | ||
179 | + | ||
159 | this.qs1.cache(); | 180 | this.qs1.cache(); |
160 | this.qs2.cache(); | 181 | this.qs2.cache(); |
161 | } | 182 | } |
@@ -163,17 +184,23 @@ | @@ -163,17 +184,23 @@ | ||
163 | 184 | ||
164 | $('.collapse').on('show.bs.collapse', function (e) { | 185 | $('.collapse').on('show.bs.collapse', function (e) { |
165 | if($(this).is(e.target)){ | 186 | if($(this).is(e.target)){ |
166 | - var btn = $(this).parent().find('.fa-angle-right'); | 187 | + // console.log(e); |
188 | + var btn = $(this).parent().find('.fa-angle-right'); | ||
167 | 189 | ||
168 | btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | 190 | btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); |
169 | - } | 191 | + |
192 | + $(this).parent().parent().parent().find('.panel-collapse.in').collapse('hide'); | ||
193 | + } | ||
194 | + | ||
195 | + | ||
170 | }); | 196 | }); |
171 | 197 | ||
172 | $('.collapse').on('hide.bs.collapse', function (e) { | 198 | $('.collapse').on('hide.bs.collapse', function (e) { |
199 | + // console.log(e); | ||
173 | if($(this).is(e.target)){ | 200 | if($(this).is(e.target)){ |
174 | var btn = $(this).parent().find('.fa-angle-down'); | 201 | var btn = $(this).parent().find('.fa-angle-down'); |
175 | 202 | ||
176 | btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | 203 | btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); |
177 | } | 204 | } |
178 | }); | 205 | }); |
179 | -</script> | ||
180 | \ No newline at end of file | 206 | \ No newline at end of file |
207 | +</script> |
subjects/views.py
@@ -40,7 +40,7 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -40,7 +40,7 @@ class HomeView(LoginRequiredMixin, ListView): | ||
40 | template_name = 'subjects/initial.html' | 40 | template_name = 'subjects/initial.html' |
41 | context_object_name = 'subjects' | 41 | context_object_name = 'subjects' |
42 | paginate_by = 10 | 42 | paginate_by = 10 |
43 | - total = 0 | 43 | + total = 0 |
44 | 44 | ||
45 | def get_queryset(self): | 45 | def get_queryset(self): |
46 | if self.request.user.is_staff: | 46 | if self.request.user.is_staff: |
@@ -49,7 +49,7 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -49,7 +49,7 @@ class HomeView(LoginRequiredMixin, ListView): | ||
49 | pk = self.request.user.pk | 49 | pk = self.request.user.pk |
50 | 50 | ||
51 | subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk)).distinct() | 51 | subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk)).distinct() |
52 | - | 52 | + |
53 | self.total = subjects.count() | 53 | self.total = subjects.count() |
54 | 54 | ||
55 | return subjects | 55 | return subjects |
@@ -58,7 +58,7 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -58,7 +58,7 @@ class HomeView(LoginRequiredMixin, ListView): | ||
58 | context = super(HomeView, self).get_context_data(**kwargs) | 58 | context = super(HomeView, self).get_context_data(**kwargs) |
59 | context['title'] = _('Home') | 59 | context['title'] = _('Home') |
60 | context['show_buttons'] = True #So it shows subscribe and access buttons | 60 | context['show_buttons'] = True #So it shows subscribe and access buttons |
61 | - | 61 | + |
62 | #bringing users | 62 | #bringing users |
63 | tag_amount = 50 | 63 | tag_amount = 50 |
64 | tags = Tag.objects.all() | 64 | tags = Tag.objects.all() |
@@ -68,14 +68,14 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -68,14 +68,14 @@ class HomeView(LoginRequiredMixin, ListView): | ||
68 | if Resource.objects.filter(tags__pk=tag.pk, students__pk = self.request.user.pk).count() > 0 or Subject.objects.filter(tags__pk = tag.pk).count() > 0: | 68 | if Resource.objects.filter(tags__pk=tag.pk, students__pk = self.request.user.pk).count() > 0 or Subject.objects.filter(tags__pk = tag.pk).count() > 0: |
69 | tags_list.append((tag.name, Subject.objects.filter(tags__pk = tag.pk).count())) | 69 | tags_list.append((tag.name, Subject.objects.filter(tags__pk = tag.pk).count())) |
70 | tags_list.sort(key= lambda x: x[1], reverse=True) #sort by value | 70 | tags_list.sort(key= lambda x: x[1], reverse=True) #sort by value |
71 | - | 71 | + |
72 | elif len(tags_list) > tag_amount: | 72 | elif len(tags_list) > tag_amount: |
73 | count = Subject.objects.filter(tags__pk = tag.pk).count() | 73 | count = Subject.objects.filter(tags__pk = tag.pk).count() |
74 | if count > tags_list[tag_amount][1]: | 74 | if count > tags_list[tag_amount][1]: |
75 | tags_list[tag_amount - 1] = (tag.name, count) | 75 | tags_list[tag_amount - 1] = (tag.name, count) |
76 | tags_list.sort(key = lambda x: x[1], reverse=True) | 76 | tags_list.sort(key = lambda x: x[1], reverse=True) |
77 | 77 | ||
78 | - | 78 | + |
79 | i = 0 | 79 | i = 0 |
80 | tags = [] | 80 | tags = [] |
81 | 81 | ||
@@ -104,50 +104,50 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -104,50 +104,50 @@ class IndexView(LoginRequiredMixin, ListView): | ||
104 | context_object_name = 'categories' | 104 | context_object_name = 'categories' |
105 | paginate_by = 10 | 105 | paginate_by = 10 |
106 | 106 | ||
107 | - def get_queryset(self): | 107 | + def get_queryset(self): |
108 | self.totals['all_subjects'] = count_subjects(self.request.user) | 108 | self.totals['all_subjects'] = count_subjects(self.request.user) |
109 | - | 109 | + |
110 | self.totals['my_subjects'] = self.totals['all_subjects'] | 110 | self.totals['my_subjects'] = self.totals['all_subjects'] |
111 | - | 111 | + |
112 | if self.request.user.is_staff: | 112 | if self.request.user.is_staff: |
113 | categories = Category.objects.all().order_by('name') | 113 | categories = Category.objects.all().order_by('name') |
114 | else: | 114 | else: |
115 | pk = self.request.user.pk | 115 | pk = self.request.user.pk |
116 | - | 116 | + |
117 | self.totals['my_subjects'] = count_subjects(self.request.user, False) | 117 | self.totals['my_subjects'] = count_subjects(self.request.user, False) |
118 | - | 118 | + |
119 | if not self.kwargs.get('option'): | 119 | if not self.kwargs.get('option'): |
120 | my_categories = Category.objects.filter(Q(coordinators__pk=pk) | Q(subject_category__professor__pk=pk) | Q(subject_category__students__pk = pk, visible = True)).distinct().order_by('name') | 120 | my_categories = Category.objects.filter(Q(coordinators__pk=pk) | Q(subject_category__professor__pk=pk) | Q(subject_category__students__pk = pk, visible = True)).distinct().order_by('name') |
121 | - | 121 | + |
122 | categories = my_categories | 122 | categories = my_categories |
123 | else: | 123 | else: |
124 | categories = Category.objects.filter(Q(coordinators__pk = pk) | Q(visible=True) ).distinct().order_by('name') | 124 | categories = Category.objects.filter(Q(coordinators__pk = pk) | Q(visible=True) ).distinct().order_by('name') |
125 | - | 125 | + |
126 | #if not self.request.user.is_staff: | 126 | #if not self.request.user.is_staff: |
127 | - | 127 | + |
128 | #my_categories = [category for category in categories if self.request.user in category.coordinators.all() \ | 128 | #my_categories = [category for category in categories if self.request.user in category.coordinators.all() \ |
129 | - #or has_professor_profile(self.request.user, category) or has_student_profile(self.request.user, category)] | 129 | + #or has_professor_profile(self.request.user, category) or has_student_profile(self.request.user, category)] |
130 | #So I remove all categories that doesn't have the possibility for the user to be on | 130 | #So I remove all categories that doesn't have the possibility for the user to be on |
131 | - | 131 | + |
132 | 132 | ||
133 | return categories | 133 | return categories |
134 | 134 | ||
135 | - def paginate_queryset(self, queryset, page_size): | 135 | + def paginate_queryset(self, queryset, page_size): |
136 | paginator = self.get_paginator( | 136 | paginator = self.get_paginator( |
137 | queryset, page_size, orphans=self.get_paginate_orphans(), | 137 | queryset, page_size, orphans=self.get_paginate_orphans(), |
138 | allow_empty_first_page=self.get_allow_empty()) | 138 | allow_empty_first_page=self.get_allow_empty()) |
139 | - | 139 | + |
140 | page_kwarg = self.page_kwarg | 140 | page_kwarg = self.page_kwarg |
141 | - | 141 | + |
142 | page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1 | 142 | page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1 |
143 | - | 143 | + |
144 | if self.kwargs.get('slug'): | 144 | if self.kwargs.get('slug'): |
145 | categories = queryset | 145 | categories = queryset |
146 | 146 | ||
147 | paginator = Paginator(categories, self.paginate_by) | 147 | paginator = Paginator(categories, self.paginate_by) |
148 | 148 | ||
149 | page = get_category_page(categories, self.kwargs.get('slug'), self.paginate_by) | 149 | page = get_category_page(categories, self.kwargs.get('slug'), self.paginate_by) |
150 | - | 150 | + |
151 | try: | 151 | try: |
152 | page_number = int(page) | 152 | page_number = int(page) |
153 | except ValueError: | 153 | except ValueError: |
@@ -155,7 +155,7 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -155,7 +155,7 @@ class IndexView(LoginRequiredMixin, ListView): | ||
155 | page_number = paginator.num_pages | 155 | page_number = paginator.num_pages |
156 | else: | 156 | else: |
157 | raise Http404(_("Page is not 'last', nor can it be converted to an int.")) | 157 | raise Http404(_("Page is not 'last', nor can it be converted to an int.")) |
158 | - | 158 | + |
159 | try: | 159 | try: |
160 | page = paginator.page(page_number) | 160 | page = paginator.page(page_number) |
161 | return (paginator, page, page.object_list, page.has_other_pages()) | 161 | return (paginator, page, page.object_list, page.has_other_pages()) |
@@ -174,7 +174,7 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -174,7 +174,7 @@ class IndexView(LoginRequiredMixin, ListView): | ||
174 | if self.request.is_ajax(): | 174 | if self.request.is_ajax(): |
175 | if self.request.user.is_staff: | 175 | if self.request.user.is_staff: |
176 | self.template_name = "categories/home_admin_content.html" | 176 | self.template_name = "categories/home_admin_content.html" |
177 | - | 177 | + |
178 | 178 | ||
179 | return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) | 179 | return self.response_class(request = self.request, template = self.template_name, context = context, using = self.template_engine, **response_kwargs) |
180 | 180 | ||
@@ -186,7 +186,7 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -186,7 +186,7 @@ class IndexView(LoginRequiredMixin, ListView): | ||
186 | 186 | ||
187 | context['show_buttons'] = True #So it shows subscribe and access buttons | 187 | context['show_buttons'] = True #So it shows subscribe and access buttons |
188 | context['totals'] = self.totals | 188 | context['totals'] = self.totals |
189 | - | 189 | + |
190 | if self.kwargs.get('option'): | 190 | if self.kwargs.get('option'): |
191 | context['all'] = True | 191 | context['all'] = True |
192 | context['title'] = _('All Subjects') | 192 | context['title'] = _('All Subjects') |
@@ -234,13 +234,13 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | @@ -234,13 +234,13 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | ||
234 | login_url = reverse_lazy('users:login') | 234 | login_url = reverse_lazy('users:login') |
235 | redirect_field_name = 'next' | 235 | redirect_field_name = 'next' |
236 | form_class = CreateSubjectForm | 236 | form_class = CreateSubjectForm |
237 | - | 237 | + |
238 | success_url = reverse_lazy('subject:index') | 238 | success_url = reverse_lazy('subject:index') |
239 | 239 | ||
240 | def dispatch(self, request, *args, **kwargs): | 240 | def dispatch(self, request, *args, **kwargs): |
241 | if kwargs.get('subject_slug'): | 241 | if kwargs.get('subject_slug'): |
242 | subject = get_object_or_404(Subject, slug = kwargs.get('subject_slug', '')) | 242 | subject = get_object_or_404(Subject, slug = kwargs.get('subject_slug', '')) |
243 | - | 243 | + |
244 | if not has_category_permissions(request.user, subject.category): | 244 | if not has_category_permissions(request.user, subject.category): |
245 | return redirect(reverse_lazy('subjects:home')) | 245 | return redirect(reverse_lazy('subjects:home')) |
246 | 246 | ||
@@ -249,15 +249,17 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | @@ -249,15 +249,17 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | ||
249 | 249 | ||
250 | if not has_category_permissions(request.user, category): | 250 | if not has_category_permissions(request.user, category): |
251 | return redirect(reverse_lazy('subjects:home')) | 251 | return redirect(reverse_lazy('subjects:home')) |
252 | - | 252 | + |
253 | return super(SubjectCreateView, self).dispatch(request, *args, **kwargs) | 253 | return super(SubjectCreateView, self).dispatch(request, *args, **kwargs) |
254 | - | 254 | + |
255 | 255 | ||
256 | def get_initial(self): | 256 | def get_initial(self): |
257 | initial = super(SubjectCreateView, self).get_initial() | 257 | initial = super(SubjectCreateView, self).get_initial() |
258 | - | 258 | + |
259 | if self.kwargs.get('slug'): #when the user creates a subject | 259 | if self.kwargs.get('slug'): #when the user creates a subject |
260 | initial['category'] = Category.objects.all().filter(slug=self.kwargs['slug']) | 260 | initial['category'] = Category.objects.all().filter(slug=self.kwargs['slug']) |
261 | + # print (initial) | ||
262 | + # initial['professor'] = User.objects.all() | ||
261 | 263 | ||
262 | if self.kwargs.get('subject_slug'): #when the user replicate a subject | 264 | if self.kwargs.get('subject_slug'): #when the user replicate a subject |
263 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) | 265 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) |
@@ -272,7 +274,7 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | @@ -272,7 +274,7 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | ||
272 | initial['end_date'] = subject.end_date | 274 | initial['end_date'] = subject.end_date |
273 | initial['students'] = subject.students.all() | 275 | initial['students'] = subject.students.all() |
274 | initial['description_brief'] = subject.description_brief | 276 | initial['description_brief'] = subject.description_brief |
275 | - | 277 | + |
276 | self.log_action = 'replicate' | 278 | self.log_action = 'replicate' |
277 | 279 | ||
278 | self.log_context['replicated_subject_id'] = subject.id | 280 | self.log_context['replicated_subject_id'] = subject.id |
@@ -284,35 +286,41 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | @@ -284,35 +286,41 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | ||
284 | def get_context_data(self, **kwargs): | 286 | def get_context_data(self, **kwargs): |
285 | context = super(SubjectCreateView, self).get_context_data(**kwargs) | 287 | context = super(SubjectCreateView, self).get_context_data(**kwargs) |
286 | context['title'] = _('Create Subject') | 288 | context['title'] = _('Create Subject') |
287 | - | 289 | + try: |
290 | + students_selected = context['form'].cleaned_data['students'].values_list('id',flat=True) | ||
291 | + professors_selected = context['form'].cleaned_data['professor'].values_list('id',flat=True) | ||
292 | + context['form'].fields['professor'].queryset = context['form'].fields['professor'].queryset.exclude(id__in=students_selected) | ||
293 | + context['form'].fields['students'].queryset = context['form'].fields['students'].queryset.exclude(id__in=professors_selected) | ||
294 | + except AttributeError: | ||
295 | + pass | ||
288 | if self.kwargs.get('slug'): | 296 | if self.kwargs.get('slug'): |
289 | context['slug'] = self.kwargs['slug'] | 297 | context['slug'] = self.kwargs['slug'] |
290 | - | 298 | + |
291 | if self.kwargs.get('subject_slug'): | 299 | if self.kwargs.get('subject_slug'): |
292 | context['title'] = _('Replicate Subject') | 300 | context['title'] = _('Replicate Subject') |
293 | 301 | ||
294 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) | 302 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) |
295 | - | 303 | + |
296 | context['slug'] = subject.category.slug | 304 | context['slug'] = subject.category.slug |
297 | context['replicate'] = True | 305 | context['replicate'] = True |
298 | 306 | ||
299 | context['subject'] = subject | 307 | context['subject'] = subject |
300 | 308 | ||
301 | context['subjects_menu_active'] = 'subjects_menu_active' | 309 | context['subjects_menu_active'] = 'subjects_menu_active' |
302 | - | 310 | + |
303 | return context | 311 | return context |
304 | 312 | ||
305 | def form_valid(self, form): | 313 | def form_valid(self, form): |
306 | - | 314 | + |
307 | self.object = form.save() | 315 | self.object = form.save() |
308 | - | 316 | + |
309 | if self.kwargs.get('slug'): | 317 | if self.kwargs.get('slug'): |
310 | self.object.category = Category.objects.get(slug=self.kwargs['slug']) | 318 | self.object.category = Category.objects.get(slug=self.kwargs['slug']) |
311 | - | 319 | + |
312 | if self.kwargs.get('subject_slug'): | 320 | if self.kwargs.get('subject_slug'): |
313 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) | 321 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) |
314 | self.object.category = subject.category | 322 | self.object.category = subject.category |
315 | - | 323 | + |
316 | self.object.save() | 324 | self.object.save() |
317 | 325 | ||
318 | self.log_context['category_id'] = self.object.category.id | 326 | self.log_context['category_id'] = self.object.category.id |
@@ -322,7 +330,7 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | @@ -322,7 +330,7 @@ class SubjectCreateView(LoginRequiredMixin, LogMixin, CreateView): | ||
322 | self.log_context['subject_name'] = self.object.name | 330 | self.log_context['subject_name'] = self.object.name |
323 | self.log_context['subject_slug'] = self.object.slug | 331 | self.log_context['subject_slug'] = self.object.slug |
324 | 332 | ||
325 | - super(SubjectCreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 333 | + super(SubjectCreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
326 | 334 | ||
327 | return super(SubjectCreateView, self).form_valid(form) | 335 | return super(SubjectCreateView, self).form_valid(form) |
328 | 336 | ||
@@ -349,7 +357,7 @@ class SubjectUpdateView(LoginRequiredMixin, LogMixin, UpdateView): | @@ -349,7 +357,7 @@ class SubjectUpdateView(LoginRequiredMixin, LogMixin, UpdateView): | ||
349 | 357 | ||
350 | def dispatch(self, request, *args, **kwargs): | 358 | def dispatch(self, request, *args, **kwargs): |
351 | subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) | 359 | subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) |
352 | - | 360 | + self.subject = subject |
353 | if not has_subject_permissions(request.user, subject): | 361 | if not has_subject_permissions(request.user, subject): |
354 | return redirect(reverse_lazy('subjects:home')) | 362 | return redirect(reverse_lazy('subjects:home')) |
355 | 363 | ||
@@ -357,10 +365,19 @@ class SubjectUpdateView(LoginRequiredMixin, LogMixin, UpdateView): | @@ -357,10 +365,19 @@ class SubjectUpdateView(LoginRequiredMixin, LogMixin, UpdateView): | ||
357 | 365 | ||
358 | def get_context_data(self, **kwargs): | 366 | def get_context_data(self, **kwargs): |
359 | context = super(SubjectUpdateView, self).get_context_data(**kwargs) | 367 | context = super(SubjectUpdateView, self).get_context_data(**kwargs) |
368 | + try: | ||
369 | + students_selected = context['form'].cleaned_data['students'].values_list('id',flat=True) | ||
370 | + professors_selected = context['form'].cleaned_data['professor'].values_list('id',flat=True) | ||
371 | + except AttributeError: | ||
372 | + students_selected = self.subject.students.all().values_list('id',flat=True) | ||
373 | + professors_selected = self.subject.professor.all().values_list('id',flat=True) | ||
374 | + | ||
375 | + context['form'].fields['professor'].queryset = context['form'].fields['professor'].queryset.exclude(id__in=students_selected) | ||
376 | + context['form'].fields['students'].queryset = context['form'].fields['students'].queryset.exclude(id__in=professors_selected) | ||
360 | context['title'] = _('Update Subject') | 377 | context['title'] = _('Update Subject') |
361 | context['template_extends'] = 'categories/home.html' | 378 | context['template_extends'] = 'categories/home.html' |
362 | context['subjects_menu_active'] = 'subjects_menu_active' | 379 | context['subjects_menu_active'] = 'subjects_menu_active' |
363 | - | 380 | + |
364 | return context | 381 | return context |
365 | 382 | ||
366 | def get_success_url(self): | 383 | def get_success_url(self): |
@@ -380,9 +397,9 @@ class SubjectUpdateView(LoginRequiredMixin, LogMixin, UpdateView): | @@ -380,9 +397,9 @@ class SubjectUpdateView(LoginRequiredMixin, LogMixin, UpdateView): | ||
380 | self.log_context['subject_slug'] = self.object.slug | 397 | self.log_context['subject_slug'] = self.object.slug |
381 | 398 | ||
382 | super(SubjectUpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 399 | super(SubjectUpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
383 | - | 400 | + |
384 | messages.success(self.request, _('The Subject "%s" was updated on "%s" Category successfully!')%(self.object.name, self.object.category.name )) | 401 | messages.success(self.request, _('The Subject "%s" was updated on "%s" Category successfully!')%(self.object.name, self.object.category.name )) |
385 | - | 402 | + |
386 | return reverse_lazy('subjects:index') | 403 | return reverse_lazy('subjects:index') |
387 | 404 | ||
388 | class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | 405 | class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): |
@@ -390,7 +407,7 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | @@ -390,7 +407,7 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | ||
390 | log_action = 'delete' | 407 | log_action = 'delete' |
391 | log_resource = 'subject' | 408 | log_resource = 'subject' |
392 | log_context = {} | 409 | log_context = {} |
393 | - | 410 | + |
394 | login_url = reverse_lazy("users:login") | 411 | login_url = reverse_lazy("users:login") |
395 | redirect_field_name = 'next' | 412 | redirect_field_name = 'next' |
396 | model = Subject | 413 | model = Subject |
@@ -398,7 +415,7 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | @@ -398,7 +415,7 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | ||
398 | 415 | ||
399 | def dispatch(self, request, *args, **kwargs): | 416 | def dispatch(self, request, *args, **kwargs): |
400 | subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) | 417 | subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) |
401 | - | 418 | + |
402 | if not has_subject_permissions(request.user, subject): | 419 | if not has_subject_permissions(request.user, subject): |
403 | return redirect(reverse_lazy('subjects:home')) | 420 | return redirect(reverse_lazy('subjects:home')) |
404 | 421 | ||
@@ -419,11 +436,11 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | @@ -419,11 +436,11 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | ||
419 | self.log_context['subject_id'] = self.object.id | 436 | self.log_context['subject_id'] = self.object.id |
420 | self.log_context['subject_name'] = self.object.name | 437 | self.log_context['subject_name'] = self.object.name |
421 | self.log_context['subject_slug'] = self.object.slug | 438 | self.log_context['subject_slug'] = self.object.slug |
422 | - | 439 | + |
423 | super(SubjectDeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 440 | super(SubjectDeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
424 | 441 | ||
425 | messages.success(self.request, _('Subject "%s" removed successfully!')%(self.object.name)) | 442 | messages.success(self.request, _('Subject "%s" removed successfully!')%(self.object.name)) |
426 | - | 443 | + |
427 | return JsonResponse({'url':reverse_lazy('subjects:index')}) | 444 | return JsonResponse({'url':reverse_lazy('subjects:index')}) |
428 | 445 | ||
429 | 446 | ||
@@ -440,14 +457,14 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | @@ -440,14 +457,14 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | ||
440 | return self.render_to_response(context) | 457 | return self.render_to_response(context) |
441 | 458 | ||
442 | def post(self, *args, **kwargs): | 459 | def post(self, *args, **kwargs): |
443 | - | 460 | + |
444 | return self.delete(*args, **kwargs) | 461 | return self.delete(*args, **kwargs) |
445 | 462 | ||
446 | def get_context_data(self, **kwargs): | 463 | def get_context_data(self, **kwargs): |
447 | context = super(SubjectDeleteView, self).get_context_data(**kwargs) | 464 | context = super(SubjectDeleteView, self).get_context_data(**kwargs) |
448 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) | 465 | subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) |
449 | context['subject'] = subject | 466 | context['subject'] = subject |
450 | - | 467 | + |
451 | if (self.request.GET.get('view') == 'index'): | 468 | if (self.request.GET.get('view') == 'index'): |
452 | context['index'] = True | 469 | context['index'] = True |
453 | else: | 470 | else: |
@@ -465,9 +482,9 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | @@ -465,9 +482,9 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): | ||
465 | 482 | ||
466 | super(SubjectDeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 483 | super(SubjectDeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
467 | 484 | ||
468 | - | 485 | + |
469 | messages.success(self.request, _('Subject "%s" removed successfully!')%(self.object.name)) | 486 | messages.success(self.request, _('Subject "%s" removed successfully!')%(self.object.name)) |
470 | - | 487 | + |
471 | return reverse_lazy('subjects:index') | 488 | return reverse_lazy('subjects:index') |
472 | 489 | ||
473 | 490 | ||
@@ -556,7 +573,7 @@ class SubjectSubscribeView(LoginRequiredMixin, LogMixin, TemplateView): | @@ -556,7 +573,7 @@ class SubjectSubscribeView(LoginRequiredMixin, LogMixin, TemplateView): | ||
556 | subject.students.add(request.user) | 573 | subject.students.add(request.user) |
557 | subject.save() | 574 | subject.save() |
558 | messages.success(self.request, _('Subscription was successfull!')) | 575 | messages.success(self.request, _('Subscription was successfull!')) |
559 | - | 576 | + |
560 | return JsonResponse({'url':reverse_lazy('subjects:index')}) | 577 | return JsonResponse({'url':reverse_lazy('subjects:index')}) |
561 | 578 | ||
562 | 579 | ||
@@ -582,11 +599,11 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): | @@ -582,11 +599,11 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): | ||
582 | 599 | ||
583 | if tags[0] == '': | 600 | if tags[0] == '': |
584 | return HttpResponseRedirect(request.META.get('HTTP_REFERER')) | 601 | return HttpResponseRedirect(request.META.get('HTTP_REFERER')) |
585 | - | 602 | + |
586 | return super(SubjectSearchView, self).dispatch(request, *args, **kwargs) | 603 | return super(SubjectSearchView, self).dispatch(request, *args, **kwargs) |
587 | - | 604 | + |
588 | def get_queryset(self): | 605 | def get_queryset(self): |
589 | - | 606 | + |
590 | tags = self.request.GET.get('search') | 607 | tags = self.request.GET.get('search') |
591 | 608 | ||
592 | self.tags = tags | 609 | self.tags = tags |
@@ -595,23 +612,23 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): | @@ -595,23 +612,23 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): | ||
595 | for tag in tags: | 612 | for tag in tags: |
596 | for word in tag.split(' '): | 613 | for word in tag.split(' '): |
597 | q = q | Q(tags__name__unaccent__iexact=word ) | 614 | q = q | Q(tags__name__unaccent__iexact=word ) |
598 | - | 615 | + |
599 | subjects = Subject.objects.filter(q).distinct() | 616 | subjects = Subject.objects.filter(q).distinct() |
600 | - | 617 | + |
601 | self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(q).distinct() | 618 | self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(q).distinct() |
602 | self.resources = [resource.id for resource in self.resources if has_resource_permissions(self.request.user, resource)] | 619 | self.resources = [resource.id for resource in self.resources if has_resource_permissions(self.request.user, resource)] |
603 | self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(id__in = self.resources) | 620 | self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(id__in = self.resources) |
604 | - | 621 | + |
605 | self.totals = {'resources': self.resources.count(), 'my_subjects': subjects.count()} | 622 | self.totals = {'resources': self.resources.count(), 'my_subjects': subjects.count()} |
606 | - | 623 | + |
607 | option = self.kwargs.get('option') | 624 | option = self.kwargs.get('option') |
608 | if option and option == 'resources': | 625 | if option and option == 'resources': |
609 | return self.resources | 626 | return self.resources |
610 | return subjects | 627 | return subjects |
611 | - | 628 | + |
612 | def get_context_data(self, **kwargs): | 629 | def get_context_data(self, **kwargs): |
613 | context = super(SubjectSearchView, self).get_context_data(**kwargs) | 630 | context = super(SubjectSearchView, self).get_context_data(**kwargs) |
614 | - | 631 | + |
615 | if self.totals['resources'] == 0 and self.totals['my_subjects'] == 0: | 632 | if self.totals['resources'] == 0 and self.totals['my_subjects'] == 0: |
616 | context['empty'] = True | 633 | context['empty'] = True |
617 | context['tags'] = self.tags | 634 | context['tags'] = self.tags |
@@ -632,7 +649,7 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): | @@ -632,7 +649,7 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): | ||
632 | super(SubjectSearchView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 649 | super(SubjectSearchView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
633 | 650 | ||
634 | return context | 651 | return context |
635 | - | 652 | + |
636 | @log_decorator_ajax('subject', 'view', 'subject') | 653 | @log_decorator_ajax('subject', 'view', 'subject') |
637 | def subject_view_log(request, subject): | 654 | def subject_view_log(request, subject): |
638 | action = request.GET.get('action') | 655 | action = request.GET.get('action') |
@@ -670,15 +687,15 @@ def most_acessed_subjects(request): | @@ -670,15 +687,15 @@ def most_acessed_subjects(request): | ||
670 | subjects = {} | 687 | subjects = {} |
671 | for datum in data: | 688 | for datum in data: |
672 | if datum.context: | 689 | if datum.context: |
673 | - subject_id = datum.context['subject_id'] | 690 | + subject_id = datum.context['subject_id'] |
674 | if subject_id in subjects.keys(): | 691 | if subject_id in subjects.keys(): |
675 | subjects[subject_id]['count'] = subjects[subject_id]['count'] + 1 | 692 | subjects[subject_id]['count'] = subjects[subject_id]['count'] + 1 |
676 | else: | 693 | else: |
677 | subjects[subject_id] = {'name': datum.context['subject_name'], 'count':0 } | 694 | subjects[subject_id] = {'name': datum.context['subject_name'], 'count':0 } |
678 | 695 | ||
679 | - | 696 | + |
680 | #order the values of the dictionary by the count in descendent order | 697 | #order the values of the dictionary by the count in descendent order |
681 | - subjects = sorted(subjects.values(), key = lambda x: x['count'], reverse=True ) | 698 | + subjects = sorted(subjects.values(), key = lambda x: x['count'], reverse=True ) |
682 | subjects = subjects[:30] | 699 | subjects = subjects[:30] |
683 | 700 | ||
684 | return JsonResponse(subjects, safe=False) | 701 | return JsonResponse(subjects, safe=False) |