示例#1
0
def index(error=None, page=None, success=None, url=None, template='index.jinja2'):
    # Max number of posts per page
    maxposts = POSTS_PER_PAGE
    # Is a specific posts page requested?
    if 'p' in request.args:
        page = int(request.args['p'])
    # Is a single page/post requested?
    if url:
        url = '/%s' % (url)
        pages, posts = mdcontent.get(url=url)
        for ctype in pages, posts:
            for content in ctype:
                if content['url'] == url:
                    single = content
    else: 
        pages, posts = mdcontent.get(page=page, maxposts=maxposts)
    # Calc how many pages of posts there are
    postpages = float(len(posts))/float(maxposts)
    postpages = int(math.ceil(postpages))
    # Build front page posts
    frontposts = []
    for post in posts[:maxposts]:
        frontposts.append(post)
    # Build archive posts
    oldpage = '/?p=1'
    newpage = None
    if page:
        archive = []
        for post in posts[maxposts:]:
            if 'content' in post:
                archive.append(post)
        oldpage = '/?p=%s' % (page+1)
        if page-1 > 1:
            newpage = '/?p=%s' % (page-1)
        else:
            newpage = '/'
    # If admin page, use admin template etc
    if request.url_rule.rule.startswith('/admin'):
        template = 'admin.jinja2'
        if 'page' in request.args:
            is_page = True
    # Is the user logged in?
    if 'logon' in session:
        admin = True
    # Title
    sitetitle = TITLE
    # Get plugins
    plugins = execute_plugins(pages, posts)
    return render_template('%s/%s' % (THEME, template), **locals())
示例#2
0
def updateitem():
    if not 'logon' in session:
        return redirect('/login/')
    valid = False
    for item in ['content', 'title', 'categories', 'filename', 'date']:
        if not item in request.form:
            error = '<strong>Error: </strong> Missing form data for: %s' % (item)
            return index(error=error)
    pages, posts = mdcontent.get()
    for ctype in pages, posts:
        for content in ctype:
            if content['filepath'] == request.form['filename']:
                valid = True
                break
        if valid:
            break
    if valid:
        categories = request.form['categories'].split(',')
        categories = ', '.join(categories)
        metadata = '---\ntitle: "%s"\ncategories: %s\ndate: %s\n---\n' % (request.form['title'], categories, request.form['date'])
        filedata = metadata + request.form['content']
        newpath = request.form['title'].replace(' ', '-').lower()
        newpath = newpath + '.markdown'
        if not 'is_page' in request.form:
            newpath = request.form['filename'][:17] + newpath
        else:
            newpath = 'pages/' + newpath
        with open(request.form['filename'], 'w') as f:
            f.write(filedata.encode('utf-8'))
        os.rename(request.form['filename'], newpath)
        return redirect(content['url'])
示例#3
0
def edititem(item):
    if not 'logon' in session:
        return redirect('/login/')
    url = '/%s' % (item)
    pages, posts = mdcontent.get(url=url)
    for ctype in pages, posts:
        for content in ctype:
            if content['url'] == url:
                single = content
    if not url.startswith('/blog/'):
        is_page = True
    template = 'admin.jinja2'
    sitetitle = TITLE
    return render_template('%s/%s' % (THEME, template), **locals())
示例#4
0
def deleteitem(url):
    if not 'logon' in session:
        return redirect('/')
    url = '/%s' % (url)
    pages, posts = mdcontent.get()
    valid = False
    for ctype in pages, posts:
        for content in ctype:
            if content['url'] == url:
                os.remove(content['filepath'])
                valid = True
                break
        if valid:
            break
    return redirect('/')
示例#5
0
def viewlogin():
    pages, posts = mdcontent.get()
    if 'logon' in session:
        admin = True
    sitetitle = TITLE
    return render_template('%s/login.jinja2' % (THEME), **locals())