Exemple #1
0
def select_page_json(offset=0):
    offset = int(offset)
    post_list = Post.select().order_by(Post.date.desc()).paginate(
        offset, PAGE_SIZE)

    json.JSONEncoder.default = lambda self, obj: (obj.isoformat(
    ) if isinstance(obj, datetime.datetime) else None)

    res = []
    for i in range(0, len(post_list)):
        res.append(model_to_dict(post_list[i], exclude=["date"]))

    res = {'data': res}
    teardown()
    return res
Exemple #2
0
def insert_article(request):

    imageFile = request.files['imageFile']
    print app.config['UPLOAD_FOLDER']

    filename = str(uuid.uuid1()) + '.png'
    localLink = os.path.join(APP_ROOT + '/images/' + filename)
    apiLink = '/api/images/' + filename
    imageFile.save(localLink)
    newPost = Post.create(title=request.form['title'],
                          body=request.form['body'],
                          image=apiLink,
                          link=request.form['link'])
    newPost.save()
    teardown()
Exemple #3
0
def select_page(offset=0):
    offset = int(offset)
    post_list = Post.select().order_by(Post.date.desc()).paginate(
        offset, PAGE_SIZE)
    teardown()
    return post_list
Exemple #4
0
def delete_article(post_id):
    delete_query = Post.delete().where(Post.id == post_id)
    delete_query.execute()
    teardown()
Exemple #5
0
 def tearDown(self):
     models.teardown(self.session)