62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
# w.c.s. - web application for online forms
|
|
# Copyright (C) 2005-2010 Entr'ouvert
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import random
|
|
|
|
import qommon.sessions
|
|
from qommon.sessions import Session
|
|
|
|
class BasicSession(Session):
|
|
|
|
anonymous_key = None
|
|
magictokens = None
|
|
anonymous_formdata_keys = None
|
|
|
|
def has_info(self):
|
|
return self.anonymous_formdata_keys or self.anonymous_key or self.magictokens or Session.has_info(self)
|
|
is_dirty = has_info
|
|
|
|
def get_anonymous_key(self, generate = False):
|
|
if self.anonymous_key:
|
|
return self.anonymous_key
|
|
if generate:
|
|
self.anonymous_key = random.randint(0, 1000000000)
|
|
return self.anonymous_key
|
|
|
|
def add_magictoken(self, token, data):
|
|
if not self.magictokens:
|
|
self.magictokens = {}
|
|
self.magictokens[token] = data
|
|
|
|
def get_by_magictoken(self, token, default = None):
|
|
if not self.magictokens:
|
|
return default
|
|
return self.magictokens.get(token, default)
|
|
|
|
def mark_anonymous_formdata(self, formdata):
|
|
if not self.anonymous_formdata_keys:
|
|
self.anonymous_formdata_keys = {}
|
|
self.anonymous_formdata_keys['%s-%s' % (formdata.formdef.id, formdata.id)] = True
|
|
|
|
def is_anonymous_submitter(self, formdata):
|
|
if not self.anonymous_formdata_keys:
|
|
return False
|
|
formdata_key = '%s-%s' % (formdata.formdef.id, formdata.id)
|
|
return formdata_key in self.anonymous_formdata_keys
|
|
|
|
qommon.sessions.BasicSession = BasicSession
|
|
StorageSessionManager = qommon.sessions.StorageSessionManager
|