def main():
    """Clear the cache and repopulate it for API data."""
    for key in {'student', 'facstaff'}:
        cache.delete('provisioning_vw_{0}_api'.format(key))
        try:
            peeps = get_peeps(key)
        except Exception as error:
            print(error)
Example #2
0
def main():
    """Clear the cache and repopulate it for API data."""

    headers = {'Cache-Control': 'no-cache'}
    for key in ['student', 'facstaff']:
        cache.delete('provisioning_vw_{}_api'.format(key))
        try:
            peeps = get_peeps(key)
        except Exception as error:
            print(error)
Example #3
0
def get_facstaff():
    """Obtain faculty and staff and build a choices list for form field."""
    peeps = get_peeps('facstaff')
    facstaff = [('', '----select----')]
    for peep in peeps:
        facstaff.append((
            peep['username'],
            '{0}, {1}'.format(
                peep['lastname'],
                peep['firstname'],
            ),
        ), )
    return facstaff
Example #4
0
def people(request, who):
    '''
    Accepts: GET request where "who" = faculty/staff/facstaff/student
    Returns: all current faculty, staff, or student types
    '''

    if request.method == 'GET':
        peeps = get_peeps(who)
        response = render(request,
                          'peeps.html', {
                              'peeps': peeps,
                          },
                          content_type='application/json; charset=utf-8')
    else:
        response = HttpResponse("None",
                                content_type='text/plain; charset=utf-8')

    return response
Example #5
0
def team_manager(request, aid):
    """Manage team members."""
    alert = get_object_or_404(Alert, pk=aid)
    perms = alert.permissions(request.user)
    student = _student(alert)
    vitals = student['student']
    team = [m.user for m in alert.team.all() if m.status]
    matrix = []
    for c in alert.category.all():
        for m in c.matrix.all():
            if m.user not in matrix and m.user not in team:
                matrix.append(m.user)
    advisor = None
    eldap = LDAPManager()
    if vitals:
        try:
            advisor = User.objects.get(pk=vitals.adv_id)
        except User.DoesNotExist:
            result_data = eldap.search(vitals.ldap_name.strip(), field='cn')
            if result_data:
                groups = eldap.get_groups(result_data)
                advisor = eldap.dj_create(result_data, groups=groups)
        if advisor and advisor not in matrix and advisor not in team:
            matrix.append(advisor)

    # check if we should add admissions reps and coaches to the matrix
    admissions = False
    admissions_group = 'Admissions Representative'
    coaches = False
    coaches_group = 'Coaches'
    for c in alert.category.all():
        for g in c.group.all():
            if g.name == admissions_group:
                admissions = True
            if g.name == coaches_group:
                coaches = True

    # add admissions reps to the matrix
    if admissions:
        rep = None
        group = Group.objects.get(name=admissions_group)
        connection = get_connection()
        with connection:
            obj = xsql(ADMISSIONS_REP(cid=alert.student.id),
                       connection).fetchone()
            if obj:
                try:
                    rep = User.objects.get(pk=obj.id)
                except:
                    luser = l.search(obj.id)
                    if luser:
                        rep = l.dj_create(luser)
                if rep:
                    if not rep.groups.filter(name=admissions_group).exists():
                        group.user_set.add(rep)
                    if rep not in matrix and rep not in team:
                        matrix.append(rep)

    # add coaches to the matrix
    if coaches:
        for c in User.objects.filter(groups__name=coaches_group):
            if c not in matrix and c not in team:
                matrix.append(c)

    peeps = get_peeps('facstaff')
    folks = team + matrix
    # iterate over a copy of peeps and remove duplicates from original peeps
    for p in peeps[:]:
        for f in folks:
            if f.id == p['cid']:
                peeps.remove(p)

    return render(
        request,
        'team.html',
        {
            'data': alert,
            'perms': perms,
            'matrix': matrix,
            'return': True,
            'student': vitals,
            'sports': student['sports'],
            'peeps': peeps,
        },
    )