예제 #1
0
        Parameters
        ----------
        _name : str

        Returns
        -------

        """
        if not _name:
            report_request = ReportRequest('sessions-per-user-by-date')
        else:
            try:
                report_request = ReportRequest(_name)
            except KeyError:
                return abort(404)
        try:
            report = Report(service, report_request)
        except HttpError as e:
            return e, abort(400)
        report.parse()
        report_file = report.export()
        return send_from_directory(DOWNLOAD_DIR, report_file, as_attachment=True)


report_endpoint = endpoint_getter(ReportView)
report_url = url_getter(ReportView)
report_converter = 'string'
report_key = '_name'

report_view_func = ReportView.as_view(report_endpoint)
        Parameters
        ----------
        _id

        Returns
        -------

        """
        data = request.get_json()
        if not User.validate_delete_data(data):
            return abort(400)
        s = session()
        if not id_validator(_id, s, User):
            return abort(404)
        user = s.query(User).filter_by(id=_id).first()
        pw = data.get('password')
        if not user.authenticate(pw):
            return abort(401)
        s.delete(user)
        s.commit()
        return make_response(jsonify('Resource deleted successfully.'), 202)


user_endpoint = endpoint_getter(UserView)
user_converter = UserView.converter
user_key = UserView.key
user_url = url_getter(UserView)

user_view_func = UserView.as_view(user_endpoint)
예제 #3
0
from tcas.helper.url_getter import url_getter


class ClusteringView(BlueprintRouterMixin, MethodView):
    """Provides view of clustering analysis for a given entity.
    """

    def __init__(self, entity):
        self.entity = entity

    def get(self):
        """Run clustering task asynchronously
        Returns
        -------
        """
        if self.entity == 'goal':
            async_task = cluster_goals.apply_async()
            return make_response(jsonify({
                'uri': url_for('admin.task_view', _id=async_task.id, task_name=__name__)
            }), 200)
        else:
            return abort(400)


clustering_endpoint = endpoint_getter(ClusteringView)
clustering_url = url_getter(ClusteringView)
clustering_converter = ClusteringView.converter
clustering_key = ClusteringView.key

clustering_view_func = ClusteringView.as_view(clustering_endpoint, 'goal')
예제 #4
0
        """Detroys an Upload resource.

        Parameters
        ----------
        _id

        Returns
        -------

        """
        if Upload.validate_delete_data(request.get_json()):
            s = session()
            data = request.get_json()
        else:
            return abort(400)
        if id_validator(_id, s, Upload):
            upload = s.query(Upload).filter_by(id=_id).first()
        else:
            return abort(404)
        s.delete(upload)
        s.commit()
        return make_response(jsonify('Resource deleted successfully'), 202)


upload_endpoint = endpoint_getter(UploadView)
upload_url = url_getter(UploadView)
upload_converter = UploadView.converter
upload_key = UploadView.key

upload_view_func = UploadView.as_view(upload_endpoint)
    """Provides view of Case entities by abstracting from uploaded data.
    """
    def get(self, _id):
        """ Reads a specified Case resource, or else all Case resources.

        Parameters
        ----------
        _id

        Returns
        -------

        """
        if _id is None:
            return jsonify([user.serialize() for user in Case.query.all()])
        else:
            return jsonify(Case.query.filter_by(id=_id).all())

    def post(self):
        """ Creates Case resources by running the case abstraction task asynchronously.
        """
        task = abstract_cases.apply_async(args=['arg'])
        return url_for('abstract.case_view', _id=task.id)


case_endpoint = endpoint_getter(CaseView)
case_url = url_getter(CaseView)
case_converter = CaseView.converter
case_key = CaseView.key
case_view_func = CaseView.as_view(case_endpoint)
from flask.views import MethodView
from tcas.helper.blueprint_router_mixin import BlueprintRouterMixin
from tcas.abstract.model.goal import Goal
from tcas.helper.endpoint_getter import endpoint_getter
from tcas.helper.url_getter import url_getter


class GoalView(BlueprintRouterMixin, MethodView):
    def get(self, _id):
        """Reads specified Goal resource or else returns all Goal resources.

        Parameters
        ----------
        _id

        Returns
        -------

        """
        if _id is None:
            return jsonify([user.serialize() for user in Goal.query.all()])
        else:
            return jsonify(Goal.query.filter_by(id=_id).all())


goal_endpoint = endpoint_getter(GoalView)
goal_url = url_getter(GoalView)
goal_converter = GoalView.converter
goal_key = GoalView.key
goal_view_func = GoalView.as_view(goal_endpoint)