Esempio n. 1
0
    def get(self, id=None):
        if id:
            log, error = Log.get_one(self,
                                     id=id,
                                     q_params=self.query_params,
                                     user=self.current_user)
            if not log:
                return

            data = {
                'log':
                get_data_as_json(log,
                                 user_type=self.user_type,
                                 include=self.include,
                                 exclude=self.exclude)
            }
        else:
            logs_pagin, error = Log.get(q_params=self.query_params,
                                        order=self.order,
                                        user=self.current_user,
                                        pagination=self.pagination)
            data = {
                'logs':
                get_data_as_json(logs_pagin.items,
                                 user_type=self.user_type,
                                 include=self.include,
                                 exclude=self.exclude),
                'pagination':
                get_pagination_as_json(logs_pagin)
            }

        return self.finish(make_rest(data, None))
Esempio n. 2
0
    def get(self, id=None):
        if id:
            log, error = Log.get_one(self, id=id,
                                q_params=self.query_params,
                                user=self.current_user
                                )
            if not log:
                return

            data = {
                    'log': get_data_as_json(
                                        log,
                                        user_type=self.user_type,
                                        include=self.include,
                                        exclude=self.exclude)
                    }
        else:
            logs_pagin, error = Log.get(
                            q_params=self.query_params,
                            order=self.order,
                            user=self.current_user,
                            pagination=self.pagination
                            )
            data = {
                    'logs': get_data_as_json(
                                        logs_pagin.items,
                                        user_type=self.user_type,
                                        include=self.include,
                                        exclude=self.exclude),
                    'pagination': get_pagination_as_json(logs_pagin)
                    }

        return self.finish(make_rest(data, None))
Esempio n. 3
0
    def put(self, id):
        client, error = Client.get_one(id)

        if not client:
            return self.return_rest(
                None, {'id': 'There is not the requested id: ' + id}, 404)

        form = UpdateClientForm(self, obj=client)
        if form.validate():
            form.populate_obj(client)

            client.password = form.password.data
            Client.update(client, self.current_user)

            data = {
                'client':
                get_data_as_json(client,
                                 user_type=self.user_type,
                                 include=self.include,
                                 exclude=self.exclude)
            }

            return self.finish(make_rest(data, None))

        return self.return_rest(None, form.errors, 400)
Esempio n. 4
0
    def post(self, id=None):
        form = CreateClientForm(self)
        if form.validate():
            client = Client()
            form.populate_obj(client)

            client.password = form.password.data
            Client.add(client, self.current_user)

            data = {
                    'client': get_data_as_json(
                                        client,
                                        user_type=self.user_type,
                                        include=self.include,
                                        exclude=self.exclude)
                    }

            return self.finish(make_rest(data, None))

        return self.return_rest(None, form.errors, 400)
Esempio n. 5
0
    def post(self, id=None):
        form = CreateClientForm(self)
        if form.validate():
            client = Client()
            form.populate_obj(client)

            client.password = form.password.data
            Client.add(client, self.current_user)

            data = {
                'client':
                get_data_as_json(client,
                                 user_type=self.user_type,
                                 include=self.include,
                                 exclude=self.exclude)
            }

            return self.finish(make_rest(data, None))

        return self.return_rest(None, form.errors, 400)
Esempio n. 6
0
    def put(self, id):
        client, error = Client.get_one(id)

        if not client:
            return self.return_rest(None, {'id': 'There is not the requested id: ' + id}, 404)

        form = UpdateClientForm(self, obj=client)
        if form.validate():
            form.populate_obj(client)

            client.password = form.password.data
            Client.update(client, self.current_user)

            data = {
                    'client': get_data_as_json(
                                        client,
                                        user_type=self.user_type,
                                        include=self.include,
                                        exclude=self.exclude)
                    }

            return self.finish(make_rest(data, None))

        return self.return_rest(None, form.errors, 400)