def unbind_users(department_id):
    department = get(department_id)
    if department.users_info_id is not None:
        for user_info_id in department.users_info_id:
            user_info = user_info_manager.get(user_info_id)
            user_info.department_id = None
            user_info_manager.update(user_info)
def users_by(request,
             scope=permissions.Scope.student,
             template="university_system/users/users.html",
             args=None):
    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):
        if args is None:
            args = {
                'users_key': 'type',
                'users_value': None,
                'users_info_key': 'login',
                'users_info_value': None
            }

        users = user_manager.search(args.get('users_key'),
                                    args.get('users_value'))
        users_info = []
        for user in users:
            users_info.append(user_info_manager.get(user.info_id))
        return render(request,
                      template,
                      context={
                          'users_info': users_info,
                          'auth_user': auth_user
                      })
    else:
        raise PermissionDenied
 def post(self, request, id):
     auth_user = auth_user_manager.get(request.session.get('token', None))
     if auth_user is not None and auth_user.has_permission(
             permissions.Scope.student, permissions.Crud.delete):
         user_info = user_info_manager.get(id)
         user_info_manager.delete_and_unbind(user_info)
         user_manager.delete(user_info.user_id)
         return base_views.home(request, 'The user was deleted.')
     else:
         raise PermissionDenied
def achievement_profile(request, id):
    auth_user = auth_user_manager.get(request.session.get('token', None))
    if auth_user is not None and auth_user.has_permission(
            permissions.Scope.achievement, permissions.Crud.read):
        achievement = form_converter.get_without_enums(
            achievement_manager.get(id))
        user_info = user_info_manager.get(achievement.user_info_id)
        return render(request,
                      "university_system/achievements/profile.html",
                      context={
                          'achievement': achievement,
                          'auth_user': auth_user,
                          'user_info': user_info
                      })
    else:
        raise PermissionDenied
def my_profile(request):
    auth_user = auth_user_manager.get(request.session.get('token'))
    if auth_user is not None and auth_user.has_permission(
            permissions.Scope.self, permissions.Crud.read):
        user = form_converter.get_without_enums(
            user_manager.get(auth_user.doc_id))
        user_info = form_converter.get_without_enums(
            user_info_manager.get(auth_user.info_id))
        return render(request,
                      "university_system/users/profile.html",
                      context={
                          "auth_user": auth_user,
                          'user': user,
                          'user_info': user_info
                      })
    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 user_profile(request,
                 id,
                 scope=permissions.Scope.student,
                 template="university_system/users/profile.html"):
    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):
        user_info = form_converter.get_without_enums(user_info_manager.get(id))
        user = form_converter.get_without_enums(
            user_manager.get(user_info.user_id))
        return render(request,
                      template,
                      context={
                          "user": user,
                          'user_info': user_info,
                          'auth_user': auth_user
                      })
    else:
        raise PermissionDenied
 def post(self, request):
     auth_user = auth_user_manager.get(request.session.get('token', None))
     info_form = UserInfoForm(request.POST)
     form = UserForm(request.POST)
     if info_form.is_valid() and form.is_valid():
         old_user = user_manager.get(auth_user.doc_id)
         new_user = form_to_object(form, old_user)
         user_manager.update(new_user)
         old_user_info = user_info_manager.get(auth_user.info_id)
         new_user_info = form_to_object(info_form, old_user_info)
         user_info_manager.update(new_user_info)
         return base_views.home(request, 'Your profile was updated.')
     return render(request,
                   "university_system/users/profile_update.html",
                   context={
                       'info_form': info_form,
                       'form': form,
                       'auth_user': auth_user
                   })
    def get(self, request):
        auth_user = auth_user_manager.get(request.session.get('token', None))
        if auth_user is not None and auth_user.has_permission(
                permissions.Scope.self, permissions.Crud.update):
            user_info = user_info_manager.get(auth_user.info_id)
            info_form = to_form(user_info, UserInfoForm)
            user = user_manager.get(auth_user.doc_id)
            form = to_form(user, UserForm)
            form.helper['type'].wrap(Field, type='hidden')
            form.helper['role'].wrap(Field, type='hidden')

            return render(request,
                          "university_system/users/profile_update.html",
                          context={
                              'info_form': info_form,
                              'form': form,
                              'auth_user': auth_user
                          })
        else:
            raise PermissionDenied
Example #10
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
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
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
def parent_department_title_by_user(id):
    user_info = user_info_manager.get(id)
    return parent_department_title(user_info.department_id)
def user_surname(id):
    user_info = user_info_manager.get(id)
    return user_info.surname
 def get_info(self):
     return user_info_manager.get(self.info_id)