Пример #1
0
def UpdateSave():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    content = request.POST.get("content", '').strip()

    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(
        config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    if not entry:
        page_url = raw_url.replace(config.raw_url,
                                   '').replace(config.raw_suffix,
                                               config.url_suffix)
        entry = entryService.find_by_url(entryService.types.page,
                                         page_url).entry

    m_file = open(entry.path, 'w')
    m_file.write('%s\n%s' % (entry.header, content))
    m_file.close()
    file_name = entry.path.replace(config.entry_dir, '')
    if file_name.startswith('/'):
        file_name = file_name.replace('/', '', 1)
    if config.use_git:
        from git import Repo
        repo = Repo('./entry')
        #git_master = repo.heads.master
        git_index = repo.index
        git_index.add([file_name])
        git_index.commit('Update %s' % file_name)
    entryService.add_entry(False, entry.path, entry.private)
    return {'code': 0, 'msg': '更新成功'}
Пример #2
0
 def GET(self, url):
     if not url in ['', '/']:
         url = config.entry_url + url
         params = entryService.find_by_url(entryService.types.entry, url)
         if params.entry == None:
             raise web.notfound(render.error(params))
         else:
             return render.entry(params)
     params = entryService.search(entryService.types.index, url)
     return render.index(params)
Пример #3
0
 def GET(self, url):
     if not url in ['', '/']:
         url = config.entry_url + url
         params = entryService.find_by_url(entryService.types.entry, url)
         if params.entry == None:
             raise web.notfound(render.error(params))
         else:
             return render.entry(params)
     params = entryService.search(entryService.types.index, url)
     return render.index(params)
Пример #4
0
def Entry(url):
    if not url in ['', '/']:
        url = config.entry_url + url
        params = entryService.find_by_url(entryService.types.entry, url)
        if params.entry == None:
            return template('error', params=params, config=config)
        else:
            return template('entry', params=params, config=config)
    params = entryService.search(entryService.types.index, url)
    return template('index', params=params, config=config)
Пример #5
0
def Entry(url):
    if not url in ['', '/']:
        url = config.entry_url + url
        params = entryService.find_by_url(entryService.types.entry, url)
        if params.entry == None:
            return template('error', params=params, config=config)
        else:
            return template('entry', params=params, config=config)
    params = entryService.search(entryService.types.index, url)
    return template('index', params=params, config=config)
Пример #6
0
def UpdateSave():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    raw_url = request.POST.get("raw_url",'')
    content = request.POST.get("content",'').strip()
    
    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    if not entry:
        page_url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix, config.url_suffix)
        entry = entryService.find_by_url(entryService.types.page, page_url).entry
    
    m_file = open(entry.path, 'w')
    m_file.write('%s\n%s'%(entry.header,content) )
    m_file.close()
    entryService.add_entry(False, entry.path, entry.private)
    return {'code': 0, 'msg': '更新成功'}
Пример #7
0
def UpdateSave():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    content = request.POST.get("content", '').strip()

    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(
        config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    if not entry:
        page_url = raw_url.replace(config.raw_url,
                                   '').replace(config.raw_suffix,
                                               config.url_suffix)
        entry = entryService.find_by_url(entryService.types.page,
                                         page_url).entry

    m_file = open(entry.path, 'w')
    m_file.write('%s\n%s' % (entry.header, content))
    m_file.close()
    entryService.add_entry(False, entry.path, entry.private)
    return {'code': 0, 'msg': '更新成功'}
Пример #8
0
def DeletePost():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    raw_url = request.POST.get("raw_url",'')
    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    entryService.delete_entry(entry.path)
    os.remove(entry.path)
    
    if entry.private:
        entryService.del_private(entry.path)
    
    return {'code': 0, 'msg': '删除成功'}
Пример #9
0
def DeletePost():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(
        config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    entryService.delete_entry(entry.path)
    os.remove(entry.path)

    if entry.private:
        entryService.del_private(entry.path)

    return {'code': 0, 'msg': '删除成功'}
Пример #10
0
def SaveHead():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat", '').strip().replace(',', ',')
    tag = request.POST.get("tag", '').strip().replace(',', ',')
    private = request.POST.get("private", '')
    content = request.POST.get("content", '').strip()
    raw_url = request.POST.get("raw_url", '')

    if not title:
        return {'code': -3, 'msg': '请填写完整'}

    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix,
                                                      config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if not entry:
        return {'code': -4, 'msg': '对象不存在'}

    tag = '__%s,%s' % (username, tag) if tag else '__' + username

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)

    m_file = open(entry.path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()

    entryService.update_entry(
        entry, {
            'title': title,
            'tags': tag and tag.split(',') or [],
            'cats': cat and cat.split(',') or [],
            'private': bool(private)
        })
    return {'code': 0, 'msg': '修改成功'}
Пример #11
0
def SaveHead():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat",'').strip().replace(',', ',')
    tag = request.POST.get("tag",'').strip().replace(',', ',')
    private = request.POST.get("private",'')
    content = request.POST.get("content",'').strip()
    raw_url = request.POST.get("raw_url",'')
    
    if not title:
        return {'code': -3, 'msg': '请填写完整'}
    
    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix, config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if not entry:
        return {'code': -4, 'msg': '对象不存在'}
    
    tag = '__%s,%s'%(username, tag) if tag else '__'+username
    
    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    '''%(title, cat, tag)

    m_file = open(entry.path, 'w+')
    m_file.write('%s\n%s'%(head,content) )
    m_file.close()
    
    entryService.update_entry(entry, {
                                      'title': title,
                                      'tags': tag and tag.split(',') or [],
                                      'cats': cat and cat.split(',') or [],
                                      'private': bool(private)
                                      })
    return {'code': 0, 'msg': '修改成功'}
Пример #12
0
def GetHead():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    raw_url = request.POST.get("raw_url",'')
    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix, config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if entry:
        tags = [e for e in entry.tags if not e.startswith('__')]
        data = {
               'title': entry.name,
               'cat': entry.categories and ','.join(entry.categories) or '',
               'tag': tags and ','.join(tags) or '',
               'private': entry.private
               }
        ret = {'code': 0, 'msg': 'ok', 'data': data}
    else:
        ret = {'code': -1, 'msg': 'can not find'}
    return ret
Пример #13
0
def GetHead():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix,
                                                      config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if entry:
        tags = [e for e in entry.tags if not e.startswith('__')]
        data = {
            'title': entry.name,
            'cat': entry.categories and ','.join(entry.categories) or '',
            'tag': tags and ','.join(tags) or '',
            'private': entry.private
        }
        ret = {'code': 0, 'msg': 'ok', 'data': data}
    else:
        ret = {'code': -1, 'msg': 'can not find'}
    return ret
Пример #14
0
 def GET(self):
     url = config.about_url
     params = entryService.find_by_url(entryService.types.page, url)
     if params.entry == None:
         raise web.notfound(render.error(params))
     return render.entry(params)
Пример #15
0
 def GET(self):
     url = config.about_url
     params = entryService.find_by_url(entryService.types.page, url)
     if params.entry == None:
         raise web.notfound(render.error(params))
     return render.entry(params)
Пример #16
0
def About():
    url = config.about_url
    params = entryService.find_by_url(entryService.types.page, url)
    if params.entry == None:
        return template('error', params=params, config=config)
    return template('entry', params=params, config=config)
Пример #17
0
def About():
    url = config.about_url
    params = entryService.find_by_url(entryService.types.page, url)
    if params.entry == None:
        return template('error', params=params, config=config)
    return template('entry', params=params, config=config)