How to use the summer.model.entry.Entry.save_draft function in summer

To help you get started, we’ve selected a few summer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaowhen / summer / summer / view / post / post.py View on Github external
def new():
    title = request.form['title']
    slug = slugify(title)
    content = request.form['content']
    date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    entry = Entry.save_draft(title, content, date, slug)

    filepath = os.path.join('./summer/_draft/', slug + '.md')
    newfile = open(filepath, 'w')

    meta = yaml.safe_dump({
        'title': title,
        'date': date,
        'tags': [''],
        'categories': ['']
    }, default_flow_style=False).replace('- ', '  - ')

    newfile.write(meta + '\n')
    newfile.write('---' + '\n\n')
    newfile.write(content.encode('utf8'))
    newfile.write('\n')
    newfile.close()