예제 #1
0
def skills():
    if request.method == 'GET':
        res = SkillsController.get_all_skills()
        if not res:
            raise exceptions.NotFound()
        return res
    elif request.method == 'POST':
        res = SkillsController.save_skill(request)
        if not res:
            raise exceptions.NotFound()
        return res
예제 #2
0
def user_entries(id):
    if request.method == 'GET':
        res = EntryController.get_all_entries(id)
        if not res:
            raise exceptions.NotFound()
        return res
    elif request.method == 'POST':
        res = EntryController.save_skill(request, id)
        if not res:
            raise exceptions.NotFound()
        return res
예제 #3
0
파일: utils.py 프로젝트: jmcarp/neurotrends
def get_tag_place_counts(place, normalize):
    records = config.tag_place_counts_collection.find({'_id.place': place})
    if not records.count():
        raise exceptions.NotFound()
    if normalize:
        total = config.place_counts_collection.find_one({'_id': place})
        if not total:
            raise exceptions.NotFound()
        denom = total['value']
    else:
        denom = None
    counts = [(record['_id']['label'], divide(int(record['value']), denom))
              for record in records]
    return collections.OrderedDict(sorted(counts, key=lambda item: item[0]))
예제 #4
0
파일: app.py 프로젝트: Ogreman/readinglist
def book_detail(key):
    """
    Retrieve, update or delete book instances.
    """
    book = g.user.books.filter_by(id=key).first()

    if request.method == 'PUT':
        text = str(request.data.get('text', ''))
        title, author = bleach.clean(text).split('by') if text else '', ''
        if book:
            book.title, book.author = title.strip(), author.strip()
        else:
            book = Book(
                title=title,
                author=author,
                user=g.user,
            )
        db.session.add(book)
        db.session.commit()
        return book.to_json(), status.HTTP_202_ACCEPTED

    elif request.method == 'DELETE':
        if book:
            book.deleted = True
            db.session.add(book)
            db.session.commit()
        return '', status.HTTP_204_NO_CONTENT

    # request.method == 'GET'
    if not book:
        raise exceptions.NotFound()
    return book.to_json(), status.HTTP_200_OK
예제 #5
0
def notes_detail(key):
    """
    Retrieve, update or delete note instances.
    """
    note = Note.query.get(key)

    if request.method == 'PUT':
        text = str(request.data.get('text', ''))
        if note:
            note.text = bleach.clean(text)
        else:
            note = Note(
                text=bleach.clean(text)
            )
        db.session.add(note)
        db.session.commit()
        return note.to_json()

    elif request.method == 'DELETE':
        note.deleted = True
        db.session.add(note)
        db.session.commit()
        return '', status.HTTP_204_NO_CONTENT

    # request.method == 'GET'
    if not note:
        raise exceptions.NotFound()
    return note.to_json()
예제 #6
0
def register_routes(blueprint):
    @blueprint.route('/case', methods=['GET'])
    def get_cases():
        result = {}
        for case, borrower in Case.all_with_borrowers():
            case_json = case.to_json()

            case_id = case_json['id']
            if case_id not in result:
                result[case_id] = case_json

            if 'borrowers' not in result[case_id]:
                result[case_id]['borrowers'] = []

            if borrower is not None:
                result[case_id]['borrowers'].append(borrower.to_json())

        return result

    @blueprint.route('/case/<id_>', methods=['GET'])
    def get_case(id_):
        case = Case.get(id_)

        if case is None:
            raise exceptions.NotFound()
        else:
            return case.to_json(), status.HTTP_200_OK
예제 #7
0
def race_detail(key):
    """
    Retrieve race instance
    """
    if key not in range(1, len(races) + 1):
        raise exceptions.NotFound()
    return race_repr(key)
예제 #8
0
def driver_detail(key):
    """
    Retrieve driver instances.
    """
    if key not in range(1, len(drivers) + 1):
        raise exceptions.NotFound()
    return driver_repr(key)
예제 #9
0
def team_detail(key):
    """
    Retrieve team instances.
    """
    if key not in range(1, len(teams) + 1):
        raise exceptions.NotFound()
    return team_repr(key)
예제 #10
0
파일: api.py 프로젝트: alchayward/bayesian
def notes_detail(key):
    """
    Retrieve, update or delete note instances.
    """

    # request.method == 'GET'
    if key not in notes:
        raise exceptions.NotFound()
예제 #11
0
파일: utils.py 프로젝트: jmcarp/neurotrends
def get_tag_distances(tag_id, metric, reverse=False):
    """
    :raise: `NotFound` if distance metric or tag not found
    """
    record = config.dist_collection.find_one({'_id': metric})
    if record is None:
        raise exceptions.NotFound()
    dist_set = distance.DistSet.from_json(record)
    try:
        vector = dist_set.get_vector(tag_id)
    except ValueError:
        raise exceptions.NotFound()
    return collections.OrderedDict(
        sorted(
            vector.items(),
            key=lambda item: item[1],
            reverse=reverse,
        ), )
예제 #12
0
파일: app.py 프로젝트: Ogreman/readinglist
def book_finish(key):
    book = g.user.books.filter_by(id=key).first()
    if book:
        if not book.finish_date and book.start_date:
            book.finish_date = datetime.datetime.now()
            db.session.add(book)
            db.session.commit()
    else:
        raise exceptions.NotFound()
    return book.to_json(), status.HTTP_202_ACCEPTED
예제 #13
0
파일: utils.py 프로젝트: jmcarp/neurotrends
def get_record_by_id(record_id, record_model, record_serializer):
    """Load a record by primary key and serialize.

    :param record_id: Record primary key
    :param record_model: Model class
    :param record_serializer: Serializer class
    """
    record = record_model.load(record_id)
    if record is None:
        raise exceptions.NotFound()
    result = record_serializer().dump(record)
    return result.data
예제 #14
0
파일: example.py 프로젝트: jakirkham/sailor
def notes_detail(key):
    """
    Retrieve, update or delete note instances.
    """
    if request.method == 'PUT':
        note = str(request.data.get('text', ''))
        notes[key] = note
        return note_repr(key)

    elif request.method == 'DELETE':
        notes.pop(key, None)
        return '', status.HTTP_204_NO_CONTENT

    # request.method == 'GET'
    if key not in notes:
        raise exceptions.NotFound()
    return note_repr(key)
예제 #15
0
def get_user(id):
    res = UserController.get_user(id=id)
    if not res:
        raise exceptions.NotFound()
    return res
예제 #16
0
def get_blurbs(id):
    res = BlurbController.get_blurbs(id)
    if not res:
        raise exceptions.NotFound()
    return res
예제 #17
0
def project(id):
    res = ProjectController.save_project(request, id)
    if not res:
        raise exceptions.NotFound()
    return res
예제 #18
0
파일: app.py 프로젝트: Ogreman/readinglist
def user_detail(key):
    user = User.query.get(key)
    if not user:
        raise exceptions.NotFound()
    return user.to_json(), status.HTTP_200_OK
예제 #19
0
파일: app.py 프로젝트: Ogreman/readinglist
def book(key):
    book = g.user.books.filter_by(id=key).first()
    if not book:
        raise exceptions.NotFound()
    return render_template('book.html', book=book.to_json())
예제 #20
0
파일: api.py 프로젝트: alchayward/bayesian
        raise exceptions.NotFound()
    return session_repr(key)


@app.route("/<int:key>/update_scores", methods=['POST', 'GET'])
def notes_detail(key):
    """
    Retrieve, update or delete note instances.
    """
    if request.method == 'POST':
        update_scores(key)
        return score_update_status(key)

    # request.method == 'GET'
    if key not in DB['Sessions'].keys():
        raise exceptions.NotFound()
    return score_update_status(key)


@app.route("/<int:key>/stage_round/", methods=['POST', 'GET'])
def notes_detail(key):
    """
    Retrieve, update or delete note instances.
    """
    if request.method == 'POST':
        stage_round(key,request.data.post('round', ''))
        return staged_games_text(key)

    # request.method == 'GET'

    if key not in DB['Sessions'].keys():