from flask import abort, request from flask.ext.login import login_required import sqlalchemy.orm as orm from webargs import fields from webargs.flaskparser import use_args import bauble.db as db from bauble.forms import form_factory from bauble.models import Genus from bauble.resource import Resource import bauble.utils as utils resource = Resource('genus', __name__) @resource.index @login_required def index(): genera = Genus.query.all() if not request.accept_json: abort(406) return resource.render_json(genera) @resource.show @login_required def show(id): genus = Genus.query \ .options(orm.joinedload(*Genus.synonyms.attr)) \ .get_or_404(id)
from flask import redirect, request, url_for from flask.ext.login import login_required import sqlalchemy.orm as orm from webargs import fields from webargs.flaskparser import use_args import bauble.db as db from bauble.forms import form_factory from bauble.models import Plant from bauble.middleware import use_model from bauble.resource import Resource from bauble.schema import schema_factory import bauble.utils as utils resource = Resource('plant', __name__) @resource.index @login_required def index(): taxa = Plant.query.all() return resource.render_json(taxa) @resource.show @login_required @use_model(Plant) def show(plant, id): if request.prefers_json: return resource.render_json(plant) # relations = ['/plants', '/plants/plants'] # counts = {}
from flask.ext.login import login_required from flask import abort, request import sqlalchemy.orm as orm import bauble.db as db from bauble.models import Taxon, VernacularName from bauble.resource import Resource resource = Resource('vernacular_name', __name__, url_prefix='/taxon/<int:taxon_id>/vernacular_name') @resource.index @login_required def index(taxon_id): taxon = Taxon.query.options( orm.joinedload('vernacular_names')).get_or_404(taxon_id) if not request.accept_json: # TODO: send paginated response of all vernacular_name and potentially # apply filters using the search module abort(406) return resource.render_json(taxon.vernacular_names) @resource.show @login_required def show(taxon_id, id): vernacular_name = VernacularName.query.get_or_404(id)
from flask import jsonify, render_template, request from flask.ext.login import login_required from marshmallow import Schema from webargs import fields, validate from webargs.flaskparser import use_args from flask_wtf import Form from wtforms import StringField from wtforms.validators import Length import bauble.db as db from bauble.search import search from bauble.resource import Resource import bauble.utils as utils resource = Resource('search', __name__) # class SearchForm(Form): # q = StringField('q', Length(min=1)) class SearchResultSchema(Schema): # TODO: pass pass # TODO: we could probably have a better way map search results to resources.... # maybe even provide a blueprint/resource and use the resource to get the url # with url_for result_resource_map = { 'families': '/family/{}', 'genera': '/genus/{}',
from flask import abort, redirect, request, url_for from flask.ext.login import login_required import sqlalchemy.orm as orm from webargs import fields from webargs.flaskparser import use_args import bauble.db as db from bauble.forms import form_factory from bauble.models import Accession from bauble.middleware import use_model from bauble.resource import Resource from bauble.schema import schema_factory import bauble.utils as utils resource = Resource('accession', __name__) @resource.index @login_required def index(): accessions = Accession.query.all() if not request.accept_json: abort(406) return resource.render_json(accessions) @resource.show @login_required def show(id): accession = Accession.query \ .options(orm.joinedload(*Accession.synonyms.attr)) \
from flask import abort, request from flask.ext.login import login_required import sqlalchemy.orm as orm from webargs import fields from webargs.flaskparser import use_args import bauble.db as db from bauble.forms import form_factory from bauble.models import Family from bauble.resource import Resource import bauble.utils as utils resource = Resource('family', __name__) @resource.index @login_required def index(): families = Family.query.all() if not request.accept_json: abort(406) return resource.render_json(families) @resource.show @login_required def show(id): family = Family.query \ .options(orm.joinedload(*Family.synonyms.attr)) \ .get_or_404(id)
from flask.ext.login import login_required from wtforms_alchemy import ModelFieldList, ModelForm, ModelFormField, model_form_factory from wtforms.fields import FormField, BooleanField, StringField import wtforms.widgets as widgets import sqlalchemy.orm as orm from webargs import fields from webargs.flaskparser import use_args import bauble.db as db # from bauble.controllers.vernacular_name import Resource as VernacularNameResource from bauble.forms import form_factory, form_class_factory, BaseModelForm from bauble.models import Geography, Taxon, VernacularName, DefaultVernacularName from bauble.resource import Resource import bauble.utils as utils resource = Resource('taxon', __name__) class HiddenBooleanField(BooleanField): widget = widgets.HiddenInput() class RelationshipFormMixin(BaseModelForm): destroy_ = HiddenBooleanField() class OneToManyField(ModelFieldList): def __init__(self, model, *args, **kwargs): model_form = model_form_factory(RelationshipFormMixin) form_cls = form_class_factory(model, model_form,
from flask import redirect, request, url_for from flask.ext.login import login_required import sqlalchemy.orm as orm from webargs import fields from webargs.flaskparser import use_args import bauble.db as db from bauble.forms import form_factory from bauble.models import Location from bauble.middleware import use_model from bauble.resource import Resource from bauble.schema import schema_factory import bauble.utils as utils resource = Resource('location', __name__) @resource.index @login_required def index(): taxa = Location.query.all() return resource.render_json(taxa) @resource.show @login_required @use_model(Location) def show(location, id): if request.prefers_json: return resource.render_json(location) # relations = ['/locations', '/locations/locations'] # counts = {}