Example #1
0
def family_count(args, family_id):
    data = {}
    family = Family.query.get_or_404(family_id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(family, relation)
    return utils.json_response(data)
Example #2
0
def taxon_count(args, id):
    data = {}
    taxon = Taxon.query.get_or_404(id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(taxon, relation)
    return utils.json_response(data)
Example #3
0
def genus_count(args, id):
    data = {}
    genus = Genus.query.get_or_404(id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(genus, relation)
    return utils.json_response(data)
Example #4
0
def accession_count(args, id):
    data = {}
    accession = Accession.query.get_or_404(id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(accession, relation)
    return utils.json_response(data)
Example #5
0
def post_taxon(taxon):
    genus = Genus.query.filter_by(id=taxon.genus_id).first()
    if not genus:
        abort(422, "Invalid genus id")
    db.session.add(taxon)
    db.session.commit()
    return utils.json_response(taxon.jsonify(), 201)
Example #6
0
def post_plant(plant):
    location_id = request.values.get('location_id', None)
    if location_id is not None:
        location = Location.query.filter_by(id=location_id).first()
        if not location:
            abort(422, "Invalid location id")

    accession_id = request.values.get('accession_id', None)
    if accession_id is not None:
        accession = Accession.query.filter_by(id=accession_id).first()
        if not accession:
            abort(422, "Invalid accession id")

    db.session.add(plant)

    # change = PlantChange(to_location_id=plant.location_id,
    #                      quantity=plant.quantity,  # store original quantity
    #                      person=request.user.fullname if request.user.fullname is not None else request.user.email,
    #                      #reason=request.json['change'].get('reason', None) if 'change' in request.json else None,
    #                      reason=None,
    #                      date=request.json['change'].get('date', None) if 'change' in request.json else None
    #                      )
    # change.plant = plant
    # request.session.add(change)

    db.session.commit()
    return utils.json_response(plant.jsonify(), 201)
Example #7
0
def post_plant(plant):
    location_id = request.values.get('location_id', None)
    if location_id is not None:
        location = Location.query.filter_by(id=location_id).first()
        if not location:
            abort(422, "Invalid location id")

    accession_id = request.values.get('accession_id', None)
    if accession_id is not None:
        accession = Accession.query.filter_by(id=accession_id).first()
        if not accession:
            abort(422, "Invalid accession id")

    db.session.add(plant)

    # change = PlantChange(to_location_id=plant.location_id,
    #                      quantity=plant.quantity,  # store original quantity
    #                      person=request.user.fullname if request.user.fullname is not None else request.user.email,
    #                      #reason=request.json['change'].get('reason', None) if 'change' in request.json else None,
    #                      reason=None,
    #                      date=request.json['change'].get('date', None) if 'change' in request.json else None
    #                      )
    # change.plant = plant
    # request.session.add(change)

    db.session.commit()
    return utils.json_response(plant.jsonify(), 201)
Example #8
0
def family_count(args, family_id):
    data = {}
    family = Family.query.get_or_404(family_id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(family, relation)
    return utils.json_response(data)
Example #9
0
def plant_count(args, id):
    data = {}
    plant = Plant.query.get_or_404(id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(plant, relation)
    return utils.json_response(data)
Example #10
0
def genus_count(args, id):
    data = {}
    genus = Genus.query.get_or_404(id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(genus, relation)
    return utils.json_response(data)
Example #11
0
def post_taxon(taxon):
    genus = Genus.query.filter_by(id=taxon.genus_id).first()
    if not genus:
        abort(422, "Invalid genus id")
    db.session.add(taxon)
    db.session.commit()
    return utils.json_response(taxon.jsonify(), 201)
Example #12
0
def location_count(args, location_id):
    data = {}
    location = Location.query.get_or_404(location_id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(location, relation)
    return utils.json_response(data)
Example #13
0
def location_count(args, location_id):
    data = {}
    location = Location.query.get_or_404(location_id)
    for relation in args['relation']:
        _, base = relation.rsplit('/', 1)
        data[base] = utils.count_relation(location, relation)
    return utils.json_response(data)
Example #14
0
def post_genus(genus):
    # TODO: do an exists query instead of loading the family
    family = Family.query.filter_by(id=genus.family_id).first()
    if not family:
        abort(422, "Invalid family id")
    db.session.add(genus)
    db.session.commit()
    return utils.json_response(genus.jsonify(), 201)
Example #15
0
def post_genus(genus):
    # TODO: do an exists query instead of loading the family
    family = Family.query.filter_by(id=genus.family_id).first()
    if not family:
        abort(422, "Invalid family id")
    db.session.add(genus)
    db.session.commit()
    return utils.json_response(genus.jsonify(), 201)
Example #16
0
    def render_json(self, model, status=200):
        if isinstance(model, (list, tuple))and len(model) > 0:
            data = type(model[0]).jsonify(model, many=True)
        elif isinstance(model, db.Model):
            data = model.jsonify()
        else:
            data = model

        return utils.json_response(data, status=status)
Example #17
0
def index(args, ext=None):
    query = args.get("q", None)
    results = search(query, db.session) if query is not None else {}

    data = {}

    if request.prefers_json:
        value_factory = lambda k, v: [obj.jsonify() for obj in v]
        response_factory = lambda d: utils.json_response(d)
    else:
        value_factory = lambda k, v: [
            {"url": result_resource_map.get(key).format(obj.id), "str": obj.str()} for obj in v
        ]
        response_factory = lambda d: render_template("search/index.html", results=d)

    for key, values in results.items():
        if len(values) > 0:
            data[key] = value_factory(key, values)

    return response_factory(data)
Example #18
0
def index(args, ext=None):
    query = args.get('q', None)
    results = search(query, db.session) if query is not None else {}

    data = {}

    if request.prefers_json:
        value_factory = lambda k, v: [obj.jsonify() for obj in v]
        response_factory = lambda d: utils.json_response(d)
    else:
        value_factory = lambda k, v: [{
            'url': result_resource_map.get(key).format(obj.id),
            'str': obj.str()
        } for obj in v]
        response_factory = lambda d: render_template('search/index.html', results=d)

    for key, values in results.items():
        if len(values) > 0:
            data[key] = value_factory(key, values)

    return response_factory(data)
Example #19
0
def patch_plant(plant, id):
    location_id = request.values.get('location_id', None)
    if location_id is not None:
        location = Location.query.filter_by(id=location_id).first()
        if not location:
            abort(422, "Invalid location id")

    accession_id = request.values.get('accession_id', None)
    if accession_id is not None:
        accession = Accession.query.filter_by(id=accession_id).first()
        if not accession:
            abort(422, "Invalid accession id")

    # create the plant change
    # change = PlantChange(plant_id=request.plant.id,
    #                      from_location_id=request.plant.location_id,
    #                      quantity=request.plant.quantity,  # store original quantity
    #                      person=request.user.fullname if request.user.fullname is not None else request.user.email,
    #                      # reason=request.json['change'].get('reason', None) if 'change' in request.json else None,
    #                      reason=None,
    #                      date=request.json['change'].get('date', None) if 'change' in request.json else None

    #                      )

    # request.session.add(change)

    # if change.from_location_id != request.plant.location_id:
    #     # the change quantity represent the number of plants tranferred to a new location
    #     change.quantity = request.plant.quantity
    #     change.to_location_id = request.plant.location_id
    # elif request.plant.quantity < change.quantity:
    #     # the change quantity represents the number of plants removed from a location
    #     change.quantity = request.plant.quantity - change.quantity
    # else:
    #     # the change quantity represents the number of plants added to a location
    #     change.quantity = request.plant.quantity - change.quantity

    db.session.commit()
    return utils.json_response(plant.jsonify())
Example #20
0
def patch_plant(plant, id):
    location_id = request.values.get('location_id', None)
    if location_id is not None:
        location = Location.query.filter_by(id=location_id).first()
        if not location:
            abort(422, "Invalid location id")

    accession_id = request.values.get('accession_id', None)
    if accession_id is not None:
        accession = Accession.query.filter_by(id=accession_id).first()
        if not accession:
            abort(422, "Invalid accession id")

    # create the plant change
    # change = PlantChange(plant_id=request.plant.id,
    #                      from_location_id=request.plant.location_id,
    #                      quantity=request.plant.quantity,  # store original quantity
    #                      person=request.user.fullname if request.user.fullname is not None else request.user.email,
    #                      # reason=request.json['change'].get('reason', None) if 'change' in request.json else None,
    #                      reason=None,
    #                      date=request.json['change'].get('date', None) if 'change' in request.json else None

    #                      )

    # request.session.add(change)

    # if change.from_location_id != request.plant.location_id:
    #     # the change quantity represent the number of plants tranferred to a new location
    #     change.quantity = request.plant.quantity
    #     change.to_location_id = request.plant.location_id
    # elif request.plant.quantity < change.quantity:
    #     # the change quantity represents the number of plants removed from a location
    #     change.quantity = request.plant.quantity - change.quantity
    # else:
    #     # the change quantity represents the number of plants added to a location
    #     change.quantity = request.plant.quantity - change.quantity

    db.session.commit()
    return utils.json_response(plant.jsonify())
Example #21
0
def patch_accession(accession, id):
    # if 'source' in request.json:
    #     if request.accession.source is None:
    #         request.accession.source = Source()
    #     source = request.accession.source  # shorthand

    #     source_json = request.json['source']
    #     source_data = {col: source_json[col] for col in source_json.keys()
    #                    if col in source_mutable}
    #     source_data['source_detail_id'] = source_data.pop('id', None)

    #     # make a copy of the data for only those fields that are columns
    #     source.set_attributes(source_data)

    #     # make sure the propagation type is not empty b/c we'll get an error
    #     # trying to set the propagation details (even if it's an empty dict) if
    #     # the prop_type hasn't been set
    #     if 'propagation' in source_json and len(source_json['propagation']) > 0:
    #         # TODO: validate prop_type
    #         if source.propagation is None:
    #             source.propagation = Propagation()

    #         prop_data = source_json['propagation']
    #         source.propagation.prop_type = prop_data.pop('prop_type', source.propagation.prop_type)
    #         prop_mutable = prop_seed_mutable if source.propagation.prop_type == 'Seed' \
    #             else prop_cutting_mutable
    #         source.propagation.details = {col: prop_data[col] for col in prop_data.keys()
    #                                       if col in prop_mutable}

    #     if 'collection' in source_json and len(source_json['collection']) > 0:
    #         # TODO: validate collection datand set mutable properties
    #         if source.collection is None:
    #             source.collection = Collection()
    #         coll_data = {col: value for col, value in source_json['collection'].items()
    #                      if col in coll_mutable}
    #         source.collection.set_attributes(coll_data)
    db.session.commit()
    return utils.json_response(accession.jsonify())
Example #22
0
def post_accession(accession):
    taxon = Taxon.query.filter_by(id=accession.taxon_id).first()
    if not taxon:
        abort(422, "Invalid taxon id")

    # if 'source' in request.json:
    #     source_json = request.json['source']
    #     source_data = {col: source_json[col] for col in source_json.keys()
    #                    if col in source_mutable}
    #     source_data['source_detail_id'] = source_data.pop('id', None)

    #     # make a copy of the data for only those fields that are columns
    #     source = Source(**source_data)
    #     request.session.add(source)

    #     if 'propagation' in source_json:
    #         # TODO: validate prop_type
    #         prop_data = source_json['propagation']
    #         propagation = Propagation(prop_type=prop_data.pop('prop_type'))
    #         prop_mutable = prop_seed_mutable if propagation.prop_type == 'Seed' \
    #             else prop_cutting_mutable

    #         propagation.details = {col: prop_data[col] for col in prop_data.keys()
    #                                if col in prop_mutable}
    #         source.propagation = propagation


    #     collection = Collection()
    #     if 'collection' in source_json:
    #         # TODO: validate collection datand set mutable properties
    #         coll_data = {col: value for col, value in source_json['collection'].items()
    #                      if col in coll_mutable}
    #         collection = Collection(**coll_data)
    #         source.collection = collection

    db.session.add(accession)
    db.session.commit()
    return utils.json_response(accession.jsonify(), 201)
Example #23
0
def post_location(location):
    db.session.add(location)
    db.session.commit()
    return utils.json_response(location.jsonify(), 201)
Example #24
0
def patch_location(location, id):
    db.session.commit()
    return utils.json_response(location.jsonify())
Example #25
0
 def get(family, id):
     return utils.json_response(family.jsonify())
Example #26
0
def index_taxon():
    taxon = Taxon.query.all()
    data = Taxon.jsonify(taxon, many=True)
    return utils.json_response(data)
Example #27
0
def index_accession():
    accession = Accession.query.all()
    data = Accession.jsonify(accession, many=True)
    return utils.json_response(data)
Example #28
0
def list_geography():
    geographies = Geography.query.all()
    return utils.json_response(Geography.jsonify(geographies, many=True))
Example #29
0
def index_taxon():
    taxon = Taxon.query.all()
    data = Taxon.jsonify(taxon, many=True)
    return utils.json_response(data)
Example #30
0
def post_family(family):
    db.session.add(family)
    db.session.commit()
    return utils.json_response(family.jsonify(), 201)
Example #31
0
def patch_family(family, id):
    db.session.commit()
    return utils.json_response(family.jsonify())
Example #32
0
def get_family(family, family_id):
    return utils.json_response(family.jsonify())
Example #33
0
def get_source(source_detail, id):
    return utils.json_response(source_detail.jsonify())
Example #34
0
def patch_source(source_detail, id):
    db.session.commit()
    return utils.json_response(source_detail.jsonify())
Example #35
0
 def patch(family, id):
     return utils.json_response(family.jsonify())
Example #36
0
def patch_taxon(taxon, taxon_id):
    db.session.commit()
    return utils.json_response(taxon.jsonify())
Example #37
0
def get_geography(geography_id):
    geography = Geography.query.get_or_404(geography_id)
    return utils.json_response(geography.jsonify())
Example #38
0
def get_taxon(taxon, id):
    return utils.json_response(taxon.jsonify())
Example #39
0
def get_taxon(taxon, id):
    return utils.json_response(taxon.jsonify())
Example #40
0
def patch_taxon(taxon, taxon_id):
    db.session.commit()
    return utils.json_response(taxon.jsonify())
Example #41
0
def get_accession(accession, id):
    return utils.json_response(accession.jsonify())
Example #42
0
def index_source():
    sources = SourceDetail.query.all()
    data = SourceDetail.jsonify(sources, many=True)
    return utils.json_response(data)
Example #43
0
def index_location():
    locations = Location.query.all()
    data = Location.jsonify(locations, many=True)
    return utils.json_response(data)
Example #44
0
def get_location(location, id):
    return utils.json_response(location.jsonify())
Example #45
0
def index_family():
    families = Family.query.all()
    data = Family.jsonify(families, many=True)
    return utils.json_response(data)
Example #46
0
def post_source(source_detail):
    db.session.add(source_detail)
    db.session.commit()
    return utils.json_response(source_detail.jsonify(), 201)