|
# -*- coding: utf-8 -*-
from __future__ import division
from django.conf import settings
from django_logit import logit
from django_response import response
from paginator import pagination
from kodo.decorators import check_admin
from tenancy.models import TenancyShotInfo
from utils.error.errno_utils import TenancyStatusCode
@logit
@check_admin
def shot_list(request, administrator):
page = request.POST.get('page', 1)
num = request.POST.get('num', 20)
shots = TenancyShotInfo.objects.filter(status=True).order_by('-pk')
shots = [shot.data for shot in shots]
shots, left = pagination(shots, page, num)
return response(data={
'shots': shots,
'left': left,
})
@logit
@check_admin
def shot_detail(request, administrator):
brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
shot_id = request.POST.get('shot_id', '')
try:
shot = TenancyShotInfo.objects.get(shot_id=shot_id, status=True)
except TenancyShotInfo.DoesNotExist:
return response(TenancyStatusCode.TENANCY_SHOT_NOT_FOUND)
return response(data={
'shot': shot.data,
})
@logit
@check_admin
def shot_create(request, administrator):
brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
model_name = request.POST.get('model_name', '')
sn = request.POST.get('sn', '')
fittings_type = request.POST.get('fittings_type', 0)
tenancy_status = request.POST.get('tenancy_status', 0)
shot = TenancyShotInfo.objects.create(
model_name=model_name,
sn=sn,
fittings_type=fittings_type,
tenancy_status=tenancy_status,
)
return response(data={
'shot': shot.data,
})
@logit
@check_admin
def shot_update(request, administrator):
brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
shot_id = request.POST.get('shot_id', '')
model_name = request.POST.get('model_name', '')
sn = request.POST.get('sn', '')
fittings_type = request.POST.get('fittings_type', 0)
tenancy_status = request.POST.get('tenancy_status', 0)
shot, _ = TenancyShotInfo.objects.update_or_create(shot_id=shot_id, defaults={
'model_name': model_name,
'sn': sn,
'fittings_type': fittings_type,
'tenancy_status': tenancy_status,
})
return response(data={
'shot': shot.data,
})
|