|
|
@@ -3,7 +3,6 @@
|
3
|
3
|
from __future__ import division
|
4
|
4
|
|
5
|
5
|
import json
|
6
|
|
-from datetime import datetime
|
7
|
6
|
|
8
|
7
|
from django.conf import settings
|
9
|
8
|
from django.db.models.query_utils import Q
|
|
|
@@ -183,28 +182,29 @@ def maintenance_list(request):
|
183
|
182
|
user_id = request.POST.get('user_id', '')
|
184
|
183
|
page = request.POST.get('page', 1)
|
185
|
184
|
num = request.POST.get('num', 20)
|
186
|
|
- query = request.POST.get('query', '')
|
187
|
185
|
maintenance_status = request.POST.get('maintenance_status', 'all')
|
|
186
|
+ query = request.POST.get('query', '')
|
188
|
187
|
start_time = request.POST.get('start_time', '')
|
189
|
188
|
end_time = request.POST.get('end_time', '')
|
190
|
189
|
|
191
|
190
|
maintenances = MaintenaceInfo.objects.filter(status=True)
|
|
191
|
+
|
192
|
192
|
if not is_admin(brand_id, admin_id):
|
193
|
193
|
maintenances = maintenances.filter(user_id=user_id)
|
194
|
|
-
|
195
|
|
- if start_time and end_time:
|
196
|
|
- start_time = datetime.strptime(start_time, '%Y%m%d')
|
197
|
|
- end_time = datetime.strptime(end_time + ' 23:59:59', '%Y%m%d %H:%M:%S')
|
198
|
|
- maintenances = maintenances.filter(created_at__range=(start_time, end_time))
|
|
194
|
+
|
|
195
|
+ if maintenance_status and maintenance_status != 'all':
|
|
196
|
+ maintenances = maintenances.filter(maintenance_status=maintenance_status)
|
199
|
197
|
|
200
|
198
|
if query:
|
201
|
199
|
maintenances = maintenances.filter(Q(phone=query) | Q(name__icontains=query) | Q(sn=query))
|
202
|
|
-
|
203
|
|
- if maintenance_status and not maintenance_status == 'all':
|
204
|
|
- maintenances = maintenances.filter(maintenance_status=maintenance_status)
|
205
|
200
|
|
206
|
|
- maintenances = maintenances.order_by('-pk')
|
|
201
|
+ if start_time and end_time:
|
|
202
|
+ start_time = tc.string_to_utc_datetime(start_time, format='%Y%m%d')
|
|
203
|
+ end_time = tc.string_to_utc_datetime(end_time + ' 23:59:59', format='%Y%m%d %H:%M:%S')
|
|
204
|
+ maintenances = maintenances.filter(created_at__range=(start_time, end_time))
|
|
205
|
+
|
207
|
206
|
count = maintenances.count()
|
|
207
|
+ maintenances = maintenances.order_by('-pk')
|
208
|
208
|
maintenances = [maintenance.data for maintenance in maintenances]
|
209
|
209
|
maintenances, left = pagination(maintenances, page, num)
|
210
|
210
|
|