Skip to content

Commit e41ba91

Browse files
committed
few fix + log
1 parent 4c49257 commit e41ba91

File tree

11 files changed

+139
-11
lines changed

11 files changed

+139
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# prod files
55
iTeam/settings_prod.py
66
gunicorn_start.sh
7+
deploy.sh
8+
git_version.txt
79

810
# dev files
911
*.pyc

iTeam/middleware.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# @Author: Adrien Chardon
4+
# @Date: 2014-10-28 19:29:36
5+
# @Last Modified by: Adrien Chardon
6+
# @Last Modified time: 2014-10-28 19:44:28
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 iTeam.stats.models import Log
26+
27+
28+
class Log_middleware(object):
29+
30+
def process_request(self, request):
31+
url = request.get_full_path()
32+
head = url.split('/')[1]
33+
34+
if head != 'admin':
35+
l = Log().set_attr(request)
36+
l.save()

iTeam/publications/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @Author: Adrien Chardon
44
# @Date: 2014-08-21 18:22:36
55
# @Last Modified by: Adrien Chardon
6-
# @Last Modified time: 2014-10-27 19:25:58
6+
# @Last Modified time: 2014-10-28 19:53:32
77

88
# This file is part of iTeam.org.
99
# Copyright (C) 2014 Adrien Chardon (Nodraak).
@@ -76,10 +76,7 @@ def detail(request, publication_id, publication_slug):
7676

7777
# Redirect if bad tutorial slug but item exists (Make sure the URL is well-formed)
7878
if publication_slug != slugify(publication.title):
79-
print 'bad slug = %s' % publication_slug
8079
return redirect(publication.get_absolute_url(), permanent=True)
81-
else:
82-
print 'slug ok : %s' % publication_slug
8380

8481
# default view, published article
8582
if not publication.is_draft:

iTeam/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @Author: Adrien Chardon
44
# @Date: 2014-09-02 12:01:06
55
# @Last Modified by: Adrien Chardon
6-
# @Last Modified time: 2014-10-28 11:33:49
6+
# @Last Modified time: 2014-10-28 19:46:39
77

88
# This file is part of iTeam.org.
99
# Copyright (C) 2014 Adrien Chardon (Nodraak).
@@ -141,6 +141,7 @@
141141
'iTeam.publications',
142142
'iTeam.medias',
143143
'iTeam.events',
144+
'iTeam.stats',
144145

145146
'django.contrib.admin',
146147
'django.contrib.auth',
@@ -159,6 +160,8 @@
159160
'django.contrib.auth.middleware.AuthenticationMiddleware',
160161
'django.contrib.messages.middleware.MessageMiddleware',
161162
'django.middleware.clickjacking.XFrameOptionsMiddleware',
163+
164+
'iTeam.middleware.Log_middleware',
162165
)
163166

164167
ROOT_URLCONF = 'iTeam.urls'

iTeam/stats/__init__.py

Whitespace-only changes.

iTeam/stats/admin.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# @Author: Adrien Chardon
4+
# @Date: 2014-10-28 19:45:49
5+
# @Last Modified by: Adrien Chardon
6+
# @Last Modified time: 2014-10-28 19:54:28
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.contrib import admin
26+
from iTeam.stats.models import Log
27+
28+
29+
class LogAdmin(admin.ModelAdmin):
30+
# fields for ALL publications
31+
list_display = ('ip', 'date', 'url', 'method', 'referer')
32+
33+
list_filter = ['ip', 'date', 'url', 'method', 'referer']
34+
search_fields = ['ip', 'date', 'url', 'method', 'referer']
35+
36+
37+
admin.site.register(Log, LogAdmin)

iTeam/stats/models.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

iTeam/stats/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

iTeam/stats/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

prod/deploy.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ sudo ln -s /etc/nginx/sites-available/iteam /etc/nginx/sites-enabled/iteam
5151
sudo service nginx reload
5252

5353
# Display current branch and commit
54-
DEPLOYED_HASH=$(git show-ref --tags | grep v1.0-RC1.1 | cut -d " " -f 1)
55-
DEPLOYED_TAG=$(git show-ref --tags | grep v1.0-RC1.1 | cut -d " " -f 2 | cut -d "/" -f 3)
54+
DEPLOYED_HASH=$(git show-ref --tags | grep $1 | cut -d " " -f 1)
55+
DEPLOYED_TAG=$(git show-ref --tags | grep $1 | cut -d " " -f 2 | cut -d "/" -f 3)
5656
HEAD_HASH=$(git rev-parse HEAD)
5757

5858
echo "$DEPLOYED_TAG" > git_version.txt
5959

6060
echo "Commit deployé :"
61-
echo "tag\t$DEPLOYED_TAG"
62-
echo "hash\t$DEPLOYED_HASH"
63-
echo "head\t$HEAD_HASH"
61+
echo "tag $DEPLOYED_TAG"
62+
echo "hash $DEPLOYED_HASH"
63+
echo "head $HEAD_HASH"

0 commit comments

Comments
 (0)