mirror of
https://github.com/RobbieHan/sandboxMP.git
synced 2026-04-09 22:00:19 +08:00
structure update & delete
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,4 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.urls import path
|
||||
from django.urls import path, re_path
|
||||
|
||||
from .views import SystemView
|
||||
from . import views_structure
|
||||
@@ -10,5 +10,6 @@ urlpatterns = [
|
||||
path('basic/structure/', views_structure.StructureView.as_view(), name='basic-structure'),
|
||||
path('basic/structure/create/', views_structure.StructureCreateView.as_view(), name='basic-structure-create'),
|
||||
path('basic/structure/list/', views_structure.StructureListView.as_view(), name='basic-structure-list'),
|
||||
path('basic/structure/delete/', views_structure.StructureDeleteView.as_view(), name='basic-structure-delete'),
|
||||
]
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from django.views.generic.base import TemplateView
|
||||
from django.views.generic.base import View
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from .mixin import LoginRequiredMixin
|
||||
from .models import Structure
|
||||
@@ -23,11 +24,17 @@ class StructureCreateView(LoginRequiredMixin, View):
|
||||
|
||||
def get(self, request):
|
||||
ret = dict(structure_all=Structure.objects.all())
|
||||
if 'id' in request.GET and request.GET['id']:
|
||||
structure = get_object_or_404(Structure, pk=request.GET['id'])
|
||||
ret['structure'] = structure
|
||||
return render(request, 'system/structure/structure_create.html', ret)
|
||||
|
||||
def post(self, request):
|
||||
res = dict(result=False)
|
||||
structure = Structure()
|
||||
if 'id' in request.POST and request.POST['id']:
|
||||
structure = get_object_or_404(Structure, pk=request.POST['id'])
|
||||
else:
|
||||
structure = Structure()
|
||||
structure_form = StructureForm(request.POST, instance=structure)
|
||||
if structure_form.is_valid():
|
||||
structure_form.save()
|
||||
@@ -40,4 +47,15 @@ class StructureListView(LoginRequiredMixin, View):
|
||||
def get(self, request):
|
||||
fields = ['id', 'name', 'type', 'parent__name']
|
||||
ret = dict(data=list(Structure.objects.values(*fields)))
|
||||
return HttpResponse(json.dumps(ret), content_type='application/json')
|
||||
|
||||
|
||||
class StructureDeleteView(LoginRequiredMixin, View):
|
||||
|
||||
def post(self, request):
|
||||
ret = dict(result=False)
|
||||
if 'id' in request.POST and request.POST['id']:
|
||||
id_list = map(int, request.POST['id'].split(','))
|
||||
Structure.objects.filter(id__in=id_list).delete()
|
||||
ret['result'] = True
|
||||
return HttpResponse(json.dumps(ret), content_type='application/json')
|
||||
Reference in New Issue
Block a user