A randomly generated device id that persists in local storage

This commit is contained in:
Kovid Goyal 2017-02-23 00:40:32 +05:30
parent d559ab9e01
commit 352a6d9238

View File

@ -1,9 +1,12 @@
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import hash_literals, bound_methods
from __python__ import bound_methods, hash_literals
from uuid import short_uuid
from ajax import ajax_send
defaults = {
# Book list settings
'view_mode': 'cover_grid',
@ -45,6 +48,7 @@ is_local_setting = {
'base_font_size': True,
}
def storage_available(which):
which = which or 'localStorage'
try:
@ -134,6 +138,18 @@ def local_storage():
local_storage.storage = SessionData('calibre-local-')
return local_storage.storage
def get_device_uuid():
if not get_device_uuid.ans:
s = local_storage()
ans = s.get('device_uuid')
if not ans:
ans = short_uuid()
s.set('device_uuid', ans)
get_device_uuid.ans = ans
return get_device_uuid.ans
default_interface_data = {
'username': None,
'output_format': 'EPUB',