Exemple #1
0
 def post(self):
     form = PostCreateForm()
     if not form.validate_on_submit():
         return form.errors, 422
     post = Post(form.title.data,form.img.data, form.body.data,form.tag.data)
     db.session.add(post)
     db.session.commit()
     return PostSerializer(post).data, 201
Exemple #2
0
def create():
    post = Post()
    form = PostCreateForm()
    if request.method == 'POST' and form.validate_on_submit():
        form.populate_obj(post)
        post.created = datetime.datetime.now()
        post.user_id = g.user.id
        db.session.add(post)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('index'))
    return render_template('edit.html',
        form = form)
Exemple #3
0
    def post(self):
        form = PostCreateForm()
        if not form.validate_on_submit():
            return form.errors, 422
        post = Post(form.title.data, form.body.data)
        db.session.add(post)
        db.session.commit()

        url = 'https://raw.githubusercontent.com/rxforces/webbot/master/webbot.json'
        response = urllib.urlopen(url)
        payload = json.loads(response.read())
        payload['owner'] = g.user.id
        payload['name'] = g.user.id + '_' + form.title.data

        url = 'http://172.17.0.1:4400/scheduler/iso8601'
        headers = {'content-type': 'application/json'}
        r = requests.post(url, data=json.dumps(payload), headers=headers)

        return PostSerializer(post).data, 201