Example #1
0
def logout():
    s = request.environ.get('beaker.session')
    s.delete()

    bf = baseinfo()
    dd = dict(title='Home', info=bf)
    return dd
Example #2
0
def code(id=1):
    p = Program[id]
    programs = select(m for m in Program)
    bf = baseinfo()
    dd = dict(title='Code Detail', info=bf, programs=programs, program=p)

    return template('source', dd)
Example #3
0
def add():
    bf = baseinfo()
    if bf.auth:
        dd = dict(title='Add program', info=bf)
        return dd
    else:
        return redirect('/program')
Example #4
0
def add():
    bf = baseinfo()
    if bf.auth:
        dd = dict(title='Add news', info=bf)
        return dd
    else:
        return redirect('/blog')
Example #5
0
def upload():
    page = request.query.page or '1'
    data = request.files.data  # 获取上传的文件

    if not data:
        return "select file please!"

    bf = baseinfo()
    if not bf.auth:
        return "Not allowed!"

    upurl = '/store/'
    uploadpath = './store/'  # 定义上传文件的保存路径
    data.save(uploadpath, overwrite=True)  # overwrite参数是指覆盖同名文件
    fname = data.filename.strip()
    ext = splitext(fname)[1]

    raw = data.file.read()
    size = str(int(len(raw) / 1024)) + 'kb'

    Photo(name=fname,
          ext=ext,
          url=upurl + fname,
          size=size,
          update=today,
          author=User[bf.id])
    commit()
    url = '/photo?page=' + page
    return redirect(url)
Example #6
0
def contact():
    """Renders the contact page."""
    nicks = select(u.nick for u in User)
    bf = baseinfo()

    dd = dict(title='member', info=bf, nicks=nicks)

    return template('member', dd)
Example #7
0
def edit(id):
    bf = baseinfo()
    if bf.auth:
        b = Blog[id]
        dd = dict(title='Edit', info=bf, blog=b)
        return template('edit', dd)
    else:
        return redirect("/blog/%s" %
                        id)  # id is string , must be %s ,not be %d
Example #8
0
def delphoto(id):
    page = request.query.page or '1'
    bf = baseinfo()
    if not bf.auth:
        return "Not allowed!"

    if id:
        p = Photo[id]
        p.delete()

        commit()
        url = '/photo?page=' + page
        return redirect(url)
    else:
        return "nothing"
Example #9
0
def write():
    bf = baseinfo()
    if bf.auth:
        title = request.forms.title
        pcode = request.forms.code
        if title.strip() and pcode.strip():
            pcode = html.unescape(pcode)
            p = Program(title=title, code=pcode, update=today, level='0')
            commit()
            # must commit,otherwise not add anything
            #必须要提交,否则添加不了内容

            return redirect("/program/%d" % p.id)
    else:
        return redirect('/program')
Example #10
0
def add():
    bf = baseinfo()
    if bf.auth:
        title = request.forms.title
        content = request.forms.content
        if title.strip() and content.strip():
            content = html.unescape(content)
            b = Blog(title=title, content=content, update=today, author=bf.id)
            commit()
            # must commit,otherwise not add anything
            #必须要提交,否则添加不了内容

            return redirect("/blog/%d" % b.id)
    else:
        return redirect('/blog')
Example #11
0
def login():
    username = request.forms.username
    password = request.forms.password

    if username.strip() and password.strip():
        u = check_login(username, password)
        if u:
            s = request.environ.get('beaker.session')
            s['nick'] = u.nick
            s['id'] = u.id
            s['auth'] = True
            s.save()
            return redirect('/')

    bf = baseinfo()
    dd = dict(title='Home', info=bf)
    return dd
Example #12
0
def program():
    page = request.query.page or '1'
    plimit = 5
    programs = select(p for p in Program)
    programscount = programs.count()
    pnum = int(programscount / plimit)
    if programscount > pnum * plimit:
        pnum = pnum + 1

    programs = programs.page(int(page), plimit)

    bf = baseinfo()
    dd = dict(title='Program',
              info=bf,
              programs=programs,
              pagecount=pnum,
              cpage=int(page))

    return template('program', dd)
Example #13
0
def blog():
    page = request.query.page or '1'
    plimit = 5
    blogs = select(b for b in Blog)
    blogscount = blogs.count()
    pnum = int(blogscount / plimit)
    if blogscount > pnum * plimit:
        pnum = pnum + 1

    blogs = blogs.page(int(page), plimit)

    bf = baseinfo()
    dd = dict(title='Blog',
              info=bf,
              blogs=blogs,
              pagecount=pnum,
              cpage=int(page))

    return template('blog', dd)
Example #14
0
def photo():
    page = request.query.page or '1'
    plimit = 6
    photos = select(p for p in Photo)
    photoscount = photos.count()
    pnum = int(photoscount / plimit)
    if photoscount > pnum * plimit:
        pnum = pnum + 1

    photos = photos.page(int(page), plimit)

    bf = baseinfo()
    dd = dict(title='Photo',
              info=bf,
              photos=photos,
              pagecount=pnum,
              cpage=int(page),
              thispage=page,
              author=bf.auth)
    return template('picture', dd)
Example #15
0
def add():
    bf = baseinfo()
    if bf.auth:
        title = request.forms.title
        describe = request.forms.content
        if title.strip() and describe.strip():
            describe = html.unescape(describe)
            b = Problem(title=title,
                        describe=describe,
                        ratio='',
                        level=0,
                        update=today,
                        author=bf.id)
            commit()
            # must commit,otherwise not add anything
            #必须要提交,否则添加不了内容

            return redirect("/problem/%d" % b.id)
    else:
        return redirect('/problem')
Example #16
0
def detail(id):
    b = Problem[id]
    bf = baseinfo()
    dd = dict(title='Detail', info=bf, problem=b)

    return template('detail', dd)
Example #17
0
def detail(id):
    b = Blog[id]
    bf = baseinfo()
    dd = dict(title='Detail', info=bf, blog=b)

    return template('detail', dd)
Example #18
0
def login():
    bf = baseinfo()
    dd = dict(title='login', info=bf)
    return dd
Example #19
0
def home():
    """Renders the home page."""
    bf = baseinfo()
    dd = dict(title='Home', info=bf)
    return dd
Example #20
0
def about():
    """Renders the about page."""
    bf = baseinfo()
    dd = dict(title='about', info=bf)
    return dd
Example #21
0
def register():
    bf = baseinfo()
    dd = dict(title='register', info=bf)
    return dd