def post(self):
        """**Create a EventType entry**

        **Example Request:**

        .. sourcecode:: http

            POST /api/v1/eventtypes HTTP/1.1
            Host: localhost
            Content-Type: application/json
            {
                "category": "system-reboot",
                "state": "required",
                "description": "System requires a reboot.",
            }

        or:

        .. sourcecode:: http

            {
                "eventTypes": [
                    {
                        "category": "foo",
                        "state": "bar",
                        "description": "Some description"

                    },
                    {
                        "category": "foo",
                        "state": "baz",
                        "description": "Some description",
                         "restricted": true,
                    },
                    {
                        "category": "tango",
                        "state": "foxtrot",
                        "description": "Some description"
                    }
                ]
            }

        **Example response:**

        .. sourcecode:: http

            HTTP/1.1 201 OK
            Location: /api/v1/eventtypes/1

            {
                "status": "created",
                "id": 1,
                "category": "system-reboot",
                "state": "required",
                "description": "System requires a reboot.",
                "restricted": false,
            }

        or:

        .. sourcecode:: http

            {
                "status": "created",
                "eventTypes":
                [
                    {
                        "category": "foo",
                        "state": "bar",
                        "href": "/api/v1/eventtypes/7",
                        "id": 7,
                        "description": "Some description",
                        "restricted": false,
                    },
                    {
                        "category": "foo",
                        "state": "baz",
                        "href": "/api/v1/eventtypes/8",
                        "id": 8,
                        "description": "Some description",
                        "restricted": true,
                    },
                    {
                        "category": "tango",
                        "state": "foxtrot",
                        "href": "/api/v1/eventtypes/9",
                        "id": 9,
                        "description": "Some description",
                        "restricted": false,
                    }
                ],
                "totalEventTypes": 3
            }

        :reqjson string category: The category value of the EventType
        :regjson string state: The state value of the EventType
        :regjson string description: The human readable description of the EventType
        :regjson boolean restricted: (*optional*) If true, the EventType
                                    created will be restricted such that
                                    only direct API calls can throw events of
                                    that type (and the CLI/WebGUI would refuse)

        :reqheader Content-Type: The server expects a json body specified with
                                 this header.

        :resheader Location: URL to the created resource.

        :statuscode 201: The site was successfully created.
        :statuscode 400: The request was malformed.
        :statuscode 401: The request was made without being logged in.
        :statuscode 409: There was a conflict with another resource.
        """

        try:
            if "eventTypes" in self.jbody:
                event_types = self.jbody["eventTypes"]
            else:
                event_types = [
                    {
                        "category": self.jbody["category"],
                        "state": self.jbody["state"],
                        "description": self.jbody["description"],
                        "restricted": self.jbody.get("restricted", False)
                    }
                ]

        except KeyError as err:
            raise exc.BadRequest(
                "Missing Required Argument: {}".format(err.message)
            )
        except ValueError as err:
            raise exc.BadRequest(err.message)

        log.info("EVENTTYPE: Creating {}".format(", ".join(
            [
                "{} {}".format(event_type['category'], event_type['state'])
                for event_type in event_types
            ]
        )))

        try:
            created_types = []
            for x in range(0, len(event_types)):
                created_type = EventType.create(
                    self.session, event_types[x]["category"],
                    event_types[x]["state"],
                    description=event_types[x]["description"],
                    restricted=event_types[x].get("restricted", False)
                )
                created_types.append(created_type.to_dict(self.href_prefix))
        except IntegrityError as err:
            if "Duplicate" in err.message:
                raise exc.Conflict("Cannot create duplicate event type")
            else:
                raise exc.Conflict(err.message)
        except exc.ValidationError as err:
            raise exc.BadRequest(err.message)

        self.session.commit()

        if len(created_types) == 1:
            json = created_types[0]
            self.created(
                "/api/v1/eventtypes/{}".format(created_types[0]["id"]), json
            )
        else:
            self.created(
                data={
                    "eventTypes": created_types,
                    "totalEventTypes": len(event_types)
                }
            )

        log.info("EVENTTYPE: Created {}".format(", ".join(
            [
                "{} {}".format(event_type['category'], event_type['state']) for event_type in event_types
            ]
        )))
dataset/ETHPy150Open dropbox/hermes/hermes/handlers/api.py/EventTypesHandler.post/original