Пример #1
0
    def post(self):
        ret = None
        data = request.get_json(True)
        expected = ['schema', 'data', 'status']
        for i in expected:
            if i not in data.keys():
                raise ValueError("%s not found" % i)

        # get schema
        schema_id = ObjectId(data["schema"])
        schema_coll = get_schema_coll()
        schema = schema_coll.find_one({"_id": schema_id})
        logging.debug(schema)
        if not schema:
            raise Exception("schema '%s' not found" % data['schema'])

        # check status
        if data['status'] not in schema['status_list']:
            msg = "status '%s'not found on schema '%s'. Expected: '%s'"
            msg = msg % (data['status'], schema['name'], schema['status_list'])
            raise Exception(msg)

        data['open_date'] = datetime.datetime.now()
        logging.debug(data)

        collection = get_ticket_coll()
        collection.insert_one(data)
        self.pub(data)
        return output_json({'success': True}, 200)
Пример #2
0
    def post(self):
        ret = None
        data = request.get_json(True)
        expected = ["schema", "data", "status"]
        for i in expected:
            if i not in data.keys():
                raise ValueError("%s not found" % i)

        # get schema
        schema_id = ObjectId(data["schema"])
        schema_coll = get_schema_coll()
        schema = schema_coll.find_one({"_id": schema_id})
        logging.debug(schema)
        if not schema:
            raise Exception("schema '%s' not found" % data["schema"])

        # check status
        if data["status"] not in schema["status_list"]:
            msg = "status '%s'not found on schema '%s'. Expected: '%s'"
            msg = msg % (data["status"], schema["name"], schema["status_list"])
            raise Exception(msg)

        data["open_date"] = datetime.datetime.now()
        logging.debug(data)

        collection = get_ticket_coll()
        collection.insert_one(data)
        self.pub(data)
        return output_json({"success": True}, 200)
Пример #3
0
    def post(self):
        data = request.get_json(True)
        self.validate_post(data)
        data = self.clear_data(data)

        schema_coll = get_schema_coll()
        ret = schema_coll.insert_one(data)

        return output_json({'success': True}, 200)
Пример #4
0
 def get(self, _id=None):
     if _id is not None:
         return self._get_one(_id)
     schema_coll = get_schema_coll()
     ret = schema_coll.find()
     return output_json(ret, 200)
Пример #5
0
 def _get_one(self, _id):
     logging.debug("Getting just one: %s " % _id)
     _id = ObjectId(_id)
     coll = get_schema_coll()
     ret = coll.find_one({"_id": _id})
     return output_json(ret, 200)