Пример #1
0
def admin_edit(name):
    try:
        Validator.check_name(name)
        p = Page(name)
        return template('admin_edit', page=p)
    except PageError, e:
        pass
Пример #2
0
def admin_new():
    if request.method == 'POST':
        name = request.forms.name.lower().strip()
        try:
            Validator.check_name(name)
            name = urllib.quote_plus(name)
            d = datetime.now()
            name = d.strftime('%Y-%m-%d-') + name
            p = Page(name)
            p.new(d)
            redirect('/admin/edit/%s' % name)
        except PageError, e:
            return template('admin_new', msg=str(e))
Пример #3
0
def login():
    if Validator.has_login(request):
        redirect('/')
    next = request.query.next or ''
    if request.method == 'POST':
        user = request.forms.username.strip()
        pwd  = request.forms.password.strip()
        if Validator.check_login(user, pwd):
            s = request.environ.get('beaker.session')
            s['user'] = hashlib.md5(user).hexdigest()
            url = next or '/admin'
            redirect(url)
    return template('login.html', next=next)
Пример #4
0
def admin_ajax(action):
    name = request.forms.name
    try:
        Validator.check_name(name)
        p = Page(name)
        if action == 'save':
            p.content = request.forms.content
            p.save()
        elif action == 'publish':
            p.publish()
        elif action == 'remove':
            delall = bool(request.forms.delall)
            p.remove(delall)
        else:
            raise PageError('No such action')
    except PageError, e:
        return {'status': 'fail', 'data': str(e)}