Пример #1
0
def workshops(db, request, coach):
    workshop1 = WorkshopModel(
        name="workshop_name_1",
        startAt=datetime(2020, 1, 1, 1, 1, 1),
        city="city_1",
        address="address1",
        eventUrl="http://www.example1.com",
        coachId=coach.id,
        creatorId=coach.id,
        model=None,
    )
    workshop2 = WorkshopModel(
        name="workshop_name_2",
        startAt=datetime(2020, 2, 2, 2, 2, 2),
        city="city_2",
        address="address2",
        eventUrl="http://www.example2.com",
        coachId=coach.id,
        creatorId=coach.id,
        model=None,
    )

    workshop1.save()
    workshop2.save()

    def teardown():
        workshop1.delete()
        workshop2.delete()

    request.addfinalizer(teardown)
    return [workshop1, workshop2]
Пример #2
0
def workshop(db, coach, model, participant, request):
    workshop_participant = WorkshopParticipantModel(
        user=participant, status=WorkshopParticipantStatus.CREATED.value)

    workshop = WorkshopModel(
        name="workshop_name_1",
        startAt=datetime(2020, 1, 1, 1, 1, 1),
        city="city_1",
        address="address1",
        eventUrl="http://www.example1.com",
        coachId=coach.id,
        creatorId=coach.id,
        model=model,
        participants=[workshop_participant],
    )
    workshop.save()
    participant.workshopParticipations.append(workshop.id)
    participant.save()

    def teardown():
        workshop.delete()

    request.addfinalizer(teardown)
    return workshop
Пример #3
0
def create_workshop(data: bytes) -> (dict, int):
    # Deserialize data
    schema = WorkshopSchema()
    data, err_msg, err_code = schema.loads_or_400(data)
    if err_msg:
        return err_msg, err_code

    # Check existence of given coachId
    coach_id = data["coachId"]
    coach = UserModel.find_by_id(coach_id)
    if coach is None:
        raise InvalidDataError("Coach does not exist : {}".format(coach_id))

    workshop = WorkshopModel(**data)
    # Append creator id
    workshop.creatorId = get_jwt_identity()
    # Append last created model id
    model = Model.find_last_created_model()
    workshop.model = model

    workshop.save()

    workshop.reload()
    return schema.dump(workshop), 200