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