Exemplo n.º 1
0
def upload():
    if request.method == 'POST':
        pst = Post(user=login_session['username'],
                   user_id=login_session['id'],
                   title=request.form['title'],
                   description=request.form['description'],
                   file=request.files['file'])
        if (user == None):
            flash("Please login to upload")
            return redirect(url_for('upload'))
        elif title == "" or description == "" or file is None:
            flash("Please fill in all the args")
            return redirect(url_for('upload'))

        else:
            session.add(pst)
            session.commit()
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return redirect(url_for('main'))
    else:
        if (session.query(User).filter_by(id=login_session['id']).first()
                is not None):
            user = session.query(User).filter_by(
                id=login_session['id']).first()
            return render_template('uploader.html', user=user)
        return render_template('uploader.html')
Exemplo n.º 2
0
def manage_new_blog():
    val_email = request.cookies.get('email')
    email = check_secure_val(val_email)
    try:
        user = session.query(User).filter_by(email=email).first()
    except:
        session.rollback()
    if not user:
        return redirect('/authenticate')
    if request.method == 'GET':
        return render_template('manage_blog_edit.html', id='', action='/manage/blogs/create', user=user)
    if request.method == 'POST':
        data = request.get_json()
        subject = data['subject']
        summary = data['summary']
        content = data['content']
        if not subject or not subject.strip():
            raise APIValueError('subject', 'subject cannot be empty.')
        if not summary or not summary.strip():
            raise APIValueError('summary', 'summary cannot be empty.')
        if not content or not content.strip():
            raise APIValueError('content', 'content cannot be empty.')
        post = Post(user_id=user.id, subject=subject.strip(), summary=summary.strip(), content=content.strip(),
                    user_name=user.name, user_image=user.image)
        session.add(post)
        try:
            session.commit()
        except:
            session.rollback()
        # session.close()
        r = make_response(json.dumps(user.name, ensure_ascii=False).encode('utf-8'))
        r.headers['Content-type'] = 'application/json; charset=utf-8'
        return r
Exemplo n.º 3
0
def upload():
	if request.method == 'GET':
		username = login_session['username']
		return render_template('load_post.html', username = username)
	else:
		if 'imagen' not in request.files:
			flash('No file part')
			return redirect(url_for('showMain'))
		file = request.files['imagen']
		if file.filename == '':
			flash('No selected file')
			return redirect(request.url)
		if file and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			print(filename)
			ruta = os.path.join(UPLOAD_FOLDER, filename)
			print(ruta)
			file.save(os.path.join(UPLOAD_FOLDER, filename))
			nuevoPost = Post(
				imagen = filename,
				titulo = request.form['titulo'],
				contenido = request.form['contenido'],
				url = request.form['url']
				)
			session.add(nuevoPost)
			session.commit()
			return redirect(url_for('showMain'))
Exemplo n.º 4
0
def create_post(sid):
    if 'uid' not in session:
        return redirect(url_for('login'))

    sub = dbsession.query(Sub).filter_by(id=sid).one()
    if request.method == 'POST':
        newPost = Post(title=request.form['title'],
                       message=request.form['message'],
                       sub_id=sid,
                       user_id=int(session['uid']))
        dbsession.add(newPost)
        dbsession.commit()
        return redirect(url_for('show_post', sid=sub.id, pid=newPost.id))
    return render_template('create_post.html', sub=sub)
Exemplo n.º 5
0
def new_blog():
    if request.method == 'GET':
        log('200')
        return render_template('new_blog.html')
    if request.method == 'POST':
        log('302')

        if 'username' not in login_session:
            return redirect(url_for('login'))

        uid = login_session['id']
        title = request.form.get('title')
        content = request.form.get('content')
        new_post = Post(uid=uid, title=title, content=content)
        session.add(new_post)
        session.commit()
        return redirect(url_for('main'))
Exemplo n.º 6
0
def newPost(author_id):
    if 'username' not in login_session:
        return redirect('/login')
    author = session.query(Author).filter_by(id=author_id).one()
    if login_session['email'] != author.email:
        return '''<script>function myFunction()
                          {alert('You are not authorized to add post.');}
                  </script>
                  <body onload='myFunction()'>'''
    if request.method == 'POST':
        newItem = Post(title=request.form['title'],
                       description=request.form['description'],
                       author_id=author.id)
        session.add(newItem)
        session.commit()
        return redirect(url_for('showIndex'))
    return render_template('postTool.html', author=author, operation='Add')
Exemplo n.º 7
0
def NewPost():
    if request.method == 'GET':
        return render_template("newpost.html")

    if request.method == 'POST':
        subject = request.form['subject']
        content = request.form['content']

        if subject and content:
            newpost = Post(subject=subject, content = content)
            session.add(newpost)
            session.commit()

            return redirect(url_for('PostPage', post_id = newpost.id))
        else:
            error = "subject and content, please!"
            return render_template("newpost.html", subject=subject, content=content, error=error)
Exemplo n.º 8
0
def newPost(category_id, item_id):
    if 'username' not in login_session:
        return redirect('/login')
    categories = session.query(Category).order_by(asc(Category.name))
    item = session.query(Item).filter_by(category_id=category_id).first()

    if request.method == 'POST':
        newPost = Post(post=request.form['post'],
                       item_id=item_id,
                       user_id=login_session['user_id'])
        session.add(newPost)
        session.commit()
        print('USER ID: ', login_session['user_id'])
        return redirect(
            url_for('showPosts', category_id=category_id, item_id=item_id))

    return render_template('newPost.html',
                           category_id=category_id,
                           categories=categories,
                           item_id=item_id,
                           item=item)
Exemplo n.º 9
0
def newPost():
    if request.method == 'POST':

        # file upload
        BLOG_FOLDER = "blog"
        f = request.files['file']

        if not os.path.isdir(UPLOAD_FOLDER):
            os.mkdir(UPLOAD_FOLDER)

        filename = secure_filename(f.filename)
        destination = "/".join([UPLOAD_FOLDER, BLOG_FOLDER, filename])
        f.save(destination)

        # database
        newPost = Post(title=request.form['title'],
                       content=request.form['content'],
                       image="http://localhost:5000/" + destination)
        session.add(newPost)
        session.commit()
        return redirect(url_for('showPosts'))
    else:
        return render_template('newPost.html')
Exemplo n.º 10
0
    name="Nasa",
    email="*****@*****.**",
    picture=
    'http://t0.gstatic.com/images?q=tbn:ANd9GcQ9u48pu-6IB2FnnYl_H-15le_g8Dkt5d5RN-VWiWIl_-dyJdaa'
)
session.add(author1)
session.commit()

# Post 1
post1 = Post(author_id=1,
             title="First step on moon",
             description='''Apollo 11 was the spaceflight that landed the first
             two people on the Moon. Mission commander Neil Armstrong and pilot
             Buzz Aldrin, both American, landed the lunar module Eagle on July
             20, 1969, at 20:17 UTC. Armstrong became the first person to step
             onto the lunar surface six hours after landing on July 21 at
             02:56:15 UTC; Aldrin joined him about 20 minutes later. They spent
             about two and a quarter hours together outside the spacecraft, and
             collected 47.5 pounds (21.5 kg) of lunar material to bring back to
             Earth. Michael Collins piloted the command module Columbia alone
             in lunar orbit while they were on the Moon's surface. Armstrong
             and Aldrin spent 21.5 hours on the lunar surface before rejoining
             Columbia in lunar orbit.''')
session.add(post1)
session.commit()

# Post 2
post2 = Post(author_id=1,
             title="a mission to touch the sun",
             description='''Wearing a nearly 5 inch coat of carbon composite
             solar shields, NASA's Parker Solar Probe will explore the sun's
             atmosphere in a mission that is expected to launch in early
Exemplo n.º 11
0
session.add(user3)
session.commit()


design_group = Group(name="design");
session.add(design_group)
session.commit()

art_group = Group(name="art");
session.add(art_group)
session.commit()



post1 = Post(subject="a sad day", 
    content="i'm depressed", 
    group=design_group, user=user1, 
    date_added = datetime.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')) 
session.add(post1)
session.commit()

post2 = Post(subject="a happy day", 
    content="i'm happy", 
    group=art_group, 
    user=user2,
    date_added = datetime.strptime('Dec 25 2017  2:00PM', '%b %d %Y %I:%M%p'))
session.add(post2)
session.commit()

post3 = Post(subject="a funny day", 
    content="i'm laughing", 
    group=art_group, 
Exemplo n.º 12
0
session.commit()

# Categories - Social
Social = Category(id=1, name="Social", user_id=1)
session.add(Social)
session.commit()

Outdoor_Activities = Item(name="Outdoor Activities",
                          description="Outdoor activities",
                          category_id=1,
                          id=1,
                          user_id=1)
session.add(Outdoor_Activities)
session.commit()

Post1 = Post(post="Today is a good day to go to a beach", item_id=1, user_id=1)
session.add(Post1)
session.commit()

Social_Media = Item(name="Social Media",
                    description="Social media",
                    category_id=1,
                    id=2,
                    user_id=1)
session.add(Social_Media)
session.commit()

Post2 = Post(post="Is facebook down today?", item_id=2, user_id=1)
session.add(Post2)
session.commit()
Exemplo n.º 13
0
def add_post():
    data = request.get_json()
    post = Post(title=data['title'], description=data['description'], user_id=g.user.id)
    db_session.add(post)
    db_session.commit()
    return jsonify({'status': 'ok'})
Exemplo n.º 14
0
session.add(new_user)
session.commit()

new_user = User(username='******',
                name='saafdasd',
                email='*****@*****.**',
                password='******',
                bio='Accountatn ',
                phone_number='+23423423')
session.add(new_user)
session.commit()

new_post = Post(
    uid=1,
    title='The raise of the empire',
    content=
    'once upon a time, the persian emire raised upon light and one day it fell, it was unexpected',
    type='history',
    status='live')
session.add(new_post)
session.commit()

new_post = Post(uid=2,
                title='CHELSEA WON THE PRIMER LEAGUE',
                content='Chelsea won the title, AGAIN! YESS 3 Nill',
                type='Sports',
                status='live')
session.add(new_post)
session.commit()

new_post = Post(uid=1,
Exemplo n.º 15
0
def add_post():
    # you have to search how to use jinja to use this user object in your profile.html
    # you need to create profile.html page in templates folder
    users = query_users_all()

    # server if recived POST request will GET the values From the Form returned by GET request
    if request.method == 'POST':
        error = False
        sys_error_message = ''
        user_error_message = ''
        try:
            post_title = '%s' % request.form.get('title')
            post_date = '%s' % request.form.get('post_date')
            post_section = '%s' % request.form.get('section')
            post_userid = int('%s' % request.form.get('user_id'))
            post_content = '%s' % request.form.get('content')
            post_image_link = '%s' % request.form.get('image')
            newPost = Post(title=post_title,
                           content=post_content,
                           post_date=post_date,
                           section=post_section,
                           image=post_image_link,
                           user_id=post_userid)
            session.add(newPost)
            session.commit()
        except:
            error = True
            print(sys.exc_info())
            sys_error_message = str(sys.exc_info())
            user_error_message = 'Sorry We can not create New Post right now Contact Support '
            session.rollback()
        finally:
            session.close()
        if not error:
            success_message = 'Greate You Have Created New Post With Title %s ' % post_title
            cod = 200
            return jsonify({'message': success_message, 'cod': cod})
        else:
            cod = 501
            return jsonify({
                'message': user_error_message,
                'debug_message': sys_error_message,
                'cod': cod
            })

    # server if recived GET request will return this form
    html_message = '<!DOCTYPE html><head><meta charset="utf-8"><title>Add Post</title>'
    html_message += '<style>* { box-sizing: border-box; } input[type=text], select, textarea'
    html_message += '{ width: 70%; padding: 12px; border: 1px solid #ccc;'
    html_message += 'border-radius: 4px; resize: vertical; } label { padding: 12px 12px 12px 0;'
    html_message += 'display: inline-block; } input[type=submit] { background-color: #4CAF50;'
    html_message += 'color: white; padding: 12px 20px; border: none; border-radius: 4px;'
    html_message += 'cursor: pointer; float: right; } input[type=submit]:hover { background-color: #45a049; }'
    html_message += '.container { border-radius: 5px; background-color: #f2f2f2; padding: 20px; }'
    html_message += '.col-25 { float: left; width: 25%; margin-top: 6px; } .col-75 { float: left; width: 75%; margin-top: 6px; }'
    html_message += '.row:after { content: ""; display: table; clear: both; }'
    html_message += '@media screen and (max-width: 600px) { .col-25, .col-75, input[type=submit] { width: 100%; margin-top: 0; } }'
    # html form feel free to change style
    html_message += '</style></head<body><form action="/add_post" method="post"><br /><br />'
    html_message += '<label for="title">Post Title: </label><input type="text" name="title"><br />'
    html_message += '<label for="">Post Date: </label><input type="date" name="post_date"><br /><br />'
    html_message += '<label for="">Post Section </label><select name="section">'
    html_message += '<option value="HTML5 Section">HTML5 Section</option>'
    html_message += '<option value="JavaScript Section">JavaScript Section</option>'
    html_message += '<option value="Python Section">Python Section</option>'
    html_message += '</select><br /><br /><label for="user_id">User Id</label><select name="user_id">'
    for user in users:
        html_message += '<option value="' + str(user.id) + '">' + str(
            user.name) + '</option>'
    html_message += '</select><br /><br />'
    html_message += '<textarea name="content">Please Enter Your Post Content</textarea><br /><br />'
    html_message += '<label for="image">Post Image Link: </label><input type="text" name="image"><br />'

    html_message += '<input type="submit"></form>'
    return html_message
Exemplo n.º 16
0
def createBlogPost(title, content):
    addedPost = Post(title=title, content=content)
    session.add(addedPost)
    session.commit()
    return jsonify(Post=addedPost.serialize)