コード例 #1
0
ファイル: api.py プロジェクト: outhanchazima/Baobab
    def put(self):
        args = self.req_parser.parse_args()

        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_repository.get_by_id(args['id'])
        if not event:
            return EVENT_NOT_FOUND

        if event_repository.exists_by_key(
                args['key']) and args['key'] != event.key:
            return EVENT_KEY_IN_USE

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

        event.update(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'], args['travel_grant'],
                     args['miniconf_url'])
        db.session.commit()

        event = event_repository.get_by_id(event.id)
        return event, 200
コード例 #2
0
ファイル: api.py プロジェクト: outhanchazima/Baobab
    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