def post_process_after_initialization(self, bean, bean_name: str): bean_type = bean.__class__ annotation = AnnotationUtils.get_annotation(bean_type, Blueprint) if annotation is not None: options = annotation['options'] or {} b = FlaskBlueprint(bean_name, bean.__module__, url_prefix=annotation['url_prefix'], **options) annotation['blueprint'] = b for m in dir(bean_type): func = getattr(bean_type, m) if inspect.isfunction(func): method = getattr(bean, m) try: self._resolve_route(b, method) self._resolve_method_def_filter(b, method) except Exception: log.error( "Failed to resolve the route function '%s' in blueprint '%s'", m, bean_type.__name__, ) raise self.blueprints.append(b) return bean
def blueprint(self, **kwargs): """ Returns a Flask Blueprint instance, either one provided or created here. .. versionchanged:: 2014.05.19 * Renamed method from ``create_blueprint`` to ``blueprint`` * If ``instance`` attribute exists, use this is as the blueprint else create the blueprint. * Support for endpoint prefixing Returns ------- flask.blueprints.Blueprint An instantiated Flask Blueprint instance """ try: blueprint = self.instance except AttributeError: #: If this route was included a url preifx may have been passed #: to the route if 'url_prefix' in kwargs: url_prefix = self.url_prefix or '' self.url_prefix = kwargs['url_prefix'] + url_prefix #: If this route was included a endpoint prefix may have been #: passed to the route if 'endpoint' in kwargs: endpoint = self.endpoint or '' self.endpoint = kwargs['endpoint'] + endpoint blueprint = FlaskBlueprint(self.endpoint, self.module, static_folder=self.static_folder, static_url_path=self.static_url_path, template_folder=self.template_folder, url_prefix=self.url_prefix, subdomain=self.subdomain, url_defaults=self.url_defaults) return blueprint
from flask import Blueprint as FlaskBlueprint from flask import abort from flask.ext.restful import marshal_with, fields from pebbles.models import db, Lock from pebbles.views.commons import auth from pebbles.utils import requires_admin from pebbles.server import restful locks = FlaskBlueprint('locks', __name__) lock_fields = {'lock_id': fields.String, 'acquired_at': fields.DateTime} class LockView(restful.Resource): @auth.login_required @requires_admin @marshal_with(lock_fields) def put(self, lock_id): lock = Lock(lock_id) db.session.add(lock) try: db.session.commit() except: db.session.rollback() abort(409) return lock @auth.login_required def delete(self, lock_id): lock = Lock.query.filter_by(lock_id=lock_id).first()
from flask.ext.restful import marshal_with from flask import abort, g from flask import Blueprint as FlaskBlueprint import logging from pouta_blueprints.models import db, Blueprint, Plugin from pouta_blueprints.forms import BlueprintForm from pouta_blueprints.server import restful from pouta_blueprints.views.commons import auth, blueprint_fields from pouta_blueprints.utils import requires_admin, parse_maximum_lifetime blueprints = FlaskBlueprint('blueprints', __name__) MAX_ACTIVATION_TOKENS_PER_USER = 3 class BlueprintList(restful.Resource): @auth.login_required @marshal_with(blueprint_fields) def get(self): query = Blueprint.query.order_by(Blueprint.name) if not g.user.is_admin: query = query.filter_by(is_enabled=True) results = [] for blueprint in query.all(): plugin = Plugin.query.filter_by(id=blueprint.plugin).first() blueprint.schema = plugin.schema blueprint.form = plugin.form # Due to immutable nature of config field, whole dict needs to be reassigned.
from flask.ext.restful import marshal_with from flask import abort from flask import Blueprint as FlaskBlueprint import logging from pouta_blueprints.models import User from pouta_blueprints.forms import UserForm from pouta_blueprints.server import restful from pouta_blueprints.views.commons import user_fields, create_user, create_worker firstuser = FlaskBlueprint('firstuser', __name__) class FirstUserView(restful.Resource): @marshal_with(user_fields) def post(self): users = User.query.all() form = UserForm() if not users: if not form.validate_on_submit(): logging.warn("validation error on first user creation") return form.errors, 422 user = create_user(form.email.data, form.password.data, is_admin=True) create_worker() return user else: return abort(403)
from flask import abort, g from flask import Blueprint as FlaskBlueprint import datetime import logging import json from pebbles.models import db, Blueprint, Instance, InstanceLog, User from pebbles.forms import InstanceForm, UserIPForm from pebbles.server import app, restful from pebbles.utils import requires_admin, memoize from pebbles.tasks import run_update, update_user_connectivity from pebbles.views.commons import auth, is_group_manager from pebbles.rules import apply_rules_instances, get_group_blueprint_ids_for_instances instances = FlaskBlueprint('instances', __name__) USER_INSTANCE_LIMIT = 5 instance_fields = { 'id': fields.String, 'name': fields.String, 'provisioned_at': fields.DateTime, 'lifetime_left': fields.Integer, 'maximum_lifetime': fields.Integer, 'runtime': fields.Float, 'state': fields.String, 'to_be_deleted': fields.Boolean, 'error_msg': fields.String, 'username': fields.String, 'user_id': fields.String,
from flask import Blueprint as FlaskBlueprint, request from pebbles.server import restful from pebbles.views.commons import auth myip = FlaskBlueprint('myip', __name__) class WhatIsMyIp(restful.Resource): @auth.login_required def get(self): if len(request.access_route) > 0: return {'ip': request.access_route[-1]} else: return {'ip': request.remote_addr}
from flask import abort, g from flask import Blueprint as FlaskBlueprint from flask.ext.restful import fields from sqlalchemy.orm.session import make_transient import logging import uuid from pebbles.models import db, BlueprintTemplate, Plugin from pebbles.forms import BlueprintTemplateForm from pebbles.server import restful from pebbles.views.commons import auth, requires_group_manager_or_admin from pebbles.utils import requires_admin, parse_maximum_lifetime from pebbles.rules import apply_rules_blueprint_templates blueprint_templates = FlaskBlueprint('blueprint_templates', __name__) blueprint_template_fields = { 'id': fields.String(attribute='id'), 'name': fields.String, 'is_enabled': fields.Boolean, 'plugin': fields.String, 'config': fields.Raw, 'schema': fields.Raw, 'form': fields.Raw, 'allowed_attrs': fields.Raw, 'blueprint_schema': fields.Raw, 'blueprint_form': fields.Raw, 'blueprint_model': fields.Raw }
from flask.ext.restful import marshal_with, fields from flask import Blueprint as FlaskBlueprint import logging from pebbles.models import Blueprint, Instance from pebbles.server import restful from pebbles.views.commons import auth from pebbles.utils import requires_admin, memoize from collections import defaultdict stats = FlaskBlueprint('stats', __name__) def query_blueprint(blueprint_id): return Blueprint.query.filter_by(id=blueprint_id).first() blueprint_fields = { 'name': fields.String, 'users': fields.Integer, 'launched_instances': fields.Integer, 'running_instances': fields.Integer, } result_fields = { 'blueprints': fields.List(fields.Nested(blueprint_fields)),
from werkzeug.routing import RoutingException # peewee from peewee import DoesNotExist from peewee import IntegrityError from playhouse.shortcuts import model_to_dict from playhouse.shortcuts import update_model_from_dict from trendlines import logger from trendlines.__about__ import __version__ from . import db from . import orm from .error_responses import ErrorResponse from . import utils pages = FlaskBlueprint('pages', __name__) # https://github.com/Nobatek/flask-rest-api/issues/51 class Api(_Api): def handle_http_exception(self, error): # Don't serialize redirects if isinstance(error, RoutingException): return error return super().handle_http_exception(error) api_class = Api() api = Blueprint("api", __name__, description="All API.") api_datapoint = Blueprint("DataPoints", __name__,
from flask.ext.restful import marshal_with, fields, reqparse from flask import abort, g from flask import Blueprint as FlaskBlueprint from sqlalchemy import desc import logging import re import werkzeug from pebbles.models import db, Keypair, User, ActivationToken from pebbles.forms import ChangePasswordForm, UserForm from pebbles.server import restful, app from pebbles.utils import generate_ssh_keypair, requires_admin from pebbles.views.commons import user_fields, auth, invite_user users = FlaskBlueprint('users', __name__) class UserList(restful.Resource): @staticmethod def address_list(value): return set(x for x in re.split(r",| |\n|\t", value) if x and '@' in x) parser = reqparse.RequestParser() parser.add_argument('addresses') @auth.login_required @requires_admin @marshal_with(user_fields) def post(self): form = UserForm()
from lazyblacksmith.models import ActivitySkill from lazyblacksmith.models import Blueprint from lazyblacksmith.models import Decryptor from lazyblacksmith.models import IndustryIndex from lazyblacksmith.models import Item from lazyblacksmith.models import Region from lazyblacksmith.models import SolarSystem from lazyblacksmith.models import User from lazyblacksmith.models import db from lazyblacksmith.utils.industry import calculate_base_cost from lazyblacksmith.utils.industry import calculate_build_cost from lazyblacksmith.utils.industry import get_common_industry_skill from lazyblacksmith.utils.industry import get_skill_data from lazyblacksmith.utils.models import get_regions blueprint = FlaskBlueprint('blueprint', __name__) @blueprint.route('/') def search(): """ Display the blueprint search page """ blueprints = [] has_corp_bp = False if current_user.is_authenticated: blueprints = Blueprint.query.join(User, Item).filter( ((Blueprint.character_id == current_user.character_id) | ((Blueprint.character_id == User.character_id) & (User.main_character_id == current_user.character_id)) ), ).outerjoin( ActivityProduct,
from flask import abort, g from flask import Blueprint as FlaskBlueprint from flask.ext.restful import marshal_with, fields, reqparse from pouta_blueprints.server import restful from pouta_blueprints.views.commons import auth from pouta_blueprints.utils import requires_admin from pouta_blueprints.models import db, User quota = FlaskBlueprint('quota', __name__) parser = reqparse.RequestParser() quota_update_functions = { 'absolute': lambda user, value: value, 'relative': lambda user, value: user.credits_quota + value } parser.add_argument('type') parser.add_argument('value', type=float) quota_fields = { 'id': fields.String, 'credits_quota': fields.Float, 'credits_spent': fields.Float, } def parse_arguments(): try: args = parser.parse_args() if not args['type'] in quota_update_functions.keys(): raise RuntimeError("Invalid arguement type = %s" % args['type'])
from flask import g from flask.ext.restful import fields, marshal_with from flask import Blueprint as FlaskBlueprint import logging from pebbles.models import db, Blueprint, BlueprintTemplate, Plugin, Group from pebbles.server import restful from pebbles.views.commons import auth, requires_group_manager_or_admin from pebbles.views.blueprint_templates import blueprint_schemaform_config from pebbles.utils import requires_admin from pebbles.rules import apply_rules_export_blueprints from pebbles.forms import BlueprintImportForm, BlueprintTemplateImportForm import_export = FlaskBlueprint('import_export', __name__) template_export_fields = { 'name': fields.String, 'is_enabled': fields.Boolean, 'plugin_name': fields.String, 'config': fields.Raw, 'allowed_attrs': fields.Raw } blueprint_export_fields = { 'maximum_lifetime': fields.Integer, 'name': fields.String, 'is_enabled': fields.Boolean, 'template_name': fields.String, 'config': fields.Raw, 'group_name': fields.String }
from flask.ext.restful import fields, marshal from flask import Blueprint as FlaskBlueprint import logging from pouta_blueprints.models import User from pouta_blueprints.forms import SessionCreateForm from pouta_blueprints.server import app, restful sessions = FlaskBlueprint('sessions', __name__) token_fields = { 'token': fields.String, 'user_id': fields.String, 'is_admin': fields.Boolean, } class SessionView(restful.Resource): def post(self): form = SessionCreateForm() if not form.validate_on_submit(): logging.warn("validation error on user login") return form.errors, 422 user = User.query.filter_by(email=form.email.data).first() if user and user.check_password(form.password.data): return marshal( { 'token': user.generate_auth_token( app.config['SECRET_KEY']),
from flask.ext.restful import marshal_with, reqparse from flask import abort, g from flask import Blueprint as FlaskBlueprint import logging from pebbles.models import db, Group, User, GroupUserAssociation from pebbles.forms import GroupForm from pebbles.server import restful from pebbles.views.commons import auth, group_fields, user_fields, requires_group_manager_or_admin, is_group_manager from pebbles.utils import requires_admin, requires_group_owner_or_admin import re groups = FlaskBlueprint('groups', __name__) class GroupList(restful.Resource): @auth.login_required @requires_group_manager_or_admin @marshal_with(group_fields) def get(self): user = g.user group_user_query = GroupUserAssociation.query results = [] if not user.is_admin: group_manager_objs = group_user_query.filter_by( user_id=user.id, manager=True).all() manager_groups = [ group_manager_obj.group for group_manager_obj in group_manager_objs ] groups = manager_groups else: