diff --git a/log/middleware.py b/log/middleware.py index 7c942f6..92df8af 100644 --- a/log/middleware.py +++ b/log/middleware.py @@ -32,16 +32,17 @@ class TimeSpentMiddleware(object): request.session['log_id'] = None - 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 -- libgit2 0.21.2