|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# @Author: Adrien Chardon |
| 4 | +# @Date: 2014-10-28 19:07:27 |
| 5 | +# @Last Modified by: Adrien Chardon |
| 6 | +# @Last Modified time: 2014-10-28 19:53:46 |
| 7 | + |
| 8 | +# This file is part of iTeam.org. |
| 9 | +# Copyright (C) 2014 Adrien Chardon (Nodraak). |
| 10 | +# |
| 11 | +# iTeam.org is free software: you can redistribute it and/or modify |
| 12 | +# it under the terms of the GNU Affero General Public License as published by |
| 13 | +# the Free Software Foundation, either version 3 of the License, or |
| 14 | +# (at your option) any later version. |
| 15 | +# |
| 16 | +# iTeam.org is distributed in the hope that it will be useful, |
| 17 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | +# GNU Affero General Public License for more details. |
| 20 | +# |
| 21 | +# You should have received a copy of the GNU Affero General Public License |
| 22 | +# along with iTeam.org. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + |
| 24 | + |
| 25 | +from django.db import models |
| 26 | +from django.utils import timezone |
| 27 | + |
| 28 | + |
| 29 | +class Log(models.Model): |
| 30 | + ip = models.CharField(max_length=256) |
| 31 | + date = models.DateTimeField() |
| 32 | + url = models.CharField(max_length=256) |
| 33 | + method = models.CharField(max_length=256) |
| 34 | + referer = models.CharField(max_length=256) |
| 35 | + |
| 36 | + def set_attr(self, request): |
| 37 | + self.ip = request.META['REMOTE_ADDR'] |
| 38 | + self.date = timezone.now() |
| 39 | + self.url = request.get_full_path() |
| 40 | + self.method = request.META['REQUEST_METHOD'] |
| 41 | + |
| 42 | + if 'HTTP_REFERER' in request.META: |
| 43 | + self.referer = request.META['HTTP_REFERER'] |
| 44 | + else: |
| 45 | + self.referer = '-' |
| 46 | + |
| 47 | + return self |
0 commit comments