@expose("/find_from_commit_and_record/<form_id>", methods=['GET']) def find_from_commit_and_record(self, form_id): """ 查询数据提交和浏览数据 :param form_id: :return: """ form = self.form_service.fetch_form(form_id) commit_count = len(form.fields) record_count = form.record_count return self.response(200, **{"commit_count": commit_count, "record_count": record_count}) @expose("/one_minute_commit/<form_id>", methods=['GET']) def one_minute_commit(self, form_id): """ 一分钟提交的数据量 :param form_id: :return: """ fields = self.form_service.one_minute_commit(form_id) return jsonify(fields.asdict()) @expose('/<form_id>', methods=['DELETE']) def delete(self, form_id): """Delete a form """ form = self.form_service.remove_form(form_id) return jsonify(form.asdict()) appbuilder.add_api(ControlPanelFormApi)
return jsonify( form.asdict(follow={ 'fields': { "follow": { "options": {}, "constraints": {}, } } })) @expose('/{id}/value', methods=['POST']) def submit(self): """Submit a form --- post: responses: 200: description: Submit form list content: application/json: schema: type: object properties: message: type: string """ pass appbuilder.add_api(FormApi)
@expose('<field_id>', methods=['PUT']) def update(self, field_id): changed = self.form_service.change_field(field_id, request.json) return jsonify(changed.asdict()) @expose('<field_id>', methods=['DELETE']) def delete(self, field_id): field = self.form_service.remove_field(field_id) return jsonify(field.asdict()) @expose('<field_id>') def get(self, field_id): """Get a form --- get: responses: 200: description: Get a form content: application/json: schema: $ref: '#/components/schemas/Field' """ field = self.form_service.fetch_field(field_id) return jsonify(field.asdict()) appbuilder.add_api(ControlPanelFieldApi)
""" return jsonify({}) @expose('/<value_id>', methods=["DELETE"]) def delete(self, value_id): """ --- delete: summary: "删除表格数据" description: "删除表格数据" parameters: - name: value_id in: path type: integer format: int64 description: "Value 主键ID" responses: 200: content: application/json: schema: $ref: "#/components/schemas/Value" """ return jsonify({}) @expose('/<value_id>') def duplicate(self, value_id): return jsonify({}) appbuilder.add_api(ControlPanelValueApi)
appbuilder.add_view(ContactModelView, "List Contacts", icon="fa-envelope", category="Contacts") from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_appbuilder.api import ModelRestApi from . import appbuilder class GroupModelApi(ModelRestApi): resource_name = 'group' datamodel = SQLAInterface(ContactGroup) appbuilder.add_api(GroupModelApi) """ Application wide 404 error handler """ @appbuilder.app.errorhandler(404) def page_not_found(e): return ( render_template("404.html", base_template=appbuilder.base_template, appbuilder=appbuilder), 404, )
#provider = request.json.get(API_SECURITY_PROVIDER_KEY, None) #refresh = request.json.get(API_SECURITY_REFRESH_KEY, False) #if not username or not password or not provider: # return self.response_400(message="Missing required parameter") ## AUTH #if provider == API_SECURITY_PROVIDER_DB: # user = self.appbuilder.sm.auth_user_db(username, password) #elif provider == API_SECURITY_PROVIDER_LDAP: # user = self.appbuilder.sm.auth_user_ldap(username, password) #else: # return self.response_400( # message="Provider {} not supported".format(provider) # ) #if not user: # return self.response_401() ## Identity can be any data that is json serializable #resp = dict() #resp[API_SECURITY_ACCESS_TOKEN_KEY] = create_access_token( # identity=user.id, fresh=True #) #if refresh: # resp[API_SECURITY_REFRESH_TOKEN_KEY] = create_refresh_token( # identity=user.id # ) #return self.response(200, **resp) appbuilder.add_api(ProjectModelApi) #
from flask import jsonify from flask_appbuilder.api import BaseApi, expose from app import appbuilder from app.services.form_analysis import FormAnalysisService class FormAnalysisApi(BaseApi): resource_name = 'cp/form/analysis' service = FormAnalysisService() @expose('/<int:form_id>') def index(self, form_id: int): result = [] for item in self.service.fetch(form_id): result.append({ 'field_id': int(item.field_id), 'option_id': int(item.option_id), 'count': int(item.count) }) print(result) return jsonify(result) appbuilder.add_api(FormAnalysisApi)
"""Get a form --- get: responses: 200: description: 查询表单协作的角色 content: application/json: schema: $ref: "#/components/schemas/Form" """ roles = self.form_service.all_roles() return jsonify([role.asdict() for role in roles]) appbuilder.add_api(ControlPanelFormRoleApi) class CollaborationAssembler: def to_dto(self, collaborator): return { 'id': collaborator.id, "user": { 'id': collaborator.user.id, 'username': collaborator.user.username, }, 'role': { 'name': collaborator.role.name, 'id': collaborator.role.id, }, 'form_id': collaborator.form_id,
{ "bucket": os.getenv("OSS_BUCKET"), "key": self.key, }, ["content-length-range", 0, 1048576], ] } policy_string = json.dumps(policy) self.policy_base64 = self._convert_base64(policy_string) self.signature = self._get_sign_policy(self.policy_base64) def _convert_base64(self, input): return base64.b64encode(input.encode("utf-8")) def _get_sign_policy(self, policy): hash_object = hmac.new(self.access_key_secret.encode(), policy, hashlib.sha1) hash_value = hash_object.digest() return base64.b64encode(hash_value).decode("utf-8") class StorageAPI(BaseApi): resource_name = 'storage' @expose("signature", methods=["POST"]) def signature(self): keys = request.form.getlist("key[]") signatures = [(Signature(key, OSS_ACCESS_KEY_SECRET)).asdict() for key in keys] return jsonify(signatures) appbuilder.add_api(StorageAPI)
# } # } if not request.is_json: return self.response_400(message="Request payload is not JSON") rid = request.json.get('rid', None) message = "" if not rid: return self.response_400(message="Missing required parameter") socket_emit = request.json.get('socket_emit', None) if socket_emit: action = socket_emit.get('action', None) p = socket_emit.get('p', {}) if action == 'heartbeat': is_alive = p.get('is_alive', 0) friend_id = resp_heartbeat(rid, is_alive, False) message = {'action' : action, 'p': friend_id} elif action == 'sync_status': me_id = socket_emit.get('me_id', -1) status = p.get('status', '') info = p.get('info', '') sync_status(me_id, rid, status, info) return self.response(200, message=message) appbuilder.add_api(ContactModelApi)
from flask_appbuilder.api import BaseApi, expose from app import appbuilder from flask import (request, jsonify) class ControlPanelReporterApi(BaseApi): resource_name = "cp/form/<form_id>/reporter" @expose('/') def get(self, form_id): """ get: description: "查询报表" responses: 200: content: application/json: schema: type: "string" """ data = {} return jsonify(data) appbuilder.add_api(ControlPanelReporterApi)