Ejemplo n.º 1
0
def dashboard():
    form = NewPost()

    if request.method == 'POST' and form.validate_on_submit():
        # Get file data and save to your uploads folder
        if form.photo.data:  #for both text and photo
            photo = form.photo.data
            description = form.description.data

            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return jsonify(message=[{
                "message": "File Upload Successful",
                "filename": filename,
                "description": description
            }])

        else:  #only posts text
            description = form.description.data
            return jsonify(message=[{
                "message": "Post Successful",
                "description": description
            }])

    return render_template('dashboard.html', form=form)
Ejemplo n.º 2
0
def update_post(request, post_id):
    note = get_object_or_404(Post, pk=post_id)

    if request.method == 'POST':
        newpost = NewPost(request.POST, instance=note)
        if newpost.is_valid():
            new = newpost.save(commit=False)
            new.auther = request.user
            new.save()
            return redirect('/')
    else:
        newpost = NewPost()
    context = {
        'title': 'تحرير تدوينة',
        'newpost': newpost,
        'post': note,
    }
    return render(request, 'app/update_post.html', context)
Ejemplo n.º 3
0
def new_post(request):

    if request.method == 'POST':
        newpost = NewPost(request.POST)
        if newpost.is_valid:
            new = newpost.save(commit=False)
            new.auther = request.user
            new.save()
            return redirect('/')

    else:
        newpost = NewPost()

    context = {
        'title': 'اضافة تدوينة جديدة',
        'newpost': newpost,
    }
    return render(request, 'app/new_post.html', context)
Ejemplo n.º 4
0
def adminblog():
    if current_user.role == 'Administrator':
        form = NewPost()
        if request.method == "POST":
            new_blog = Blog(blog_title=request.form['title'],
                            blog_content=request.form['text'],
                            blog_slug=request.form['slug'],
                            blog_author=request.form['author'])
            db.session.add(new_blog)
            db.session.commit()
            return render_template("index.html")
        elif request.method == "GET":
            return render_template("adminblog.html", form=form)
Ejemplo n.º 5
0
def blog_create():
    form = NewPost()
    if form.validate_on_submit():
        new_post = Posts(title=form.data['title'],
                         headline=form.data['headline'],
                         body=form.data['body'],
                         created_by=current_user.id)
        db.session.add(new_post)
        db.session.commit()
        flash('New post created successfully!')

        url = url_for('blog_view', post_id=new_post.id, slug=new_post.slug)
        return redirect(url)

    return render_template('blog_create.html', form=form)
Ejemplo n.º 6
0
def blog_edit(post_id, slug):
    post = Posts.by_id(post_id)
    if post.author.id != current_user.id:
        return redirect(url_for('index'))

    form = NewPost(**post.__dict__)
    if form.validate_on_submit():
        post.title = form.data['title']
        post.headline = form.data['headline']
        post.body = form.data['body']
        db.session.commit()

        flash('Post updated successfully!')

        url = url_for('blog_view', post_id=post.id, slug=post.slug)
        return redirect(url)

    return render_template('blog_edit.html', form=form, post=post)
Ejemplo n.º 7
0
def addNew():
	if current_user.is_admin:
		page_title="Grace this world with a new post, Sensei"
		post=NewPost()
		if request.method=='POST' and post.validate_on_submit():
			if 'post_image' not in request.files:
				flash('No Files')
				return 'no file found'
			filename=images.save(request.files['post_image'])
			url=images.url(filename)
			blogpost=Post(post.title.data, post.category.data, post.content.data, filename, url)
			save_changes(blogpost, post, isnew=True)
			# return render_template('postData.html', form=post)
			return redirect(url_for('index'))
		else:
			flash(post.errors)
		
		return render_template('newpost.html', form=post, title=page_title)
	else:
		abort(404)