def reset_standings(semester=None, pool_hours=None):
    """
    Utility function to recalculate workshift standings. This function is meant
    to only be called from the manager shell, it is not referenced anywhere
    else in the workshift module.

    Parameters
    ----------
    semester : workshift.models.Semester, optional
    pool_hours : list of workshift.models.PoolHours, optional
    """
    if semester is None:
        try:
            semester = Semester.objects.get(current=True)
        except (Semester.DoesNotExist, Semester.MultipleObjectsReturned):
            return
    if pool_hours is None:
        pool_hours = PoolHours.objects.filter(pool__semester=semester)

    for hours in pool_hours:
        hours.last_updated = None
        hours.standing = hours.hour_adjustment

        profile = WorkshiftProfile.objects.get(pool_hours=hours)

        instances = WorkshiftInstance.objects.filter(
            Q(weekly_workshift__pool=hours.pool) |
            Q(info__pool=hours.pool),
            Q(workshifter=profile) | Q(liable=profile),
            closed=True,
        )
        for instance in instances:
            if instance.blown:
                hours.standing -= instance.hours
            else:
                hours.standing += instance.hours

        hours.save(update_fields=["standing", "last_updated"])

    update_standings(
        semester=semester,
        pool_hours=pool_hours,
    )
def reset_standings ( semester = None , pool_hours = None ) : if semester is None : try : semester = Semester . objects . get ( current = True ) except ( Semester . DoesNotExist , Semester . MultipleObjectsReturned ) : return if pool_hours is None : pool_hours = PoolHours . objects . filter ( pool__semester = semester ) for hours in pool_hours : hours . last_updated = None hours . standing = hours . hour_adjustment profile = WorkshiftProfile . objects . get ( pool_hours = hours ) instances = WorkshiftInstance . objects . filter ( Q ( weekly_workshift__pool = hours . pool ) | Q ( info__pool = hours . pool ) , Q ( workshifter = profile ) | Q ( liable = profile ) , closed = True , ) for instance in instances : if instance . blown : hours . standing -= instance . hours else : hours . standing += instance . hours hours . save ( update_fields = [ "standing" , "last_updated" ] ) update_standings ( semester = semester , pool_hours = pool_hours , )
Utility function to recalculate workshift standings. This function is meant
    to only be called from the manager shell, it is not referenced anywhere
    else in the workshift module.

    Parameters
    ----------
    semester : workshift.models.Semester, optional
    pool_hours : list of workshift.models.PoolHours, optional