Beispiel #1
0
def create_school(name, country, region):
    try:
        school = School(name=name, country=country, region=region).save()
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.item_already_exists()
    return school
Beispiel #2
0
def create_activity_type(title, instructions, pdf_link, **kwargs):
    try:
        activity_type = ActivityType(title=title,
                                     instructions=instructions,
                                     pdf_link=pdf_link,
                                     **kwargs).save()
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.item_already_exists()
    return activity_type
Beispiel #3
0
def create_classroom(classname, **kwargs):
    try:
        school = current_user.profile.school
        if not school:
            raise InvalidUsage.no_associated_school()
        classroom = Classroom(classname=classname,
                              teacher=current_user.profile,
                              school=school).save()
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.item_already_exists()
    return classroom
Beispiel #4
0
def create_activity(classroom_slug, activity_name, activity_type_id, **kwargs):
    classroom = Classroom.query.filter_by(slug=classroom_slug).first()
    if not classroom:
        raise InvalidUsage.classroom_not_found()
    while True:
        code = secrets.token_hex(3)
        existing_activity = Activity.query.filter_by(code=code).first()
        if not existing_activity:
            break
    try:
        activity = Activity(activity_type_id=activity_type_id,
                            activity_name=activity_name, classroom=classroom, code=code)
        if 'reaction_to_id' in kwargs:
            reaction_to = Activity.get_by_id(kwargs['reaction_to_id'])
            activity.reaction_to = reaction_to
            activity.is_reaction = True
        activity.save()
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.item_already_exists()
    return activity