Пример #1
0
	def patch(self, config_key):
		config = Configs.query.filter_by(key=config_key).first()
		data = request.get_json()
		if config:
			schema = ConfigSchema(instance=config, partial=True)
			response = schema.load(data)
		else:
			schema = ConfigSchema()
			data['key'] = config_key
			response = schema.load(data)
			db.session.add(response.data)

		if response.errors:
			return response.errors, 400

		db.session.commit()

		response = schema.dump(response.data)
		db.session.close()

		clear_config()
		clear_standings()

		return {
			'success': True,
			'data': response.data
		}
Пример #2
0
    def patch(self):
        req = request.get_json()
        schema = ConfigSchema()

        for key, value in req.items():
            response = schema.load({"key": key, "value": value})
            if response.errors:
                return {"success": False, "errors": response.errors}, 400
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
Пример #3
0
    def post(self):
        req = request.get_json()
        schema = ConfigSchema()
        response = schema.load(req)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True, "data": response.data}
Пример #4
0
    def patch(self):
        req = request.get_json()
        schema = ConfigSchema()

        for key, value in req.items():
            response = schema.load({"key": key, "value": value})
            if response.errors:
                # Inject config key into error
                config_key = response.data["key"]
                response.errors["value"][
                    0] = f"{config_key} config is too long"
                return {"success": False, "errors": response.errors}, 400
            set_config(key=key, value=value)

        clear_config()
        clear_standings()

        return {"success": True}
Пример #5
0
    def post(self):
        req = request.get_json()
        schema = ConfigSchema()
        response = schema.load(req)

        if response.errors:
            # Inject config key into error
            config_key = response.data["key"]
            response.errors["value"][0] = f"{config_key} config is too long"
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_config()
        clear_standings()

        return {"success": True, "data": response.data}