From 4d316ef2bbf1a184fbb66ad260db2d6d56fdef5e Mon Sep 17 00:00:00 2001 From: Zambom Date: Wed, 25 Jan 2017 17:58:55 -0200 Subject: [PATCH] Adding subject log --- log/middleware.py | 43 ++++++++++++++++++++++--------------------- subjects/templates/subjects/subject_card.html | 3 +++ subjects/urls.py | 1 + subjects/views.py | 1078 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 4 files changed, 616 insertions(+), 509 deletions(-) diff --git a/log/middleware.py b/log/middleware.py index 92df8af..66cbfb3 100644 --- a/log/middleware.py +++ b/log/middleware.py @@ -14,35 +14,36 @@ class TimeSpentMiddleware(object): if not 'admin' in app_names: if not request.is_ajax(): - log_id = request.session.get('log_id', None) + if not request.path.startswith('/uploads/'): + log_id = request.session.get('log_id', None) - if not log_id is None: - log = get_object_or_404(Log, id = log_id) + if not log_id is None: + log = get_object_or_404(Log, id = log_id) - if type(log.context) == dict: - log_context = log.context - else: - log_context = json.loads(log.context) + if type(log.context) == dict: + log_context = log.context + else: + log_context = json.loads(log.context) - log_context['timestamp_end'] = str(int(time.time())) + log_context['timestamp_end'] = str(int(time.time())) - log.context = log_context + log.context = log_context - log.save() + log.save() - request.session['log_id'] = None + request.session['log_id'] = None - if request.user.is_authenticated: - oppened_logs = Log.objects.filter(user = request.user, context__contains={'timestamp_end': '-1'}) + if request.user.is_authenticated: + oppened_logs = Log.objects.filter(user = request.user, context__contains={'timestamp_end': '-1'}) - for op_log in oppened_logs: - if type(op_log.context) == dict: - log_context = op_log.context - else: - log_context = json.loads(op_log.context) + for op_log in oppened_logs: + if type(op_log.context) == dict: + log_context = op_log.context + else: + log_context = json.loads(op_log.context) - log_context['timestamp_end'] = str(int(time.time())) + log_context['timestamp_end'] = str(int(time.time())) - op_log.context = log_context + op_log.context = log_context - op_log.save() \ No newline at end of file + op_log.save() \ No newline at end of file diff --git a/subjects/templates/subjects/subject_card.html b/subjects/templates/subjects/subject_card.html index d82229b..f0b55df 100644 --- a/subjects/templates/subjects/subject_card.html +++ b/subjects/templates/subjects/subject_card.html @@ -42,6 +42,9 @@
+ + +
{% if subject.professor.all|length > 0 %} diff --git a/subjects/urls.py b/subjects/urls.py index ae7c6b8..50eb599 100644 --- a/subjects/urls.py +++ b/subjects/urls.py @@ -15,5 +15,6 @@ urlpatterns = [ url(r'^search/$', views.SubjectSearchView.as_view(), name='search'), url(r'^search/(?P