Skip to content

Commit 3aa1f01

Browse files
committed
0.1.1.2 优化搜索
1 parent a47580b commit 3aa1f01

File tree

171 files changed

+57
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+57
-55
lines changed

.idea/chain.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-109 Bytes
Binary file not shown.
-221 Bytes
Binary file not shown.
-696 Bytes
Binary file not shown.
-9.49 KB
Binary file not shown.
Binary file not shown.
-109 Bytes
Binary file not shown.
-109 Bytes
Binary file not shown.
Binary file not shown.
File renamed without changes.
114 Bytes
Binary file not shown.
226 Bytes
Binary file not shown.

asset/__pycache__/urls.cpython-36.pyc

698 Bytes
Binary file not shown.
9.71 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.

apps/asset/models.py renamed to asset/models.py

-8
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,3 @@ def __str__(self):
5959
return self.hostname
6060

6161

62-
63-
#
64-
# class asset_import(models.Model):
65-
# userName = models.CharField(max_length = 30)
66-
# uploadFile = models.FileField(upload_to = 'disk/upload/')
67-
#
68-
# def __str__(self):
69-
# return self.userName

apps/asset/urls.py renamed to asset/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.urls import path
2-
from asset import views
2+
from . import views
33

44
urlpatterns = [
55
path('asset.html',views.AssetListAll.as_view(),name='asset_list'),

apps/asset/views.py renamed to asset/views.py

+38-20
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
from django.urls import reverse_lazy
99
from django.conf import settings
1010
from django.db.models import Q
11-
from asset.form import FileForm
12-
from asset.models import asset
11+
from asset.form import FileForm
12+
from asset.models import asset
13+
from asset.models import asset as Asset
1314
import codecs,chardet
1415
import csv,time
1516
from io import StringIO
1617
import json
1718

1819

20+
1921
class AssetListAll(LoginRequiredMixin,ListView):
2022
'''
2123
列表
@@ -24,20 +26,29 @@ class AssetListAll(LoginRequiredMixin,ListView):
2426
paginate_by = settings.DISPLAY_PER_PAGE
2527
model = asset
2628
context_object_name = "asset_list"
29+
queryset = asset.objects.all()
2730
ordering = ('id',)
2831

2932
def get_context_data(self, **kwargs):
33+
search_data = self.request.GET.copy()
3034
context = {
3135
"asset_active": "active",
3236
"asset_list_active": "active",
37+
"search_data":search_data.urlencode()
3338
}
3439
kwargs.update(context)
35-
return super(AssetListAll, self).get_context_data(**kwargs)
40+
return super().get_context_data(**kwargs)
41+
42+
43+
def get_queryset(self,*args,**kwargs):
44+
self.queryset = super().get_queryset()
45+
if self.request.GET.get('name'):
46+
query = self.request.GET.get('name',None)
47+
queryset = self.queryset.filter(Q(network_ip=query)| Q(hostname=query) | Q(inner_ip=query) | Q(manager=query)).order_by('id')
48+
else:
49+
queryset = super().get_queryset()
50+
return queryset
3651

37-
def post(self, request):
38-
query = request.POST.get("name")
39-
ret = asset.objects.filter(Q(network_ip=query)| Q(hostname=query) | Q(inner_ip=query) | Q(manager=query))
40-
return render(request, 'asset/asset.html',{"asset_active": "active", "asset_list_active": "active", "asset_list": ret})
4152

4253

4354

@@ -119,10 +130,13 @@ class AssetAllDel(LoginRequiredMixin,View):
119130
def post(self, request):
120131
ret = {'status': True, 'error': None, }
121132
try:
122-
123-
ids = request.POST.getlist('id', None) or request.POST.get('nid', None)
124-
idstring = ','.join(ids)
125-
asset.objects.extra(where=['id IN (' + idstring + ')']).delete()
133+
if request.POST.get('nid') :
134+
id = request.POST.get('nid', None)
135+
asset.objects.get(id=id).delete()
136+
else:
137+
ids = request.POST.getlist('id', None)
138+
idstring = ','.join(ids)
139+
asset.objects.extra(where=['id IN (' + idstring + ')']).delete()
126140
except Exception as e:
127141
ret['status'] = False
128142
ret['error'] = '删除请求错误,没有权限{}'.format(e)
@@ -136,7 +150,9 @@ class AssetExport(View):
136150
:param request:
137151
:return:
138152
"""
139-
def get(self,request):
153+
154+
155+
def get(self,request,):
140156

141157
fields = [
142158
field for field in Asset._meta.fields
@@ -153,16 +169,16 @@ def get(self,request):
153169

154170
header = [field.verbose_name for field in fields]
155171
writer.writerow(header)
156-
for asset in assets:
157-
data = [getattr(asset, field.name) for field in fields]
172+
for asset_ in assets:
173+
data = [getattr(asset_, field.name) for field in fields]
158174
writer.writerow(data)
159175
return response
160176

161177
def post(self,request):
162178
ids = request.POST.getlist('id', None)
163179
idstring = ','.join(ids)
164180
fields = [
165-
field for field in Asset._meta.fields
181+
field for field in Asset._meta.fields
166182
if field.name not in [
167183
'date_created'
168184
]
@@ -171,14 +187,14 @@ def post(self,request):
171187
response = HttpResponse(content_type='text/csv')
172188
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
173189
response.write(codecs.BOM_UTF8)
174-
assets = Asset.objects.extra(where=['id IN (' + idstring + ')']).all()
190+
assets = Asset.objects.extra(where=['id IN (' + idstring + ')']).all()
175191
writer = csv.writer(response, dialect='excel', quoting=csv.QUOTE_MINIMAL)
176192

177193
header = [field.verbose_name for field in fields]
178194
writer.writerow(header)
179195

180-
for asset in assets:
181-
data = [getattr(asset, field.name) for field in fields]
196+
for asset_ in assets:
197+
data = [getattr(asset_, field.name) for field in fields]
182198
writer.writerow(data)
183199
return response
184200

@@ -235,10 +251,11 @@ def AssetImport(request):
235251
v = 0
236252
elif k in ['ctime','utime'] :
237253
try:
238-
v1 = time.strptime(v, '%Y/%m/%d %H:%I')
254+
v1 = time.strptime(v, '%Y/%m/%d %H:%M')
239255
v = time.strftime("%Y-%m-%d %H:%M",v1)
240256
except Exception as e :
241257
print(e)
258+
v = v
242259
else:
243260
continue
244261
asset_dict_id[k] =v
@@ -253,10 +270,11 @@ def AssetImport(request):
253270
v = 0
254271
elif k in ['ctime','utime'] :
255272
try:
256-
v1 = time.strptime(v, '%Y/%m/%d %H:%I')
273+
v1 = time.strptime(v, '%Y/%m/%d %H:%M')
257274
v = time.strftime("%Y-%m-%d %H:%M",v1)
258275
except Exception as e :
259276
print(e)
277+
v = v
260278
else:
261279
continue
262280
asset_dict[k] = v
File renamed without changes.
114 Bytes
Binary file not shown.

apps/chain/settings.py renamed to chain/settings.py

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'bootstrap3',
4141
'asset',
4242
'index',
43+
'pure_pagination',
4344
]
4445

4546
MIDDLEWARE = [
@@ -144,3 +145,8 @@
144145
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
145146
DISPLAY_PER_PAGE = 25
146147

148+
PAGINATION_SETTINGS = {
149+
'PAGE_RANGE_DISPLAYED': 20,
150+
'MARGIN_PAGES_DISPLAYED': 2,
151+
'SHOW_FIRST_PAGE_WHEN_INVALID': True,
152+
}

apps/chain/urls.py renamed to chain/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from django.contrib import admin
1717
from django.urls import path
1818
from django.conf.urls import include
19-
from index.views import index,login_view,logout,password_update,LoginHistorys
19+
from index.views import index,login_view,logout,password_update,LoginHistorys
2020

2121
urlpatterns = [
2222
path('admin/', admin.site.urls,name='admin'),
File renamed without changes.
144 KB
Binary file not shown.
File renamed without changes.
114 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

apps/templates/_js.html renamed to templates/_js.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
dom: '<"html5buttons"B>lTfgitp,',
6565

6666
buttons: [],
67-
lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "全部"]]
67+
lengthMenu: [[25, 50, 70, -1], [25, 50, 70, "全部"]]
6868
});
6969

7070
});
File renamed without changes.

apps/templates/asset/asset.html renamed to templates/asset/asset.html

+9-23
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ <h5>资产信息</h5>
5555

5656
<div class="table-responsive">
5757

58-
<form id="cha" class="form-horizontal" action="{% url 'asset:asset_list' %}" method="post">
58+
<form id="cha" class="form-horizontal" action="{% url 'asset:asset_list' %}" method="GET">
5959
{% csrf_token %}
60-
<div class="col-md-2"><input type="text" class="form-control" name="name"
61-
placeholder="主机名、IP、负责人" required></div>
60+
<div class="col-md-2"><input type="text" class="form-control" name="name" placeholder="主机名、IP、负责人" required></div>
6261

6362
<button class="btn btn-sm btn-primary" type="submit">查询</button>
6463

@@ -107,8 +106,8 @@ <h5>资产信息</h5>
107106
<td class="center">{{ row.is_active }}</td>
108107
<td><a class="btn btn-primary btn-xs "
109108
href="{% url "asset:asset_update" pk=row.id %}">编辑</a>
110-
<a class="btn btn-danger btn-xs asset_del_1" data-toggle="modal"
111-
data-target="#myModal1">删除</a>
109+
<a class="btn btn-danger btn-xs asset_del"
110+
>删除</a>
112111
</td>
113112
</tr>
114113
{% endfor %}
@@ -132,7 +131,7 @@ <h5>资产信息</h5>
132131
{% endif %}
133132

134133
{% for p in paginator.page_range %}
135-
{% if search_data %} <!-- 判断是否是搜索分页-->
134+
{% if search_data %} <!-- 判断是否是搜索分页-->
136135
{% if p == page_obj.number %}
137136
<li class="active"><a
138137
href="{% url "asset:asset_list" %}?page={{ p }}&{{ search_data }}"> {{ p }} </a>
@@ -172,6 +171,7 @@ <h5>资产信息</h5>
172171
</div> <!--页码 -->
173172

174173

174+
175175
</form>
176176

177177

@@ -197,7 +197,7 @@ <h5>资产信息</h5>
197197

198198

199199
$(document).ready(function () {
200-
$('.dataTables-asset').DataTable({
200+
$('.dataTables-asset').DataTable({
201201

202202
"oLanguage": {
203203
"sLengthMenu": "每页显示 _MENU_ 条记录",
@@ -222,25 +222,11 @@ <h5>资产信息</h5>
222222
dom: '<"html5buttons"B>lTfgitp,'
223223

224224
});
225-
226-
227-
225+
});
228226

229227
$(function () {
230228

231-
$(document).on('click', '#export1', function () {
232-
$.ajax({
233-
url: "/asset/asset-export1.html",
234-
type: 'POST',
235-
data: $('#del_form_asset_all').serialize(),
236-
success: function (data) {
237-
238-
}
239-
});
240-
});
241-
242-
243-
$(document).on('click', '.asset_del_1', function () {
229+
$(document).on('click', '.asset_del', function () {
244230
var id = $(this).parent().parent().attr('id');
245231
swal({
246232
title: "你确定删除",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)