Commit 25286b08c518bf5a3c554a152f777c253a119d97
1 parent
f116c316
Exists in
master
and in
5 other branches
Implementando log
Showing
9 changed files
with
69 additions
and
84 deletions
Show diff stats
amadeus/settings.py
app/templates/home_app.html
... | ... | @@ -1,74 +0,0 @@ |
1 | -{% extends 'base.html' %} | |
2 | - | |
3 | -{% load i18n %} | |
4 | - | |
5 | -{% block breadcrumbs %} | |
6 | - <div class="row"> | |
7 | - <div class="col-md-12"> | |
8 | - <h4>{{ user }}</h4> | |
9 | - </div> | |
10 | - </div> | |
11 | - <div class="row"> | |
12 | - <div class="col-md-12"> | |
13 | - <ul class="breadcrumb" style="margin-bottom: 5px;"> | |
14 | - <li><a href="{% url 'core:index' %}">{% trans 'Home' %}</a></li> | |
15 | - <li><a href="{% url 'core:logout' %}">{% trans 'Logout' %}</a></li> | |
16 | - </ul> | |
17 | - </div> | |
18 | - </div> | |
19 | -{% endblock %} | |
20 | - | |
21 | -{% block sidebar %} | |
22 | - <div class="btn-group-vertical"> | |
23 | - <a href="javascript:void(0)" class="btn btn-raised">{% trans 'Pending tasks' %}</a> | |
24 | - <a href="javascript:void(0)" class="btn btn-raised" type="button" data-container="body" data-toggle="popover" data-placement="right" data-content="Gerson Rodriguez" >{% trans 'Users Online (1)' %}</a> | |
25 | - <a href="javascript:void(0)" class="btn btn-raised" button id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{% trans 'Course' %} <span class="caret"></span></a> | |
26 | - <ul class="dropdown-menu" aria-labelledby="dLabel"> | |
27 | - <a href="{% url 'course:create' %}" class="btn btn">{% trans 'Create Course' %}</a> | |
28 | - <a href="{% url 'course:manage' %}" class="btn btn">{% trans 'Manage Course' %}</a> | |
29 | - </ul> | |
30 | - </div> | |
31 | -{% endblock %} | |
32 | - | |
33 | -{% block content %} | |
34 | - <h4> | |
35 | - <strong> | |
36 | - <center>{% trans 'Courses' %}</center> | |
37 | - </strong> | |
38 | - </h4> | |
39 | - | |
40 | - {% if courses|length > 0 %} | |
41 | - {% for course in courses %} | |
42 | - <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-{{ course.slug }}-modal-sm">{{ course }}</button> | |
43 | - <div class="modal fade bs-{{ course.slug }}-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel"> | |
44 | - <div class="modal-dialog modal-sm" role="document"> | |
45 | - <div class="modal-content"> | |
46 | - <p> {{ course }}</p> | |
47 | - </div> | |
48 | - </div> | |
49 | - </div> | |
50 | - {% endfor %} | |
51 | - {% else %} | |
52 | - <p>{% trans "You didn't create any course yet." %}</p> | |
53 | - {% endif %} | |
54 | -{% endblock %} | |
55 | - | |
56 | -{% block rightbar %} | |
57 | - <div class="bs-callout bs-callout-info" id="callout-helper-context-color-specificity"> | |
58 | - <h4> | |
59 | - <strong> | |
60 | - <center>{% trans 'Goals' %}</center> | |
61 | - </strong> | |
62 | - </h4> | |
63 | - <table class="table"> | |
64 | - <tr> | |
65 | - <th scope="row"><input type="checkbox"/></th> | |
66 | - <td>70% de Presenca nas aulas</td> | |
67 | - </tr> | |
68 | - <tr> | |
69 | - <th scope="row"><input type="checkbox"/></th> | |
70 | - <td>30/11 - Entrega das notas finais</td> | |
71 | - </tr> | |
72 | - </table> | |
73 | - </div> | |
74 | -{% endblock rightbar %} |
app/templates/home_student.html
app/views.py
1 | 1 | from django.shortcuts import render |
2 | 2 | from django.views.generic import TemplateView |
3 | 3 | from django.contrib.auth.mixins import LoginRequiredMixin |
4 | +from django.utils.decorators import decorator_from_middleware_with_args | |
5 | +from django.utils.decorators import decorator_from_middleware | |
6 | +from django.utils.decorators import method_decorator | |
7 | +from core.mixins import LogMixin | |
4 | 8 | |
5 | 9 | from courses.models import Course |
6 | 10 | |
7 | -class AppIndex(LoginRequiredMixin, TemplateView): | |
11 | +class AppIndex(LoginRequiredMixin, LogMixin, TemplateView): | |
12 | + log_action = "Acessou home" | |
8 | 13 | template_name = "home_professor.html" |
9 | 14 | |
10 | 15 | def render_to_response(self, context, **response_kwargs): | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +import os | |
2 | +import datetime | |
3 | +from django.conf import settings | |
4 | +from functools import wraps | |
5 | + | |
6 | +def log_decorator(log_action = ''): | |
7 | + | |
8 | + def _log_decorator(view_function): | |
9 | + | |
10 | + def _decorator(request, *args, **kwargs): | |
11 | + | |
12 | + response = view_function(request, *args, **kwargs) | |
13 | + | |
14 | + if request.user.is_authenticated and request.POST: | |
15 | + date = datetime.datetime.now() | |
16 | + | |
17 | + message = date.strftime("%d/%m/%Y %H:%M:%S") + ' - ' + request.user.username + ' - ' + log_action + '\n' | |
18 | + | |
19 | + file_name = 'log_file_' + date.strftime("%d-%m-%Y") + '.txt' | |
20 | + | |
21 | + log_path = os.path.join(settings.LOGS_URL, file_name) | |
22 | + | |
23 | + log_file = open(log_path,'a+') | |
24 | + log_file.write(message) | |
25 | + log_file.close() | |
26 | + | |
27 | + return response | |
28 | + | |
29 | + return wraps(view_function)(_decorator) | |
30 | + | |
31 | + return _log_decorator | |
0 | 32 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +import os | |
2 | +import datetime | |
3 | +from django.conf import settings | |
4 | + | |
5 | +class LogMixin(object): | |
6 | + log_action = "" | |
7 | + | |
8 | + def dispatch(self, request, *args, **kwargs): | |
9 | + date = datetime.datetime.now() | |
10 | + | |
11 | + message = date.strftime("%d/%m/%Y %H:%M:%S") + ' - ' + request.user.username + ' - ' + self.log_action + '\n' | |
12 | + | |
13 | + file_name = 'log_file_' + date.strftime("%d-%m-%Y") + '.txt' | |
14 | + | |
15 | + log_path = os.path.join(settings.LOGS_URL, file_name) | |
16 | + | |
17 | + log_file = open(log_path,'a+') | |
18 | + log_file.write(message) | |
19 | + log_file.close() | |
20 | + | |
21 | + return super(LogMixin, self).dispatch(request, *args, **kwargs) | |
0 | 22 | \ No newline at end of file | ... | ... |
core/views.py
1 | - | |
2 | 1 | from django.shortcuts import render |
3 | 2 | from django.http import HttpResponse |
3 | + | |
4 | +from django.contrib.auth import authenticate, login as login_user | |
5 | +from django.shortcuts import redirect | |
6 | +from django.core.urlresolvers import reverse | |
7 | + | |
8 | +from .decorators import log_decorator | |
4 | 9 | # from django.contrib.auth.views import LoginView |
5 | 10 | |
6 | 11 | def index(request): |
... | ... | @@ -15,12 +20,7 @@ def create_account(request): |
15 | 20 | def remember_password(request): |
16 | 21 | return render(request, "remember_password.html") |
17 | 22 | |
18 | - | |
19 | - | |
20 | -from django.contrib.auth import authenticate, login as login_user | |
21 | -from django.shortcuts import redirect | |
22 | -from django.urls import reverse | |
23 | - | |
23 | +@log_decorator('Entrou no sistema') | |
24 | 24 | def login(request): |
25 | 25 | if request.POST: |
26 | 26 | username = request.POST['username'] | ... | ... |
db.sqlite3
No preview for this file type