Brak opisu

maintenance_views.py 3.2KB

    # -*- coding: utf-8 -*- from __future__ import division from django_logit import logit from django_response import response from maintenance.models import MaintenaceInfo from utils.error.errno_utils import MaintenaceStatusCode @logit def maintenance_add(request): user_id = request.POST.get('user_id', '') name = request.POST.get('name', '') phone = request.POST.get('phone', '') address = request.POST.get('address', '') sn = request.POST.get('sn', '') desc = request.POST.get('desc', '') point_id = request.POST.get('point_id', '') point_name = request.POST.get('point_name', '') express_name = request.POST.get('express_name', '') tracking_number = request.POST.get('tracking_number', '') maintenace_status = request.POST.get('maintenace_status', '') maintenace = MaintenaceInfo.objects.create( user_id=user_id, name=name, phone=phone, address=address, sn=sn, desc=desc, point_id=point_id, point_name=point_name, express_name=express_name, tracking_number=tracking_number, maintenace_status=maintenace_status, ) return response(data={ 'maintenace_id': maintenace.id, }) @logit def maintenance_delete(request): maintenace_id = request.POST.get('maintenace_id', '') user_id = request.POST.get('user_id', '') MaintenaceInfo.objects.filter(id=maintenace_id, user_id=user_id).update(status=False) return response() @logit def maintenance_update(request): maintenace_id = request.POST.get('maintenace_id', '') user_id = request.POST.get('user_id', '') name = request.POST.get('name', '') phone = request.POST.get('phone', '') address = request.POST.get('address', '') sn = request.POST.get('sn', '') desc = request.POST.get('desc', '') point_id = request.POST.get('point_id', '') point_name = request.POST.get('point_name', '') express_name = request.POST.get('express_name', '') tracking_number = request.POST.get('tracking_number', '') maintenace_status = request.POST.get('maintenace_status', '') try: maintenace = MaintenaceInfo.objects.get(id=maintenace_id, user_id=user_id, status=True) except MaintenaceInfo.DoesNotExist: return response(MaintenaceStatusCode.MAINTENACE_NOT_FOUND) if name: maintenace.name = name if phone: maintenace.phone = phone if address: maintenace.address = address if sn: maintenace.sn = sn if desc: maintenace.desc = desc if point_id: maintenace.point_id = point_id if point_name: maintenace.point_name = point_name if express_name: maintenace.express_name = express_name if tracking_number: maintenace.tracking_number = tracking_number if maintenace_status: maintenace.maintenace_status = maintenace_status maintenace.save() return response() @logit def maintenance_list(request): user_id = request.POST.get('user_id', '') maintenaces = MaintenaceInfo.objects.filter(user_id=user_id, status=True) maintenaces = [maintenace.data for maintenace in maintenaces] return response(data={ 'maintenaces': maintenaces, })