def package(id): try: data = toDict(PYLOAD.getPackageData(id)) data['links'] = [toDict(x) for x in data['links']] for pyfile in data['links']: if pyfile['status'] == 0: pyfile['icon'] = "status_finished.png" elif pyfile['status'] in (2, 3): pyfile['icon'] = "status_queue.png" elif pyfile['status'] in (9, 1): pyfile['icon'] = "status_offline.png" elif pyfile['status'] == 5: pyfile['icon'] = "status_waiting.png" elif pyfile['status'] == 8: pyfile['icon'] = "status_failed.png" elif pyfile['status'] == 4: pyfile['icon'] = "arrow_right.png" elif pyfile['status'] in (11, 13): pyfile['icon'] = "status_proc.png" else: pyfile['icon'] = "status_downloading.png" tmp = data['links'] tmp.sort(key=get_sort_key) data['links'] = tmp return data except Exception: traceback.print_exc() return bottle.HTTPError()
def admin(): # convert to dict user = dict((name, toDict(y)) for name, y in PYLOAD.getAllUserData().iteritems()) perms = permlist() for data in user.itervalues(): data['perms'] = {} get_permission(data['perms'], data['permission']) data['perms']['admin'] = data['role'] is 0 s = bottle.request.environ.get('beaker.session') if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST": for name in user: if bottle.request.POST.get("%s|admin" % name, False): user[name]['role'] = 0 user[name]['perms']['admin'] = True elif name != s['name']: user[name]['role'] = 1 user[name]['perms']['admin'] = False # set all perms to false for perm in perms: user[name]['perms'][perm] = False for perm in bottle.request.POST.getall("%s|perms" % name): user[name]['perms'][perm] = True user[name]['permission'] = set_permission(user[name]['perms']) PYLOAD.setUserPermission(name, user[name]['permission'], user[name]['role']) return render_to_response("admin.html", {"users": user, "permlist": perms}, [pre_processor])
def status(): try: status = toDict(PYLOAD.statusServer()) status['captcha'] = PYLOAD.isCaptchaWaiting() return status except Exception: return bottle.HTTPError()
def home(): try: res = [toDict(x) for x in PYLOAD.statusDownloads()] except Exception: s = bottle.request.environ.get('beaker.session') s.delete() return bottle.redirect("/login") for link in res: if link['status'] == 12: link['information'] = "%s kB @ %s kB/s" % (link['size'] - link['bleft'], link['speed']) return render_to_response("home.html", {"res": res}, [pre_processor])
def home(): try: res = [toDict(x) for x in PYLOAD.statusDownloads()] except Exception: s = bottle.request.environ.get('beaker.session') s.delete() return bottle.redirect("/login") for link in res: if link['status'] == 12: link['information'] = "%s kB @ %s kB/s" % ( link['size'] - link['bleft'], link['speed']) return render_to_response("home.html", {"res": res}, [pre_processor])
def links(): try: links = [toDict(x) for x in PYLOAD.statusDownloads()] ids = [] for link in links: ids.append(link['fid']) if link['status'] == 12: link['info'] = "%s @ %s/s" % (link['format_eta'], formatSize(link['speed'])) elif link['status'] == 5: link['percent'] = 0 link['size'] = 0 link['bleft'] = 0 link['info'] = _("waiting %s") % link['format_wait'] else: link['info'] = "" data = {'links': links, 'ids': ids} return data except Exception, e: traceback.print_exc() return bottle.HTTPError()
def admin(): # convert to dict user = dict( (name, toDict(y)) for name, y in PYLOAD.getAllUserData().iteritems()) perms = permlist() for data in user.itervalues(): data['perms'] = {} get_permission(data['perms'], data['permission']) data['perms']['admin'] = data['role'] is 0 s = bottle.request.environ.get('beaker.session') if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST": for name in user: if bottle.request.POST.get("%s|admin" % name, False): user[name]['role'] = 0 user[name]['perms']['admin'] = True elif name != s['name']: user[name]['role'] = 1 user[name]['perms']['admin'] = False # set all perms to false for perm in perms: user[name]['perms'][perm] = False for perm in bottle.request.POST.getall("%s|perms" % name): user[name]['perms'][perm] = True user[name]['permission'] = set_permission(user[name]['perms']) PYLOAD.setUserPermission(name, user[name]['permission'], user[name]['role']) return render_to_response("admin.html", { "users": user, "permlist": perms }, [pre_processor])
def default(self, o): if isinstance(o, BaseObject): return toDict(o) return json.JSONEncoder.default(self, o)