0

我正在尝试按照文档中的说明在 jasminSMS 中创建用户。但在我的情况下,我想创建像 UserManagement 这样的类来管理用户函数我可以创建用户但无法在 UserManagement 函数中启动/停止反应器,并且我在 Views 中调用 add_user 函数。

我做错了什么?(我在 django 工作)

# Class code as per jasmin documentation

class UserManagement:
    def __init__(self):
        self.host = '127.0.0.1'
        self.port = 8988
        self.username = 'radmin'
        self.password = 'rpwd'

    @defer.inlineCallbacks
    def add_user(self, cust_uid, cust_name, cust_password,cust_group):
        try:
            proxy_router = RouterPBProxy()
            yield proxy_router.connect(self.host, self.port, self.username, self.password)
            g1 = Group(cust_group)
            u1 = User(uid=cust_uid, group=g1, username=cust_name, password=cust_password)
            yield proxy_router.user_add(u1)

        except Exception as e:
            print("ERROR RUNNING SCENARIO: %s" % str(e))
        finally:
            reactor.stop()
        return redirect('user_add_nk')
        
        
# views.py code 
      
from app.usermanagement import UserManagement
      
def user_add_nk(request):
    if request.method == 'POST':
        cust_group = request.POST.get('cust_group')
        cust_uid = request.POST.get('uid')
        cust_name = request.POST.get('cust_name')
        cust_password = request.POST.get('cust_password')

        um = UserManagement()
        um.add_user(cust_uid, cust_name, cust_password,cust_group)
        try:
            reactor.run()
        except Exception as e:
            print(str(e))
   
    return render(request, 'adduser.html')

4

0 回答 0