Beispiel #1
0
    def get(self):
        '''returns all the bucketlists of the user'''
        usr_id = g.user.id

        # set limit for pagination
        if 'limit' in request.args:
            if request.args['limit'].isdigit():
                limit = int(request.args['limit'])
            else:
                abort(400, message='limit parameter should be an integer')
        else:
            limit = 20

        # set page of pagination
        if 'page' in request.args:
            if request.args['page'].isdigit():
                page = int(request.args['page'])
            else:
                abort(400, message='page parameter should be an integer')
        else:
            page = 1

        # get the bucketlists and implement search if required
        if 'q' in request.args:
            query = db_session.query(BucketList).\
                    filter_by(created_by=usr_id).\
                    filter(BucketList.name.like('%'+request.args['q']+'%'))
            paginator = Paginator(query, limit)
            current_page = paginator.page(page)
            bucketlists = current_page.object_list
        else:
            # get all bucketlists for this user and implement pagination
            query = db_session.query(BucketList).filter_by(created_by=usr_id)
            paginator = Paginator(query, limit)
            current_page = paginator.page(page)
            bucketlists = current_page.object_list

        if bucketlists is None:
            rv = {'bucketlists': 'none'}
        else:
            ls = []
            schema = BucketListSchema()

            for bucketlist in bucketlists:
                ls.append(schema.dump(bucketlist).data)
            rv = {
                    'total_objects': current_page.paginator.count,
                    'total_pages': current_page.paginator.total_pages,
                    'current_page': current_page.number,
                    'has_next_page': current_page.has_next(),
                    'has_previous_page': current_page.has_previous(),
                    'bucketlists': ls
                 }

        return rv, 200
Beispiel #2
0
def get_bucketlist_item(bucketlist, bucketlistitem_id):
    '''function to get a bucketlist item'''
    query = db_session.query(BucketListItem).\
            filter_by(bucket_list=bucketlist.id).\
            filter_by(id=bucketlistitem_id)
    try:
        bl_item = query.one()
    except NoResultFound:
        abort(404, message='no object with this id found')
    except MultipleResultsFound:
        abort(409, message='multiply bucketlists with this id found')
    return bl_item
Beispiel #3
0
def get_bucketlist(user, bucketlist_id):
    '''function to get a bucketlist'''
    query = db_session.query(BucketList).\
            filter_by(created_by=user.id).\
            filter_by(id=bucketlist_id)
    try:
        bl = query.one()
    except NoResultFound:
        abort(404, message='no object with this id found')
    except MultipleResultsFound:
        abort(409, message='multiply bucketlists with this id found')
    return bl