示例#1
0
 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')
示例#2
0
    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)
示例#3
0
文件: tool.py 项目: feijilei/Eden
 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)
示例#4
0
    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)
示例#5
0
 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)
示例#6
0
    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)
示例#7
0
 def test_render_template(self):
     setup_template([self.path], module_cache_dir=self.cache)
     assert render_template('test.html', name='world') == u'Hello world'
示例#8
0
 def add_user_page(self):
     return render_template('user.add.html', statuses=USER_STATUSES, roles=ROLES)
示例#9
0
 def login_page(self):
     if cherrypy.request.user.uid != 0:
         raise cherrypy.HTTPRedirect('/task')
     return render_template('login.html')
示例#10
0
 def index(self):
     return render_template('index.html')
示例#11
0
 def _404_page(self, *args, **kw):
     return render_template('404.html')
示例#12
0
 def add_task_page(self):
     return render_template('task.add.html')
示例#13
0
 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)
示例#14
0
    def test_render_template(self):
        setup_template([self.path], 

            module_cache_dir=self.cache)
        assert render_template('test.html', name='world') == u'Hello world'