not in
This commit is contained in:
parent
3e5c3c9a47
commit
abc0b82961
4 changed files with 48 additions and 47 deletions
|
@ -157,6 +157,7 @@ class UploadHandler(tornado.web.RequestHandler):
|
|||
self.set_status(403)
|
||||
self.write('')
|
||||
return
|
||||
|
||||
def save_files(context, request, callback):
|
||||
listname = request.arguments.get('list', None)
|
||||
if listname:
|
||||
|
@ -198,7 +199,7 @@ class UploadHandler(tornado.web.RequestHandler):
|
|||
callback(response)
|
||||
|
||||
response = yield tornado.gen.Task(save_files, self._context, self.request)
|
||||
if not 'status' in response:
|
||||
if 'status' not in response:
|
||||
response = json_response(response)
|
||||
response = json_dumps(response)
|
||||
self.set_header('Content-Type', 'application/json')
|
||||
|
|
|
@ -36,8 +36,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
user_items = sa.Table('useritem', db.metadata,
|
||||
sa.Column('user_id', sa.String(43), sa.ForeignKey('user.id')),
|
||||
sa.Column('item_id', sa.String(32), sa.ForeignKey('item.id'))
|
||||
)
|
||||
sa.Column('item_id', sa.String(32), sa.ForeignKey('item.id')))
|
||||
|
||||
class Item(db.Model):
|
||||
__tablename__ = 'item'
|
||||
|
@ -118,10 +117,10 @@ class Item(db.Model):
|
|||
|
||||
def add_user(self, user):
|
||||
from user.models import list_items
|
||||
if not user in self.users:
|
||||
if user not in self.users:
|
||||
self.users.append(user)
|
||||
l = user.library
|
||||
if not self in l.items:
|
||||
if self not in l.items:
|
||||
q = list_items.insert({'item_id': self.id, 'list_id': l.id})
|
||||
state.db.session.execute(q)
|
||||
|
||||
|
@ -140,7 +139,7 @@ class Item(db.Model):
|
|||
j['transferadded'] = t['added']
|
||||
j['transferprogress'] = t['progress']
|
||||
# unused and slow
|
||||
#j['users'] = list(map(str, list(self.users)))
|
||||
# j['users'] = list(map(str, list(self.users)))
|
||||
|
||||
if self.info:
|
||||
meta_keys = [k for k in self.meta_keys if k != 'pages']
|
||||
|
@ -206,7 +205,7 @@ class Item(db.Model):
|
|||
if value:
|
||||
value = str(value)
|
||||
value = ox.sort_string(value).lower()
|
||||
elif isinstance(value, list): #empty list
|
||||
elif isinstance(value, list): # empty list
|
||||
value = None
|
||||
if not value and sort_type != 'boolean':
|
||||
value = None
|
||||
|
@ -251,7 +250,8 @@ class Item(db.Model):
|
|||
value = self.json().get(key['id'], None)
|
||||
if key.get('filterMap') and value:
|
||||
value = re.compile(key.get('filterMap')).findall(value)
|
||||
if value: value = value[0]
|
||||
if value:
|
||||
value = value[0]
|
||||
if key.get('type') == 'boolean':
|
||||
value = True if value else False
|
||||
value = str(value).lower()
|
||||
|
@ -397,7 +397,7 @@ class Item(db.Model):
|
|||
# of fall back to first peer that has this item
|
||||
# in case its not available locally
|
||||
if not sync_from and self.info.get('mediastate') != 'available' and first_peer:
|
||||
#logger.debug('syncing from first peer that has item %s', first_peer)
|
||||
# logger.debug('syncing from first peer that has item %s', first_peer)
|
||||
sync_from = first_peer
|
||||
if sync_from:
|
||||
peer = utils.get_peer(sync_from)
|
||||
|
@ -436,7 +436,7 @@ class Item(db.Model):
|
|||
|
||||
def update_cover(self):
|
||||
logger.debug('%s update cover', self.id)
|
||||
key = 'cover:%s'%self.id
|
||||
key = 'cover:%s' % self.id
|
||||
cover = None
|
||||
if 'cover' in self.meta and self.meta['cover']:
|
||||
logger.debug('download cover %s %s', self.id, self.meta['cover'])
|
||||
|
@ -459,7 +459,7 @@ class Item(db.Model):
|
|||
logger.debug('%s update_cover done', self.id)
|
||||
|
||||
def get_preview(self):
|
||||
key = 'preview:%s'%self.id
|
||||
key = 'preview:%s' % self.id
|
||||
data = icons[key]
|
||||
if not data:
|
||||
preview = self.extract_preview()
|
||||
|
@ -468,12 +468,12 @@ class Item(db.Model):
|
|||
|
||||
def update_preview(self):
|
||||
logger.debug('%s update_preview', self.id)
|
||||
key = 'preview:%s'%self.id
|
||||
key = 'preview:%s' % self.id
|
||||
preview = self.extract_preview()
|
||||
if preview:
|
||||
icons[key] = preview
|
||||
self.info['previewRatio'] = get_ratio(preview)
|
||||
if not 'coverRatio' in self.info:
|
||||
if 'coverRatio' not in self.info:
|
||||
self.info['coverRatio'] = self.info['previewRatio']
|
||||
else:
|
||||
del icons[key]
|
||||
|
@ -505,7 +505,7 @@ class Item(db.Model):
|
|||
if key != 'pages':
|
||||
del self.info[key]
|
||||
|
||||
#FIXME get from user_meta
|
||||
# FIXME get from user_meta
|
||||
if state.online:
|
||||
if 'isbn' in self.meta:
|
||||
data = meta.lookup('isbn', self.meta['isbn'])
|
||||
|
@ -515,13 +515,13 @@ class Item(db.Model):
|
|||
|
||||
def queue_download(self):
|
||||
u = state.user()
|
||||
if not self.id in state.downloads.transfers:
|
||||
if self.id not in state.downloads.transfers:
|
||||
state.downloads.transfers[self.id] = {
|
||||
'added': datetime.utcnow(),
|
||||
'progress': 0
|
||||
}
|
||||
logger.debug('queue %s for download', self.id)
|
||||
if not u in self.users:
|
||||
if u not in self.users:
|
||||
self.add_user(u)
|
||||
|
||||
def save_file(self, content):
|
||||
|
@ -730,7 +730,7 @@ class File(db.Model):
|
|||
|
||||
def move(self):
|
||||
def format_underscores(string):
|
||||
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
|
||||
return re.sub(r'^\.|\.$|:|/|\?|<|>', '_', string)
|
||||
prefs = settings.preferences
|
||||
prefix = os.sep.join(os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/').split('/'))
|
||||
if not self.item:
|
||||
|
@ -833,7 +833,7 @@ def update_sort_table():
|
|||
sort_indexes = [i[len('ix_sort_'):] for i in layout['indexes'] if i.startswith('ix_sort_')]
|
||||
for col in set(Item.sort_keys)-set(sort_indexes):
|
||||
sql.append('CREATE INDEX ix_sort_{col} ON sort ({col})'.format(col=col))
|
||||
if not 'sortvalue' in db.get_table_columns('find'):
|
||||
if 'sortvalue' not in db.get_table_columns('find'):
|
||||
create_table = str(CreateTable(Find.__table__).compile(db.engine)).split('\n')
|
||||
col = 'sortvalue'
|
||||
add = [r for r in create_table if '\t%s ' % col in r][0].strip()[:-1]
|
||||
|
@ -848,7 +848,7 @@ def update_sort_table():
|
|||
def get_cover(id):
|
||||
delay = 60
|
||||
if state.online:
|
||||
#logger.debug('get_cover(%s)', id)
|
||||
# logger.debug('get_cover(%s)', id)
|
||||
with db.session():
|
||||
i = Item.get(id)
|
||||
if i:
|
||||
|
@ -859,7 +859,7 @@ def get_cover(id):
|
|||
|
||||
def get_preview(id):
|
||||
if state.online:
|
||||
#logger.debug('get_preview(%s)', id)
|
||||
# logger.debug('get_preview(%s)', id)
|
||||
with db.session():
|
||||
i = Item.get(id)
|
||||
if i:
|
||||
|
@ -869,7 +869,7 @@ def get_preview(id):
|
|||
time.sleep(0.5)
|
||||
|
||||
def sync_metadata(ids=None):
|
||||
#logger.debug('sync_metadata(%s)', len(ids) if len(ids) > 10 else ids)
|
||||
# logger.debug('sync_metadata(%s)', len(ids) if len(ids) > 10 else ids)
|
||||
step = 1000
|
||||
delay = 10
|
||||
with db.session():
|
||||
|
@ -893,5 +893,5 @@ def sync_metadata(ids=None):
|
|||
if later:
|
||||
if state.main and state.tasks:
|
||||
state.main.call_later(delay, lambda: state.tasks.queue('syncmetadata', later))
|
||||
#else:
|
||||
# else:
|
||||
# logger.debug('sync_metadata done')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# encoding: utf-8
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
DEBUG=False
|
||||
DEBUG = False
|
||||
try:
|
||||
from gi.repository import Gtk, GObject
|
||||
GObject.threads_init()
|
||||
|
@ -62,7 +62,8 @@ class GtkUI:
|
|||
class TkUI:
|
||||
def __init__(self):
|
||||
self.root = Tk()
|
||||
self.root.withdraw() #hiding tkinter window
|
||||
self.root.withdraw() # hiding tkinter window
|
||||
|
||||
def selectFolder(self, data):
|
||||
return tkinter.filedialog.askdirectory(title=data.get("title", "Select Folder"))
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ class User(db.Model):
|
|||
self.save()
|
||||
if not was_peering:
|
||||
Changelog.record(state.user(), 'addpeer', self.id, self.nickname)
|
||||
if not 'index' in self.info:
|
||||
if 'index' not in self.info:
|
||||
self.info['index'] = max([
|
||||
u.info.get('index', -1) for u in User.query.filter_by(peered=True)
|
||||
] + [0]) + 1
|
||||
|
@ -204,7 +204,7 @@ class User(db.Model):
|
|||
name = self.info.get('nickname') or self.info.get('username') or 'anonymous'
|
||||
nickname = name
|
||||
n = 2
|
||||
while self.query.filter_by(nickname=nickname).filter(User.id!=self.id).first():
|
||||
while self.query.filter_by(nickname=nickname).filter(User.id != self.id).first():
|
||||
nickname = '%s [%d]' % (name, n)
|
||||
n += 1
|
||||
self.nickname = nickname
|
||||
|
@ -238,8 +238,7 @@ class User(db.Model):
|
|||
|
||||
list_items = sa.Table('listitem', db.metadata,
|
||||
sa.Column('list_id', sa.Integer(), sa.ForeignKey('list.id')),
|
||||
sa.Column('item_id', sa.String(32), sa.ForeignKey('item.id'))
|
||||
)
|
||||
sa.Column('item_id', sa.String(32), sa.ForeignKey('item.id')))
|
||||
|
||||
class List(db.Model):
|
||||
__tablename__ = 'list'
|
||||
|
@ -305,13 +304,13 @@ class List(db.Model):
|
|||
|
||||
@classmethod
|
||||
def rename_user(cls, old, new):
|
||||
for l in cls.query.filter(cls._query!=None):
|
||||
for l in cls.query.filter(cls._query is not None):
|
||||
|
||||
def update_conditions(conditions):
|
||||
changed = False
|
||||
for c in conditions:
|
||||
if 'conditions' in c:
|
||||
changed = update_conditions(c['conditions'] )
|
||||
changed = update_conditions(c['conditions'])
|
||||
else:
|
||||
if c.get('key') == 'list' and c.get('value', '').startswith('%s:' % old):
|
||||
c['value'] = '%s:%s' % new, c['value'].split(':', 1)[1]
|
||||
|
|
Loading…
Reference in a new issue