From d409d2358e68180a98cbd8570d09c33910341c7a Mon Sep 17 00:00:00 2001 From: zhong Date: Wed, 6 Apr 2016 14:43:16 +0800 Subject: [PATCH] can remove quota group from web page can add quota with just one click --- src/httprest.py | 5 ++++- src/userManager.py | 23 ++++++++++++++++++++--- web/templates/admin.html | 19 ++++++++++++++++++- web/web.py | 8 +++++++- web/webViews/user/userlist.py | 13 +++++++++++++ 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/httprest.py b/src/httprest.py index 31f5eb1..56d6898 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -422,7 +422,10 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler): result = G_usermgr.register(user = user, cur_user = cur_user) self.response(200, result) elif cmds[1] == 'groupadd': - result = G_usermgr.groupadd(name = form.getvalue('name', None), cur_user = cur_user) + result = G_usermgr.groupadd(form = form, cur_user = cur_user) + self.response(200, result) + elif cmds[1] == 'groupdel': + result = G_usermgr.groupdel(name = form.getvalue('name', None), cur_user = cur_user) self.response(200, result) elif cmds[1] == 'data': logger.info("handle request: user/data") diff --git a/src/userManager.py b/src/userManager.py index c04f740..c1d69b8 100755 --- a/src/userManager.py +++ b/src/userManager.py @@ -663,8 +663,8 @@ class userManager: @administration_required def groupadd(*args, **kwargs): - name = kwargs.get('name', None) - if (name == None): + form = kwargs.get('form') + if (form.getvalue("name") == None): return {"success":'false', "reason": "Empty group name"} #group_new = UserGroup(name) #db.session.add(group_new) @@ -672,7 +672,24 @@ class userManager: groupfile = open(fspath+"/global/group",'r') groups = json.loads(groupfile.read()) groupfile.close() - groups.append({'name':name, 'cpu':'100000', 'memory':'2000', 'imageQuantity':'10', 'lifeCycle':'24'}) + groups.append({'name':form.getvalue("name"), 'cpu':form.getvalue("cpu"), 'memory':form.getvalue("memory"), 'imageQuantity':form.getvalue("image"), 'lifeCycle':form.getvalue("lifecycle")}) + groupfile = open(fspath+"/global/group",'w') + groupfile.write(json.dumps(groups)) + groupfile.close() + return {"success":'true'} + + @administration_required + def groupdel(*args, **kwargs): + name = kwargs.get('name', None) + if (name == None): + return {"success":'false', "reason": "Empty group name"} + groupfile = open(fspath+"/global/group",'r') + groups = json.loads(groupfile.read()) + groupfile.close() + for group in groups: + if group['name'] == name: + groups.remove(group) + break groupfile = open(fspath+"/global/group",'w') groupfile.write(json.dumps(groups)) groupfile.close() diff --git a/web/templates/admin.html b/web/templates/admin.html index baddae8..19c016f 100644 --- a/web/templates/admin.html +++ b/web/templates/admin.html @@ -52,6 +52,22 @@ +
+ + +
+
+ + +
+
+ + +
+
+ + +
@@ -140,7 +156,8 @@ "columnDefs": [ { "render": function ( data, type, row ) { - return '' + 'Edit' + ''; + return '' + 'Edit' + '' + + '' + 'Delete' + ''; }, "targets": 5 }, diff --git a/web/web.py b/web/web.py index 5911d05..6f14843 100755 --- a/web/web.py +++ b/web/web.py @@ -20,7 +20,7 @@ from webViews.log import logger from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort from webViews.dashboard import dashboardView -from webViews.user.userlist import userlistView, useraddView, usermodifyView, groupaddView, userdataView, userqueryView +from webViews.user.userlist import userlistView, useraddView, usermodifyView, groupaddView, groupdelView, userdataView, userqueryView from webViews.user.userinfo import userinfoView from webViews.user.userActivate import userActivateView from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView @@ -328,6 +328,12 @@ def usermodify(): def groupadd(): return groupaddView.as_view() +@app.route("/group/delete//", methods=['POST', 'GET']) +@administration_required +def groupdel(groupname): + groupdelView.groupname = groupname + return groupdelView.as_view() + @app.route("/user/info/", methods=['GET', 'POST']) @login_required def userinfo(): diff --git a/web/webViews/user/userlist.py b/web/webViews/user/userlist.py index c3cc62a..5af0582 100644 --- a/web/webViews/user/userlist.py +++ b/web/webViews/user/userlist.py @@ -54,3 +54,16 @@ class groupaddView(normalView): def post(self): dockletRequest.post('/user/groupadd', request.form) return redirect('/admin/') + +class groupdelView(normalView): + @classmethod + def post(self): + data = { + "name" : self.groupname, + } + dockletRequest.post('/user/groupdel', data) + return redirect('/admin/') + + @classmethod + def get(self): + return self.post()