Ejemplo n.º 1
0
def aboutme(request):
    user = AuthService.get_current_user(request)
    
    context = { 'user': user }
    login_as =""
    if user.local_user.is_authenticated:
        context['show_color'] = user.local_user.is_authenticated
        context['colors'] = constant.favorite_colors        
        context['favorite_color'] = user_service.get_favorite_color(user.user_id)
    if user.is_admin:
        login_as ="Admin"
    if not user.is_admin and user.o365_user is not None:
        token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)        
        education_service = EducationService(user.tenant_id, token)            
        me = education_service.get_me() 
        my_school_id = me.schools[0].id
        
        if me.is_teacher:
            login_as="Teacher"
        if me.is_student:
            login_as="Student"
        
        context['me'] = me
        context['groups'] = education_service.get_my_classes(my_school_id)
    else:
        context['groups'] = []
    context['login_as'] = login_as
    context['role']=login_as
    return render(request, 'managements/aboutme.html', context)
Ejemplo n.º 2
0
def classes(request, school_id):
    user = AuthService.get_current_user(request)
    token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)
    education_service = EducationService(user.tenant_id, token)
    me = education_service.get_me()
    role = get_user_role(user, me)
    education_service = EducationService(user.tenant_id, token)
    school = education_service.get_school(school_id)
    my_classes = education_service.get_my_classes(school_id)
    all_classes, classesnextlink = education_service.get_classes(school_id, 12)

    for c in all_classes:
        my_class = next((mc for mc in my_classes if c.id == mc.id), None)
        c.custom_data['is_my'] = my_class != None
        if my_class != None:
            c.members = my_class.members

    context = {
        'user': user,
        'school': school,
        'classesnextlink': classesnextlink,
        'classes': all_classes,
        'myclasses': my_classes,
        'school_id': school_id,
        'is_in_a_school': True,
        'me': me,
        'role':role
    }
    return render(request, 'schools/classes.html', context)
Ejemplo n.º 3
0
 def _get_roles(self, tenant_id, user_id):
     roles = []
     # check if the user is an admin
     directory_roles = self._get_directory_roles()
     admin_role = next(
         r for r in directory_roles
         if r.display_name == constant.company_admin_role_name)
     if admin_role:
         members = admin_role.to_dict()['members']
         if any(m for m in members if m['id'] == user_id):
             roles.append(constant.Roles.Admin)
     # check if the user is a faculty or a student
     education_service = EducationService(tenant_id, self.access_token)
     me = education_service.get_me()
     if me:
         if me.is_teacher:
             roles.append(constant.Roles.Faculty)
         if me.is_student:
             roles.append(constant.Roles.Student)
     return roles
Ejemplo n.º 4
0
def schools(request):   
    user = AuthService.get_current_user(request)
    token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)

    education_service = EducationService(user.tenant_id, token)
    me = education_service.get_me()

    schools = education_service.get_schools()
    for school in schools:
        school.custom_data['is_my'] = me.is_in_school(school.id)

    # sort schools: my school will be put to the top
    schools.sort(key=lambda s:s.display_name if me.is_in_school(s.id) else 'Z_' + s.display_name)
    role = get_user_role(user, me)
    context = {
        'user': user,
        'me': me,
        'role':role,
        'schools': schools
    }
    return render(request, 'schools/index.html', context)
Ejemplo n.º 5
0
def class_details(request, school_id, class_id):
    user = AuthService.get_current_user(request)
    token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)
    education_service = EducationService(user.tenant_id, token)
    me = education_service.get_me()
    role = get_user_role(user, me)
    token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)
    education_service = EducationService(user.tenant_id, token)

    school = education_service.get_school(school_id)
    current_class = education_service.get_class(class_id)    
    members = education_service.get_class_members(class_id)
    teachers = [m for m in members if m.primary_role == 'teacher']
    students = [m for m in members if m.primary_role == 'student']    
    
    # set favorite colors and seating positions
    for student in students:
        favorite_color = user_service.get_favorite_color_by_o365_user_id(student.id)
        if favorite_color:
            student.custom_data['favorite_color'] = favorite_color
        seating_position = user_service.get_seating_position(student.id, class_id)
        if not seating_position:
            seating_position = 0
        student.custom_data['position'] = seating_position
   
    assignments = education_service.get_assignments(class_id)
    for assignment in assignments: 
        if assignment.dueDateTime !=None:      
            assignment.dueDateTimeLocal = datetime_from_utc_to_local(datetime.strptime(assignment.dueDateTime, '%Y-%m-%dT%H:%M:%SZ')).strftime("%m/%d/%Y")



    all_teachers = education_service.get_teachers(school.number)
    filtered_teachers = [t for t in all_teachers if all(t.id != i.id for i in teachers)]

    # set seatrange
    seatrange = range(1, 37)

    ms_token = token_service.get_access_token(constant.Resources.MSGraph, user.o365_user_id)
    ms_graph_service = MSGraphService(ms_token)

    documents = ms_graph_service.get_documents(class_id)
    documents_root = ms_graph_service.get_documents_root(class_id)
    conversations = ms_graph_service.get_conversations(class_id)
    for conversation in conversations:
        conversation.custom_data['url'] = ms_graph_service.get_conversations_url(conversation.id, current_class.mail_nickname)
    conversations_root = ms_graph_service.get_conversations_root(current_class.mail_nickname)

    favorite_color = user_service.get_favorite_color_by_o365_user_id(user.o365_user_id)

    context = {
        'user': user,
        'me': me,
        'role':role,
        'is_student':me.is_student,
        'school': school,
        'class': current_class,
        'teachers': teachers,
        'students': students,
        'documents': documents,
        'documents_root': documents_root,
        'conversations': conversations,
        'conversations_root': conversations_root,
        'seatrange': seatrange,
        'school_id': school_id,
        'class_id': class_id,
        'is_in_a_school': True,
        'favorite_color': favorite_color,
        'filtered_teachers': filtered_teachers,
        'assignments' : assignments
    }
    return render(request, 'schools/classdetails.html', context)