Commit b88eff76 authored by reynaldi adriantama's avatar reynaldi adriantama

group management/user management

parent 2f08a104
......@@ -32,5 +32,7 @@ urlpatterns = [
path('adduser/', views.addUser, name="adduser"),
path('getallGroups/', views.listGroup, name="getallGroups"),
path('switchStatus/', views.deactivateUser, name="switchStatus"),
path('loadUserbyId/', views.loadUserbyId, name="loadUserbyId")
path('loadUserbyId/', views.loadUserbyId, name="loadUserbyId"),
path('addGroup/', views.addGroup, name="addGroup"),
path('deleteGroup/', views.deleteGroup, name="deleteGroup")
]
......@@ -52,10 +52,22 @@ class Usermanagement(generic.TemplateView):
}
user_res.append(datas)
with conn.cursor() as grouplist_:
grouplist_.execute("SELECT * FROM auth_group ORDER BY name ASC")
allGroup = grouplist_.fetchall()
group_res = []
for rows in allGroup:
datas = {
"id" : rows[0],
"name" : rows[1],
}
group_res.append(datas)
context = {
'title' : 'user management',
'data' : user_res
'data' : user_res,
'dataGroup' : group_res
}
print(context)
......@@ -130,7 +142,7 @@ def addUser(request):
@api_view(('POST',))
def listGroup(request):
if request.method == "POST":
groupList = Group.objects.all()
groupList = Group.objects.all().order_by('name')
group = []
for g in groupList:
......@@ -246,4 +258,75 @@ def loadGroupById(iduser):
resGroup.append(i[0])
print(resGroup)
return resGroup
\ No newline at end of file
return resGroup
@api_view(('POST',))
def addGroup(request):
if request.method == "POST":
name = request.POST.get('name')
idgroup = request.POST.get('id')
try:
if idgroup:
with conn.cursor() as cursor:
cursor.execute("UPDATE auth_group SET name = '"+name+"' WHERE id="+idgroup)
result = cursor.rowcount
print(result)
data = {
"code" : 0,
"data" : "Group telah diperbaharui.",
"info" : "success"
}
else:
group = Group.objects.get(name=name)
data = {
"code" : 4,
"data" : "Group telah tersedia.",
"info" : "failed"
}
except Group.DoesNotExist:
Group.objects.create(name=name)
if Group.objects.get(name=name):
data = {
"code" : 0,
"info" : "success",
"data" : "Group berhasil ditambahkan"
}
else:
data = {
"code" : 4,
"info" : "failed",
"data" : "Group gagal ditambahkan"
}
return Response(data)
@api_view(('POST',))
def deleteGroup(request):
if request.method == "POST":
id = request.POST.get('id')
with conn.cursor() as cursor:
cursor.execute("DELETE FROM auth_group WHERE id="+id)
result = cursor.rowcount
if result > 0:
data = {
"code" : 0,
"info" : "success",
"data" : "data berhasil dihapus"
}
else:
data = {
"code" : 4,
"info" : "success",
"data" : "data berhasil dihapus"
}
return Response(data)
\ No newline at end of file
......@@ -93,6 +93,7 @@ $(function() {
// Mini
$('.select-size-xs').select2({
maximumSelectionLength: 5,
containerCssClass: 'select-xs'
});
......
......@@ -37,6 +37,6 @@
Notific{% static 'Plugin -->
<script src="{% static '/js/plugins/bootstrap-notify.js' %}"></script>
<!-- Control {% static 'for Material Dashboard: parallax effects, scripts for the example pages etc -->
<script src="{% static '/js/material-dashboard.js' %}" type="text/javascript"></script>
<!-- <script src="{% static '/js/material-dashboard.js' %}" type="text/javascript"></script> -->
<!-- Material{% static 'ard DEMO methods, don't include it in your project! -->
<script src="{% static '/demo/demo.js' %}"></script>
\ No newline at end of file
<!-- <script src="{% static '/demo/demo.js' %}"></script> -->
\ No newline at end of file
This diff is collapsed.
......@@ -27,7 +27,7 @@
<div>
{% if form.errors %}
<div class="alert alert-danger">
Username atau Password kamu salah. Silahkan coba kembali.
Username atau Password salah. Silahkan coba kembali.
</div>
{% endif %}
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment