comparison farol/session.py @ 0:4a9f23230eba

Initial Release
author Benoît Allard <benoit.allard@greenbone.net>
date Wed, 24 Sep 2014 10:07:49 +0200
parents
children 4219d6fb4c38
comparison
equal deleted inserted replaced
-1:000000000000 0:4a9f23230eba
1 # -*- encoding: utf-8 -*-
2 # Description:
3 # Farol Session Management
4 #
5 # Authors:
6 # BenoƮt Allard <benoit.allard@greenbone.net>
7 #
8 # Copyright:
9 # Copyright (C) 2014 Greenbone Networks GmbH
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
15 #
16 # This program 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 General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 """\
26 Stuff related to temporary storage
27 """
28
29 from functools import wraps
30 import uuid
31
32 from flask import session, flash, redirect, url_for
33
34 CVRFs = {}
35
36 def set_current(cvrf):
37 session['id'] = uuid.uuid4()
38 CVRFs[session['id']] = cvrf
39
40 def get_current():
41 if not has_current(): return None
42 return CVRFs[session['id']]
43
44 def has_current():
45 if 'id' not in session:
46 return False
47 if session['id'] not in CVRFs:
48 return False
49 return CVRFs[session['id']] is not None
50
51 def del_current():
52 if 'id' in session:
53 if session['id'] in CVRFs:
54 del CVRFs[session['id']]
55 del session['id']
56
57
58 def document_required(f):
59 @wraps(f)
60 def decorated_function(*args, **kwargs):
61 if not has_current():
62 flash('Operation invalid without document', 'warning')
63 return redirect(url_for('new'))
64 return f(*args, **kwargs)
65 return decorated_function

http://farol.wald.intevation.org