Example #1
0
def edit_text_ajax(slugid, year=None, month=None, day=None, slug=None):
    meta = Meta()
    try:
        text_post = TextPost.objects(slugid=slugid).get()
    except:
        return abort(404)
    if (slug == None or year == None or month == None or day == None):
        return redirect(url_for('edit_text_ajax', slugid=slugid,\
            slug=text_post.slug, year=text_post.created.year,\
            month=text_post.created.month, day=text_post.created.day))
    return render_template("add_text_post.html", meta=meta,\
            text_post=text_post)
Example #2
0
def add_text__content(slugid):
    """Ajax event & markdown for content"""
    try:
        text_post = TextPost.objects(slugid=slugid).get()
    except:
        return abort(404)
    if request.method == "PUT" or request.method == 'POST':
        content = request.values.get('content')
        text_post.content = content
        text_post.html_content = markdown(content, extensions)
        text_post.updated.append(datetime.datetime.now())
        text_post.save()
        return text_post.html_content
    elif request.method == "GET":
        try:
            return text_post.content
        except:
            return abort(500)
Example #3
0
def add_text__title(slugid):
    """Ajax event to title"""
    try:
        text_post = TextPost.objects(slugid=slugid).first()
    except:
        return abort(404)
    if request.method == "PUT" or request.method == "POST":
        title = request.values.get('title', type=unicode)
        text_post.title = title
        if text_post.updated:
            text_post.updated.append(datetime.datetime.now())
        else:
            text_post.updated = [datetime.datetime.now()]
        text_post.slug = slugfy(unicode(title))
        text_post.save()
        return text_post.title
    elif request.method == "GET":
        return text_post.title
Example #4
0
def post_by_slug(slug):
    meta = Meta()
    text_post = TextPost.objects(slug=slug).first()
    text_post["created"] = datetime.datetime.strftime(text_post.created, "%Y-%m-%d @ %H:%M")
    return render_template("text_post.html", meta=meta, text_post=text_post)
Example #5
0
def single_text_post(year, month, day, slugid, slug=None):
    meta = Meta()
    text_post = TextPost.objects(slugid=slugid).get()
    return dict(meta=meta, text_post=text_post)
Example #6
0
def add_text_post():
    meta = Meta()
    form = TextPostForm(request.form)
    if form.validate_on_submit():
        username = escape(session['username'])
        text_post = TextPost(slug=slugfy(form.title.data))
        text_post.is_published = form.is_published.data
        try:
            text_post.author = User.objects(username=username).get()
        except:
            flash("user not found")
            return redirect(url_for('add_text_post', meta=meta, form=form))
        # Media ripping method
        def rip_media(mediastr):
            try:
                assert len(mediastr) % 8 == 0
            except:
                flash("could not save media %s " % escape(form.media.data))
            ret = []
            for i in range(len(mediastr) / 8):
                ret.append(mediastr[i*8:(i+1)*8])
            return ret
        if form.media.data:
            media = rip_media(form.media.data)
            if media:
                for j in range(len(media)):
                    med = Media.objects(slugid=media[j]).get()
                    text_post.media.append(med)
        published_time = escape(form.published_time.data)
        published_date = escape(form.published_date.data)
        published = "%s %s" % (published_date, published_time)
        datetimeformat = "%Y-%m-%d %H:%M"
        published = datetime.datetime.strptime(published, datetimeformat)
        text_post.published = published
        text_post.created = datetime.datetime.now()
        text_post.title = escape(form.title.data)
        text_post.content = escape(form.content.data)
        text_post.html_content = markdown(text_post.content, extensions)
        text_post.slugid = slugidfy()
        try:
            text_post.save()
            flash("%s was successfully saved as slugid %s" % (text_post.title,\
                text_post.slugid))
            return redirect(url_for('frontend.post_by_slugid', slugid=text_post.slugid))
        except:
            flash("Error: Post was not saved")
            return redirect(url_for('add_text_post', meta=meta, form=form))
    return render_template('admin/admin_entry.html', meta=meta, form=form)