def login(self, username='', password=''): username = username.strip() password = password.strip() user = Backend('user').find_by_username(username) if user and user.check(password): set_secure_cookie('auth', str(user.uid)) raise cherrypy.HTTPRedirect('/task') return render_template('login.html')
def user_index(self, page=1): user = cherrypy.request.user if user.role != 'root': raise cherrypy.HTTPRedirect('/user/%d/edit' % (user.uid)) page = int(page) users = Backend('user').paginate(page, 10) return render_template('user.index.html', users=users)
def _decorator(*args, **kw): if request.user == _guest and request.path_info !='/login': raise HTTPRedirect('/login') user = request.user _role = user.role if user.is_banned() and (role and _role != 'root' and _role != role): raise render_template('403.html', role=role, banned=user.is_banned()) return f(*args, **kw)
def edit_task_page(self, name): task = Backend('task').find(name) if not task: raise cherrypy.HTTPError(404, 'nof found') if not task.data: task.data = '' else: task.data = json_encode(task.data) return render_template('task.edit.html', task=task, statuses=TASK_STATUSES)
def _decorator(*args, **kw): if request.user == _guest and request.path_info != '/login': raise HTTPRedirect('/login') user = request.user _role = user.role if user.is_banned() and (role and _role != 'root' and _role != role): raise render_template('403.html', role=role, banned=user.is_banned()) return f(*args, **kw)
def task_page(self, status='all', name='', page=1): # process page , keep it within range(1, 2000) try: page = int(page) except TypeError: page = 1 if page > 2000: page = 2000 _status = TASK_STATUSES.get(status, 0) name = name.strip() tasks = Backend('task').take(name, _status, page) count = Backend('task').count(name, _status) glue = '?page=' if not name else '?name=%s&page=' % (name) tasks = Paginator(tasks, count, page, 20, '/task/status/%s' % (status), glue) return render_template('task.index.html', name=name, status=status, statuses=TASK_STATUS_LIST, key_statuses=TASK_KEY_STATUSES, tasks=tasks)
def test_render_template(self): setup_template([self.path], module_cache_dir=self.cache) assert render_template('test.html', name='world') == u'Hello world'
def add_user_page(self): return render_template('user.add.html', statuses=USER_STATUSES, roles=ROLES)
def login_page(self): if cherrypy.request.user.uid != 0: raise cherrypy.HTTPRedirect('/task') return render_template('login.html')
def index(self): return render_template('index.html')
def _404_page(self, *args, **kw): return render_template('404.html')
def add_task_page(self): return render_template('task.add.html')
def edit_user_page(self, uid): uid = int(uid) user = Backend('user').find(uid) if not user: raise cherrypy.HTTPError(404, 'user not found') return render_template('user.edit.html', statuses=USER_STATUSES, roles=ROLES, user=user)