Commit 8f010a7c269a6058f98321dfb9b1929ce43eae7c
Exists in
master
and in
3 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
8 changed files
with
72 additions
and
16 deletions
Show diff stats
amadeus/settings.py
... | ... | @@ -71,7 +71,7 @@ MIDDLEWARE_CLASSES = [ |
71 | 71 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
72 | 72 | 'django.middleware.locale.LocaleMiddleware', |
73 | 73 | |
74 | - #'core.middleware.TimeSpentMiddleware', | |
74 | + 'log.middleware.TimeSpentMiddleware', | |
75 | 75 | #libs-middleware |
76 | 76 | |
77 | 77 | ] | ... | ... |
amadeus/static/js/course.js
... | ... | @@ -111,6 +111,21 @@ $('.collapse').on('show.bs.collapse', function (e) { |
111 | 111 | var btn = $(this).parent().find('.fa-angle-right'); |
112 | 112 | |
113 | 113 | btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); |
114 | + | |
115 | + var url = $(this).parent().find('.log_url').val(); | |
116 | + var log_input = $(this).parent().find('.log_id'); | |
117 | + | |
118 | + $.ajax({ | |
119 | + url: url, | |
120 | + data: {'action': 'open'}, | |
121 | + dataType: 'json', | |
122 | + success: function (data) { | |
123 | + log_input.val(data.log_id); | |
124 | + }, | |
125 | + error: function (data) { | |
126 | + console.log(data); | |
127 | + } | |
128 | + }); | |
114 | 129 | } |
115 | 130 | }); |
116 | 131 | |
... | ... | @@ -119,5 +134,20 @@ $('.collapse').on('hide.bs.collapse', function (e) { |
119 | 134 | var btn = $(this).parent().find('.fa-angle-down'); |
120 | 135 | |
121 | 136 | btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); |
137 | + | |
138 | + var url = $(this).parent().find('.log_url').val(); | |
139 | + var log_id = $(this).parent().find('.log_id').val(); | |
140 | + | |
141 | + $.ajax({ | |
142 | + url: url, | |
143 | + data: {'action': 'close', 'log_id': log_id}, | |
144 | + dataType: 'json', | |
145 | + success: function (data) { | |
146 | + console.log(data.message); | |
147 | + }, | |
148 | + error: function (data) { | |
149 | + console.log(data); | |
150 | + } | |
151 | + }); | |
122 | 152 | } |
123 | 153 | }); |
124 | 154 | \ No newline at end of file | ... | ... |
categories/templates/categories/create.html
... | ... | @@ -14,18 +14,17 @@ |
14 | 14 | {% csrf_token %} |
15 | 15 | {% for field in form %} |
16 | 16 | <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> |
17 | - {% if field.auto_id != 'id_public' %} | |
17 | + {% if field.auto_id != 'id_visible' %} | |
18 | 18 | <label for="{{ field.auto_id }}">{{ field.label }}</label> |
19 | 19 | {% endif %} |
20 | 20 | {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} |
21 | 21 | <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> |
22 | - {% elif field.auto_id == 'id_public' %} | |
22 | + {% elif field.auto_id == 'id_visible' %} | |
23 | 23 | <div class="checkbox"> |
24 | - <label> | |
25 | - <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | |
26 | - </label> | |
24 | + <label for="{{ field.auto_id }}"> | |
25 | + {% render_field field %} {{field.label}} | |
26 | + </label> | |
27 | 27 | </div> |
28 | - | |
29 | 28 | {% elif field.auto_id == 'id_description' %} |
30 | 29 | {% render_field field class='form-control text_wysiwyg' %} |
31 | 30 | ... | ... |
categories/templates/categories/list.html
... | ... | @@ -32,8 +32,7 @@ |
32 | 32 | <li>{% trans "all subjects" %}</li> |
33 | 33 | </ul> |
34 | 34 | </div> |
35 | - {% endif %} | |
36 | - | |
35 | + {% endif %} | |
37 | 36 | |
38 | 37 | <!-- Code for listing categories --> |
39 | 38 | <div class="col-md-12 cards-content"> |
... | ... | @@ -79,6 +78,9 @@ |
79 | 78 | </div> |
80 | 79 | </div> |
81 | 80 | <div id="{{category.slug}}" class="panel-collapse collapse category-panel-content"> |
81 | + <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> | |
82 | + <input type="hidden" class="log_id" value="" /> | |
83 | + | |
82 | 84 | <h4> {% trans "Coordinator(s): " %} |
83 | 85 | {% for coordinator in category.coordinators.all %} |
84 | 86 | {{coordinator.username}} | ... | ... |
categories/templates/categories/update.html
... | ... | @@ -16,16 +16,16 @@ |
16 | 16 | {% csrf_token %} |
17 | 17 | {% for field in form %} |
18 | 18 | <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> |
19 | - {% if field.auto_id != 'id_public' %} | |
19 | + {% if field.auto_id != 'id_visible' %} | |
20 | 20 | <label for="{{ field.auto_id }}">{{ field.label }}</label> |
21 | 21 | {% endif %} |
22 | 22 | {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} |
23 | 23 | <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> |
24 | - {% elif field.auto_id == 'id_public' %} | |
24 | + {% elif field.auto_id == 'id_visible' %} | |
25 | 25 | <div class="checkbox"> |
26 | - <label> | |
27 | - <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | |
28 | - </label> | |
26 | + <label for="{{ field.auto_id }}"> | |
27 | + {% render_field field %} {{field.label}} | |
28 | + </label> | |
29 | 29 | </div> |
30 | 30 | {% elif field.auto_id == 'id_description' %} |
31 | 31 | {% render_field field class='form-control text_wysiwyg' %} | ... | ... |
categories/urls.py
... | ... | @@ -7,4 +7,5 @@ urlpatterns = [ |
7 | 7 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCategory.as_view(), name='delete'), |
8 | 8 | url(r'^replicate/(?P<slug>[\w_-]+)/$', views.CreateCategory.as_view(), name='replicate'), |
9 | 9 | url(r'^update/(?P<slug>[\w_-]+)/$', views.UpdateCategory.as_view(), name='update'), |
10 | + url(r'^view_log/(?P<category>[\w_-]+)/$', views.category_view_log, name = 'view_log') | |
10 | 11 | ] |
11 | 12 | \ No newline at end of file | ... | ... |
categories/views.py
... | ... | @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse_lazy |
5 | 5 | from rolepermissions.verifications import has_role |
6 | 6 | |
7 | 7 | from django.contrib import messages |
8 | -from django.http import HttpResponse | |
8 | +from django.http import HttpResponse, JsonResponse | |
9 | 9 | from django.utils.translation import ugettext_lazy as _ |
10 | 10 | |
11 | 11 | from django.contrib.auth.mixins import LoginRequiredMixin |
... | ... | @@ -17,6 +17,10 @@ from braces import views |
17 | 17 | from subjects.models import Subject |
18 | 18 | |
19 | 19 | from log.mixins import LogMixin |
20 | +from log.decorators import log_decorator_ajax | |
21 | +from log.models import Log | |
22 | + | |
23 | +import time | |
20 | 24 | |
21 | 25 | from users.models import User |
22 | 26 | |
... | ... | @@ -121,7 +125,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat |
121 | 125 | |
122 | 126 | super(CreateCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
123 | 127 | |
124 | - #TODO: Implement log calls | |
125 | 128 | return super(CreateCategory, self).form_valid(form) |
126 | 129 | |
127 | 130 | def get_success_url(self): |
... | ... | @@ -190,4 +193,24 @@ class UpdateCategory(LogMixin, UpdateView): |
190 | 193 | messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) |
191 | 194 | return reverse_lazy('categories:index') |
192 | 195 | |
196 | +@log_decorator_ajax('category', 'view', 'category') | |
197 | +def category_view_log(request, category): | |
198 | + action = request.GET.get('action') | |
199 | + | |
200 | + if action == 'open': | |
201 | + category = get_object_or_404(Category, id = category) | |
202 | + | |
203 | + log_context = {} | |
204 | + log_context['category_id'] = category.id | |
205 | + log_context['category_name'] = category.name | |
206 | + log_context['category_slug'] = category.slug | |
207 | + log_context['timestamp_start'] = str(int(time.time())) | |
208 | + log_context['timestamp_end'] = '-1' | |
209 | + | |
210 | + request.log_context = log_context | |
211 | + | |
212 | + log_id = Log.objects.latest('id').id | |
213 | + | |
214 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
193 | 215 | |
216 | + return JsonResponse({'message': 'ok'}) | ... | ... |
log/middleware.py
... | ... | @@ -32,6 +32,7 @@ class TimeSpentMiddleware(object): |
32 | 32 | |
33 | 33 | request.session['log_id'] = None |
34 | 34 | |
35 | + if request.user.is_authenticated: | |
35 | 36 | oppened_logs = Log.objects.filter(user = request.user, context__contains={'timestamp_end': '-1'}) |
36 | 37 | |
37 | 38 | for op_log in oppened_logs: | ... | ... |