Exemplo n.º 1
0
def upload_post():
	form = UploadPostForm()
	if form.validate_on_submit():
		title = form.title.data.strip(' ')
		content = form.content.data.strip(' ')
		image_name = form.image_name.data.strip(' ')
		
		old = Posts.query.filter_by(title=title).first()
		if old:
			flash('post already collected')
			return redirect(url_for('admin.upload_post'))

		post = Posts(title=title, content=content)
		post.add_tag(form.tags.data)
		post.image_name = image_name
		post.description = form.description.data
		post.author = current_user

		db.session.add(post)
		db.session.commit()

		flash('upload successful')
		return redirect(url_for('admin.upload_post'))

	return render_template('admin/upload_post.html',form=form)
Exemplo n.º 2
0
def post():
    form = PostForm()
    src = [{'filetype': 'None', 'path': 'None'}]
    privacy = request.form['privacy']
    if request.method == 'POST':
        if 'media' in request.files:
            media = request.files.getlist('media')
            process = upload(media, privacy=privacy, used_as='post')
            if process['result'] == 'done':
                path = process['path']
                type_ = process['filetype']
                postname = process['postname']
                src = [{'path': path, 'filetype': type_, 'filename': postname}]
            pass
        if form.validate_on_submit():
            new_post = Posts(post_content={
                'headline': form.headline.data,
                'body': form.body.data,
                'media': src
            },
                             privacy=privacy,
                             timestamp=getDate())
            db.session.add(new_post)
            db.session.commit()
            flash("Post successfull!", "success")
            return redirect(url_for('home'))
        return redirect(url_for("home"))
    abort(400)
Exemplo n.º 3
0
 def get(self, id=None):
     header = self.get_argument('header', default=None)
     content = self.get_argument('content', default=None)
     author = self.get_argument('author', default=None)
     categories = self.get_arguments('categories')
     post = Posts(header, content, author, id)
     try:
         Posts.update(post, categories)
     except:
         self.send_error(400)
Exemplo n.º 4
0
 def get(self):
     header = self.get_argument('header')
     content = self.get_argument('content')
     author = self.get_argument('author')
     categories = self.get_arguments('categories')
     if not categories:
         self.send_error(400)
     else:
         post = Posts(header, content, author)
         Posts.add(post, categories)
Exemplo n.º 5
0
from database import Posts
from flask import Flask, render_template, request, url_for, redirect
import time

app = Flask(__name__) #Instantiated Flask Object
newpost = Posts()

@app.route("/")
@app.route("/home")
def home():
    return render_template('home01.html', posts = newpost.posts, comment = len(newpost.posts))

@app.route("/about")
def about():
    return render_template('about01.html', title = 'about')

@app.route("/post")
def post():
    return render_template('post.html')

@app.route("/create", methods = ["POST"])
def create_post():
    author = request.form['author']
    title = request.form['title']
    date_posted = time.strftime("%e %B, %Y", time.localtime())
    content = request.form['content']
    newpost.get_Dict(author, title, content, date_posted)
    newpost.StoreDatabase()
    return redirect(url_for('home'))
    
if __name__ == "__main__":