Ejemplo n.º 1
0
def get_activity_reactions(classroom_slug, code):
    classroom = Classroom.query.filter_by(slug=classroom_slug).first()
    if not classroom:
        raise InvalidUsage.classroom_not_found()
    activity = Activity.query.filter_by(classroom=classroom, code=code).first()
    if not activity:
        raise InvalidUsage.item_not_found()
    return activity.reactions
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def get_classroom_activities(classroom_slug):
    classroom = Classroom.query.filter_by(slug=classroom_slug).first()
    if not classroom:
        raise InvalidUsage.classroom_not_found()
    return Activity.query.filter_by(classroom=classroom).all()