示例#1
0
文件: routes.py 项目: tyjsee/YouMd
def publish():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    name = request.POST.get("name", '').strip()
    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", '')  # '' or 'on'
    content = request.POST.get("content", '').strip()

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

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

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    path = 'raw/entry/%s-%s.md' % (m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()

    entryService.add_entry(True, path, True if private else False)
    return {'code': 0, 'msg': '发布成功'}
示例#2
0
文件: routes.py 项目: MaloneQQ/YouMd
def publish():
    name = request.POST.get("name",None)
    title = request.POST.get("title",None)
    cat = request.POST.get("cat",'')
    tag = request.POST.get("tag",'')
    private = request.POST.get("private",'')
    print '---------',private,type(private)

    content = request.POST.get("content",'').strip()
    
    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    '''%(title, cat, tag)
    import datetime
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    path = 'raw/entry/%s-%s.md'%(m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s'%(head,content) )
    m_file.close()
    if private:
        entryService.add_entry(False, path, True)
        entryService.update_urls()
        entryService.private_list.append(path)
        entryService.save_private()
    else:
        entryService.add_entry(True, path)
    return {'code': 0, 'msg': '发布成功'}
示例#3
0
def publish():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    name = request.POST.get("name", '').strip()
    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",'') # '' or 'on'
    content = request.POST.get("content",'').strip()
    
    if not (name and title):
        return {'code': -3, 'msg': '请填写完整'}
    
    tag = '__%s,%s'%(username, tag) if tag else '__'+username
    
    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    '''%(title, cat, tag)
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    path = 'raw/entry/%s-%s.md'%(m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s'%(head,content) )
    m_file.close()
    
    entryService.add_entry(True, path, True if private else False)
    return {'code': 0, 'msg': '发布成功'}
示例#4
0
def publish():
    name = request.POST.get("name", None)
    title = request.POST.get("title", None)
    cat = request.POST.get("cat", '')
    tag = request.POST.get("tag", '')
    private = request.POST.get("private", '')
    print '---------', private, type(private)

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

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)
    import datetime
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    path = 'raw/entry/%s-%s.md' % (m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()
    if private:
        entryService.add_entry(False, path, True)
        entryService.update_urls()
        entryService.private_list.append(path)
        entryService.save_private()
    else:
        entryService.add_entry(True, path)
    return {'code': 0, 'msg': '发布成功'}
示例#5
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': '更新成功'}
示例#6
0
def publish():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    name = request.POST.get("name", '').strip()
    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", '')  # '' or 'on'
    content = request.POST.get("content", '').strip()

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

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

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    file_name = '%s-%s.md' % (m_date, name)
    path = os.path.join(config.entry_dir,
                        file_name)  #'raw/entry/%s-%s.md' % (m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()
    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('Add %s' % file_name)

    entryService.add_entry(True, path, True if private else False)
    return {'code': 0, 'msg': '发布成功'}
示例#7
0
文件: routes.py 项目: MaloneQQ/YouMd
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
文件: routes.py 项目: tyjsee/YouMd
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': '更新成功'}