Exemple #1
0
Fichier : orm.py Projet : wmv/omega
    def handle_get_collection(self, request):
        """Return a response for a get request on the entire collection.

        :param request: The incoming Request object.

        """

        resources = self._session.query(self.cls).all()
        self.template = self.env.get_template('resources.html')

        return make_response(
            self.template.render(
                resources=resources, form=self.form(), name=self.cls.__name__))
Exemple #2
0
Fichier : orm.py Projet : wmv/omega
    def handle_get(self, request, primary_key):
        """Return a response for a get request for a specific resource.

        :param request: The incoming Request object
        :param primary_key: The primary_key of the ORM model to retrieve

        """

        resource = self._session.query(self.cls).get(primary_key)
        if not resource:
            return None
        self.template = self.env.get_template('resource.html')
        form = self.form(request.form, resource)
        return make_response(self.template.render(
            resource=resource, name=self.name, form=form))
Exemple #3
0
Fichier : orm.py Projet : wmv/omega
    def handle_patch(self, request, primary_key):
        """Return a :class:`werkzeug.Response` object after handling the PUT
        call.

        :param request: The incoming Request object.
        :param primary_key: The primary_key of the ORM model to retrieve

        """

        resource = self._session.query(self.cls).get(primary_key)
        if resource:
            for field, value in request.form.items():
                setattr(resource, field, value)
        else:
            resource = self.cls(request.form)
        error = self.validate_data(resource)
        if error:
            return None
        self._session.add(resource)
        self._session.commit()
        template = self.env.get_template('resource.html')

        return make_response(template.render(resource=resource))
Exemple #4
0
 def __call__(self, request):
     return make_response(self.template.render())
Exemple #5
0
 def __call__(self, *args, **kwargs):
     file_path = kwargs['file_path']
     with open(os.path.join('static', file_path), 'r') as file_handle:
         response = make_response(file_handle.read())
         response.headers['Content-type'] = mimetype_for_path(file_path)
         return response
Exemple #6
0
def bad_request(message):
    response = make_response(json.dumps({'status': 'ERR', 'message': message}))
    response.status_code = 400
    response.headers = {'Content-type': 'application/json'}
    return response