コード例 #1
0
def department_profile(request,
                       id,
                       template="university_system/departments/profile.html"):
    auth_user = auth_user_manager.get(request.session.get('token', None))
    if auth_user is not None and auth_user.has_permission(
            permissions.Scope.department, permissions.Crud.read):
        department_info = department_info_manager.get(id)
        department = department_manager.get(department_info.department_id)
        return render(
            request, template, {
                'department': department,
                'department_info': department_info,
                'auth_user': auth_user
            })
    else:
        raise PermissionDenied
コード例 #2
0
def achievements_by(request,
                    template,
                    scope=permissions.Scope.achievement,
                    department_info_id=None,
                    user_info_id=None):
    auth_user = auth_user_manager.get(request.session.get('token', None))
    if auth_user is not None and auth_user.has_permission(
            scope, permissions.Crud.read):
        dirty_achievements = []
        clean_achievements = []
        user_info = None
        department_info = None
        if department_info_id is not None:
            department_info = department_info_manager.get(department_info_id)
            department = department_manager.get(department_info.department_id)
            for user_info_id in department.users_info_id:
                user_achievements = achievement_manager.search(
                    'user_info_id', user_info_id)
                if user_achievements is not None:
                    dirty_achievements.extend(
                        achievement_manager.search('user_info_id',
                                                   user_info_id))

        else:
            if user_info_id is None:
                user_info_id = auth_user.info_id
            user_info = user_info_manager.get(user_info_id)
            user_achievements = achievement_manager.search(
                'user_info_id', user_info_id)
            if user_achievements is not None:
                dirty_achievements.extend(user_achievements)

        for achievement in dirty_achievements:
            clean_achievements.append(
                form_converter.get_without_enums(achievement))

        return render(request,
                      template,
                      context={
                          'achievements': clean_achievements,
                          'auth_user': auth_user,
                          'user_info': user_info,
                          'department_info': department_info
                      })
    else:
        raise PermissionDenied
コード例 #3
0
def users_by_department(request,
                        department_info_id,
                        template,
                        scope=permissions.Scope.student):
    auth_user = auth_user_manager.get(request.session.get('token'))
    if auth_user is not None and auth_user.has_permission(
            scope, permissions.Crud.read):
        department_info = department_info_manager.get(department_info_id)
        department = department_manager.get(department_info.department_id)
        users_info = []
        for id in department.users_info_id:
            users_info.append(user_info_manager.get(id))

        return render(request,
                      template,
                      context={
                          'users_info': users_info,
                          'auth_user': auth_user
                      })
    else:
        raise PermissionDenied
コード例 #4
0
def parent_department_id_by_user(id):
    user_info = user_info_manager.get(id)
    department = department_manager.get(user_info.department_id)
    parent = department_manager.get(department.parent_department_id)
    return parent.info_id
コード例 #5
0
def department_id_by_user(id):
    user_info = user_info_manager.get(id)
    department = department_manager.get(user_info.department_id)
    return department.info_id
コード例 #6
0
def parent_department_title(id):
    department = department_manager.get(id)
    parent = department_manager.get(department.parent_department_id)
    parent_info = department_info_manager.get(parent.info_id)
    return parent_info.title
コード例 #7
0
def department_title(id):
    department = department_manager.get(id)
    info = department_info_manager.get(department.info_id)
    return info.title
コード例 #8
0
def unbind_from_department(user_info_id, department_id):
    department = department_manager.get(department_id)
    if department.parent_department_id is not None:
        unbind_from_department(user_info_id, department.parent_department_id )
    department.users_info_id.remove(user_info_id)
    department_manager.update(department)