예제 #1
0
파일: user.py 프로젝트: jcops/diting
 def get(self, request, *args, **kwargs):
     #获取客户端传来的参数PK
     pk = kwargs.get('pk')
     if settings.AUTH_LDAP:
         try:
             ldap_tool = LDAPTool()
             status = ldap_tool.ldap_get_user(pk, isdict=True)
             if status:
                 msg = "用户:%s 获取成功" % pk
                 data = status
                 form = self.form_class(initial=data)
                 context = {'form': form, 'app': _('Users'), 'action': _('LDAP Update user')}
                 return render(request, self.template_name, context)
             else:
                 msg = "未获取用户:%s" % pk
                 messages.add_message(self.request, messages.WARNING, msg)
                 return redirect(reverse('users:ldap-user-list'))
         except Exception as e:
             msg = "用户:%s 获取失败,原因:%s" % (pk, str(e))
             messages.add_message(self.request, messages.ERROR, msg)
             return redirect(reverse('users:ldap-user-list'))
     else:
         msg = '请系统先支持ldap'
         messages.add_message(self.request, messages.WARNING, msg)
         return redirect(reverse('users:ldap-user-list'))
예제 #2
0
파일: user.py 프로젝트: jcops/diting
 def get_context_data(self, **kwargs):
     data = ''
     pk = kwargs.get('pk')
     if settings.AUTH_LDAP:
         try:
             ldap_tool = LDAPTool()
             status = ldap_tool.ldap_get_user(pk, isdict=True)
             if status:
                 msg = "用户:%s 获取成功" % pk
                 data = status
                 # messages.add_message(self.request, messages.SUCCESS, msg)
             else:
                 msg = "未获取用户:%s" % pk
                 messages.add_message(self.request, messages.WARNING, msg)
                 return redirect(reverse('users:ldap-user-list'))
         except Exception as e:
             msg = "用户:%s 获取失败,原因:%s" % (pk, str(e))
             messages.add_message(self.request, messages.ERROR, msg)
             return redirect(reverse('users:ldap-user-list'))
     else:
         msg = '请系统先支持ldap'
         messages.add_message(self.request, messages.WARNING, msg)
         return redirect(reverse('users:ldap-user-list'))
     context = super().get_context_data(**kwargs)
     context['user'] = data
     context.update({
         'app': _('Users'),
         'action': _('LDAP User Detail'),
     })
     return context
예제 #3
0
 def get(self, request, *args, **kwargs):
     #获取客户端传来的参数PK
     pk = kwargs.get('pk')
     if settings.AUTH_LDAP:
         try:
             ldap_tool = LDAPTool()
             status = ldap_tool.ldap_get_user(pk, isdict=True)
             if status:
                 msg = "用户:%s 获取成功" % pk
                 data = status
                 form = self.form_class(initial=data)
                 context = {
                     'form': form,
                     'app': _('Users'),
                     'action': _('LDAP Update user')
                 }
                 return render(request, self.template_name, context)
             else:
                 msg = "未获取用户:%s" % pk
                 messages.add_message(self.request, messages.WARNING, msg)
                 return redirect(reverse('users:ldap-user-list'))
         except Exception as e:
             msg = "用户:%s 获取失败,原因:%s" % (pk, str(e))
             messages.add_message(self.request, messages.ERROR, msg)
             return redirect(reverse('users:ldap-user-list'))
     else:
         msg = '请系统先支持ldap'
         messages.add_message(self.request, messages.WARNING, msg)
         return redirect(reverse('users:ldap-user-list'))
예제 #4
0
 def get_context_data(self, **kwargs):
     data = ''
     pk = kwargs.get('pk')
     if settings.AUTH_LDAP:
         try:
             ldap_tool = LDAPTool()
             status = ldap_tool.ldap_get_user(pk, isdict=True)
             if status:
                 msg = "用户:%s 获取成功" % pk
                 data = status
                 # messages.add_message(self.request, messages.SUCCESS, msg)
             else:
                 msg = "未获取用户:%s" % pk
                 messages.add_message(self.request, messages.WARNING, msg)
                 return redirect(reverse('users:ldap-user-list'))
         except Exception as e:
             msg = "用户:%s 获取失败,原因:%s" % (pk, str(e))
             messages.add_message(self.request, messages.ERROR, msg)
             return redirect(reverse('users:ldap-user-list'))
     else:
         msg = '请系统先支持ldap'
         messages.add_message(self.request, messages.WARNING, msg)
         return redirect(reverse('users:ldap-user-list'))
     context = super().get_context_data(**kwargs)
     context['user'] = data
     context.update({
         'app': _('Users'),
         'action': _('LDAP User Detail'),
     })
     return context
예제 #5
0
파일: api.py 프로젝트: jcops/diting
 def get(self, request, *args, **kwargs):
     pk = kwargs.get('pk')
     data = {'status': '', 'msg': '', 'data': ''}
     if settings.AUTH_LDAP:
         try:
             ldap_tool = LDAPTool()
             status = ldap_tool.ldap_get_user(pk, isdict=True)
             if status:
                 data['msg'] = "用户:%s 获取成功" % pk
                 data['data'] = status
                 data['status'] = 200
             else:
                 data['msg'] = "未获取用户:%s" % pk
                 data['status'] = 404
             return Response(data=data, status=200)
         except Exception as e:
             data['msg'] = "用户:%s 获取失败,原因:%s" % (pk, str(e))
             data['status'] = 500
             return Response(data=data, status=200)
     else:
         data['msg'] = '请系统先支持ldap'
         data['status'] = 501
         return Response(data=data, status=200)
예제 #6
0
 def get(self, request, *args, **kwargs):
     pk = kwargs.get('pk')
     data = {'status': '', 'msg': '', 'data': ''}
     if settings.AUTH_LDAP:
         try:
             ldap_tool = LDAPTool()
             status = ldap_tool.ldap_get_user(pk, isdict=True)
             if status:
                 data['msg'] = "用户:%s 获取成功" % pk
                 data['data'] = status
                 data['status'] = 200
             else:
                 data['msg'] = "未获取用户:%s" % pk
                 data['status'] = 404
             return Response(data=data, status=200)
         except Exception as e:
             data['msg'] = "用户:%s 获取失败,原因:%s" % (pk, str(e))
             data['status'] = 500
             return Response(data=data, status=200)
     else:
         data['msg'] = '请系统先支持ldap'
         data['status'] = 501
         return Response(data=data, status=200)