Ejemplo n.º 1
0
def home(request, text=None):
    auth_user = auth_user_manager.get(request.session.get('token', None))
    if auth_user is not None:
        department_info = department_info_manager.get(1)
        return render(request,
                      "university_system/home.html",
                      context={
                          'department_info': department_info,
                          'auth_user': auth_user,
                          'text': text
                      })
Ejemplo n.º 2
0
def get_title_list(level=None):
    departments = department_manager.search(
        'level') if level is None else department_manager.search(
            'level', level)
    titles_and_ids = []
    if departments is not None:
        for department in departments:
            department_info = department_info_manager.get(department.info_id)
            titles_and_ids.append(
                (department_info.department_id, department_info.title))
        return titles_and_ids
    else:
        return []
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
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
def departments_by(request, level, id=None, template=None):
    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):
        departments = department_manager.search(
            'level', level) if id is None else department_manager.search(
                ['level', 'parent_department_id'], [level, id])
        clean_departments_info = []
        for department in departments:
            clean_departments_info.append(
                department_info_manager.get(department.info_id))
        return render(request,
                      template,
                      context={
                          "departments": departments,
                          'departments_info': clean_departments_info,
                          'auth_user': auth_user
                      })
    else:
        raise PermissionDenied
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def department_title(id):
    department = department_manager.get(id)
    info = department_info_manager.get(department.info_id)
    return info.title
 def post(self, request, id):
     department_info = department_info_manager.get(id)
     department_manager.delete_and_unbind(department_info.department_id)
     department_info_manager.delete(id)
     return base_views.home(request, 'The department was deleted')