示例#1
0
def edit(filename):
    filename = system.get_safe_filename(filename)
    articleElements = system.get_article_elements(filename)
    
    return render_template('editor.html',
                           filename=filename, 
                           rawText=articleElements['rawText'],
                           isDraft=False)
示例#2
0
def save():
    if request.form.get('preview') == 'Preview':
        return render_template('preview.html', 
                           preview_html=markdown(request.form['text'], output_format="html5"),
                           rawText=request.form['text'],
                           filename=request.form['filename'])
                           
    if request.form['text'] == '':
        flash("articles must have body text", category='error')
        return redirect(url_for('electrostatic.index'))
        
    text = request.form['text']
        
    title = system.get_title_elements(text)[0]
    safe_title = re.sub('[^a-zA-Z0-9\s]', '', title).replace(' ', '_')
    date = time.strftime('%Y-%m-%d_%H-%M', time.gmtime())
    
    
    if request.form.get('draft') == 'on':
        if request.form['filename'] != '':
            filename = request.form['filename']
        else:
            filename = "%s.txt" % safe_title
        
        system.save_draft(filename, text)
            
    else:
        if request.form['wasDraft'] == 'yes':
            filename = "%s_%s" % (date, system.get_safe_filename(request.form['filename']))
        elif request.form['filename'] != '':
            filename = system.get_safe_filename(request.form['filename'])
            system.kill_item_in_cache(filename)
        else:
            filename = "%s_%s.txt" % (date, safe_title)
        
        system.save_article(filename, text)
        
    
        #TODO: This is not multi-user friendly!!
        author = "%s %s" % (session['user']['forename'], session['user']['surname'])
        system.create_article_from_template(text, title, filename[:-4], author)
            
    
    return redirect(url_for('electrostatic.index'))