示例#1
0
    def post(self):
        args = self.req_parser.parse_args()

        user_id = g.current_user["id"]
        current_user = user_repository.get_by_id(user_id)
        if not current_user.is_admin:
            return FORBIDDEN

        if event_repository.exists_by_key(args['key']):
            return EVENT_KEY_IN_USE

        if len(args['name']) == 0 or len(args['description']) == 0:
            return EVENT_MUST_CONTAIN_TRANSLATION

        if set(args['name']) != set(args['description']):
            return EVENT_TRANSLATION_MISMATCH

        event = Event(args['name'], args['description'], args['start_date'],
                      args['end_date'], args['key'], args['organisation_id'],
                      args['email_from'], args['url'],
                      args['application_open'], args['application_close'],
                      args['review_open'], args['review_close'],
                      args['selection_open'], args['selection_close'],
                      args['offer_open'], args['offer_close'],
                      args['registration_open'], args['registration_close'],
                      EventType[args['event_type'].upper()],
                      args['travel_grant'], args['miniconf_url'])

        event.add_event_role('admin', user_id)
        event = event_repository.add(event)

        event = event_repository.get_by_id(event.id)
        return event, 201
示例#2
0
    def post(self):
        args = self.req_parser.parse_args()

        user_id = g.current_user["id"]
        current_user = user_repository.get_by_id(user_id)
        if not current_user.is_admin:
            return FORBIDDEN

        _date_format = '%Y-%m-%dT%H:%M:%S.%fZ'
        name = args['name']
        description = args['description']
        start_date = datetime.strptime((args['start_date']), _date_format)
        end_date = datetime.strptime((args['end_date']), _date_format)
        key = args['key']
        organisation_id = args['organisation_id']
        email_from = args['email_from']
        url = args['url']
        application_open = datetime.strptime((args['application_open']),
                                             _date_format)
        application_close = datetime.strptime((args['application_close']),
                                              _date_format)
        review_open = datetime.strptime((args['review_open']), _date_format)
        review_close = datetime.strptime((args['review_close']), _date_format)
        selection_open = datetime.strptime((args['selection_open']),
                                           _date_format)
        selection_close = datetime.strptime((args['selection_close']),
                                            _date_format)
        offer_open = datetime.strptime((args['offer_open']), _date_format)
        offer_close = datetime.strptime((args['offer_close']), _date_format)
        registration_open = datetime.strptime((args['registration_open']),
                                              _date_format)
        registration_close = datetime.strptime((args['registration_close']),
                                               _date_format)
        event_type = args['event_type'].upper()

        event = Event(name, description, start_date, end_date, key,
                      organisation_id, email_from, url, application_open,
                      application_close, review_open, review_close,
                      selection_open, selection_close, offer_open, offer_close,
                      registration_open, registration_close,
                      EventType[event_type])
        event.add_event_role('admin', user_id)
        try:
            event = event_repository.add(event)
        except IntegrityError as e:

            LOGGER.error("Event with KEY: {} already exists".format(key))
            LOGGER.error(e)
            return EVENT_KEY_IN_USE

        event_org = event_repository.get_by_id_with_organisation(event.id)
        return event_details(event_org), 201