예제 #1
0
def rest_new_card(request):
    response = {}
    if request.method == 'PUT':
        user = UserCustom.objects.get(user_id__exact=request.user.pk)
        card_new_data = json.loads(request.body.decode())

        card = Card()
        card.org = user.org
        card.reg_date = datetime.now()
        card.changes_date = datetime.now()
        card.holder_name = card_new_data['holder_name']
        card.code = card_new_data['code']
        card.holder_phone = card_new_data['holder_phone']
        card.sex = card_new_data['sex']
        card.type = card_new_data['type']
        try:
            card.save()
            response['status'] = 'success'
            response['message'] = 'Новая карта успешно заведена!'
            return JsonResponse(response, safe=False)
        except IntegrityError as err:
            response['status'] = 'error'
            response['message'] = 'Карта с таким кодом уже существует!'
            return JsonResponse(response, safe=False)
예제 #2
0
        name = name.title()

        card.holder_name = name

        code = row[1]
        card.code = str(code)

        reg_date = row[2]
        try:
            card.reg_date = datetime.strptime(reg_date, '%d.%m.%Y')
        except:
            card.reg_date = None

        sex = row[3]
        if sex == 'муж':
            card.sex = 'm'
        elif sex == 'жен':
            card.sex = 'f'
        else:
            card.sex = 'm'

        fav_date = row[4]
        try:
            card.fav_date = datetime.strptime(fav_date, '%d.%m.%Y')
        except:
            card.fav_date = None

        accum = row[7]
        card.accumulation = float(accum)

        phone = row[9]