Browse Source

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

prieto 8 years ago
parent
commit
95fb85f3c9
3 changed files with 8 additions and 72 deletions
  1. 0
    66
      lodel/interface/web/run.py
  2. 7
    5
      run.py
  3. 1
    1
      templates/test.html

+ 0
- 66
lodel/interface/web/run.py View File

@@ -1,66 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-import os
3
-import datetime
4
-from werkzeug.contrib.sessions import FilesystemSessionStore
5
-
6
-from lodel.interface.web.router import get_controller
7
-from lodel.interface.web.lodelrequest import LodelRequest
8
-
9
-# TODO Déplacer ces trois paramètres dans les settings
10
-SESSION_FILES_TEMPLATE = 'lodel_%s.sess'
11
-SESSION_FILES_BASE_DIR = 'tmp/sessions'
12
-SESSION_EXPIRATION_LIMIT = 900 # 15 min
13
-
14
-session_store = FilesystemSessionStore(path=SESSION_FILES_BASE_DIR, filename_template=SESSION_FILES_TEMPLATE)
15
-
16
-# TODO Déplacer cette méthode dans un module Lodel/utils/datetime.py
17
-def get_utc_timestamp():
18
-    d = datetime.datetime.utcnow()
19
-    epoch = datetime.datetime(1970, 1, 1)
20
-    t = (d - epoch).total_seconds()
21
-    return t
22
-
23
-# TODO déplacer dans un module "sessions.py"
24
-def delete_old_session_files(timestamp_now):
25
-    session_files_path = os.path.abspath(session_store.path)
26
-    session_files = [file_object for file_object in os.listdir(session_files_path)
27
-                     if os.path.isfile(os.path.join(session_files_path, file_object))]
28
-    for session_file in session_files:
29
-        expiration_timestamp = os.statos.path.join(session_files_path, session_file)).st_mtime + \
30
-                                                                                      SESSION_EXPIRATION_LIMIT
31
-        if timestamp_now > expiration_timestamp:
32
-            os.unlink(os.path.join(session_files_path, session_file))
33
-
34
-
35
-# TODO Déplacer dans une module "sessions.py"
36
-def is_session_file_expired(timestamp_now, sid):
37
-    session_file = session_store.get_session_filename(sid)
38
-    expiration_timestamp = os.stat(session_file).st_mtime + SESSION_EXPIRATION_LIMIT
39
-    if timestamp_now < expiration_timestamp:
40
-        return False
41
-    return True
42
-
43
-# WSGI Application
44
-def application(env, start_response):
45
-    current_timestamp = get_utc_timestamp()
46
-    delete_old_session_files(current_timestamp)
47
-    request = LodelRequest(env)
48
-    sid = request.cookies.get('sid')
49
-    if sid is None or sid not in session_store.list():
50
-        request.session = session_store.new()
51
-        request.session['last_accessed'] = current_timestamp
52
-    else:
53
-        request.session = session_store.get(sid)
54
-        if is_session_file_expired(current_timestamp, sid):
55
-            session_store.delete(request.session)
56
-            request.session = session_store.new()
57
-            request.session['user_context'] = None
58
-        request.session['last_accessed'] = current_timestamp
59
-
60
-    controller = get_controller(request)
61
-    response = controller(request)
62
-    if request.session.should_save:
63
-        session_store.save(request.session)
64
-        response.set_cookie('sid', request.session.sid)
65
-
66
-    return response(env, start_response)

+ 7
- 5
run.py View File

@@ -13,19 +13,20 @@ SESSION_EXPIRATION_LIMIT = 900 # 15 min
13 13
 
14 14
 session_store = FilesystemSessionStore(path=SESSION_FILES_BASE_DIR, filename_template=SESSION_FILES_TEMPLATE)
15 15
 
16
+
16 17
 # TODO déplacer dans un module "sessions.py"
17 18
 def delete_old_session_files(timestamp_now):
18 19
     session_files_path = os.path.abspath(session_store.path)
19
-    session_files = [file_object for file_object in os.listdir(session_files_path)
20
+    session_files = [os.path.join(session_files_path, file_object) for file_object in os.listdir(session_files_path)
20 21
                      if os.path.isfile(os.path.join(session_files_path, file_object))]
22
+
21 23
     for session_file in session_files:
22
-        expiration_timestamp = os.path.join(session_files_path, session_file).st_mtime + \
23
-                                                                                      SESSION_EXPIRATION_LIMIT
24
+        last_modified = os.stat(session_file).st_mtime
25
+        expiration_timestamp = last_modified + SESSION_EXPIRATION_LIMIT
24 26
         if timestamp_now > expiration_timestamp:
25
-            os.unlink(os.path.join(session_files_path, session_file))
27
+            os.unlink(session_file)
26 28
 
27 29
 
28
-# TODO Déplacer dans une module "sessions.py"
29 30
 def is_session_file_expired(timestamp_now, sid):
30 31
     session_file = session_store.get_session_filename(sid)
31 32
     expiration_timestamp = os.stat(session_file).st_mtime + SESSION_EXPIRATION_LIMIT
@@ -33,6 +34,7 @@ def is_session_file_expired(timestamp_now, sid):
33 34
         return False
34 35
     return True
35 36
 
37
+
36 38
 # WSGI Application
37 39
 def application(env, start_response):
38 40
     current_timestamp = get_utc_timestamp()

+ 1
- 1
templates/test.html View File

@@ -1,7 +1,7 @@
1 1
 <html>
2 2
 <head></head>
3 3
 <body>
4
-    <form action="http://haroutiounian-devel.in.revues.org:9090/admin?r=1&rand[]=7&rand[]=5" method="POST" enctype="multipart/form-data">
4
+    <form action="http://localhost:9090/admin?r=1&rand[]=7&rand[]=5" method="POST" enctype="multipart/form-data">
5 5
         <input type="text" name="re[]" value="3"><br />
6 6
         <input type="text" name="re[]" value="1"><br />
7 7
         <input type="text" name="val" value="8"><br />

Loading…
Cancel
Save