Example #1
0
    def post(self, request):
        name = request.POST.get('name')
        phone = request.POST.get('phone')
        address1 = request.POST.get('address')
        address2 = Address()
        address2.name = name
        address2.user = request.user
        address2.phone = phone
        address2.address = address1
        address2.save()

        return JsonResponse({'res': 1})
Example #2
0
def add_address(request):
    user = User.objects.get(pk=request.session.get('uid'))
    if Address.objects.filter(user=user).count() > 20:
        return JsonResponse({'code': 1, 'msg': '只能添加20个地址'})
    if not request.POST.get('a_email') or not request.POST.get('a_phone') or not request.POST.get('a_region') or not request.POST.get('a_place') or not request.POST.get('a_name') or not request.POST.get('fixed_telephone'):
        return JsonResponse({'code': 1, 'msg': '参数错误'})
    address = Address()
    address.a_email = request.POST.get('a_email')
    address.a_phone = request.POST.get('a_phone')
    address.a_region = request.POST.get('a_region')
    address.a_place = request.POST.get('a_place')
    address.a_name = request.POST.get('a_name')
    address.fixed_telephone = request.POST.get('fixed_telephone')
    address.user = user
    if Address.objects.filter(user=user).count() == 0:
        address.is_default = True
    address.save()
    return JsonResponse({'code': 0})
    def handle(self, *args, **options):
        path = args[0]

        if path.startswith('http'):
            content = json.load(urllib2.urlopen(path))
        else:
            content = json.load(open(path))

        for item in content:
            if not '@' in item['username']:
                print item['username']
                continue

            try:
                user = User.objects.get(id=int(item['id']))
            except User.DoesNotExist:
                user = User(id=int(item['id']))

            user.email = item['username']
            user.password = item['password']
            user.title = item['fullname']
            user.phone = item.get('phone', '')

            birthday = None
            if 'year' in item:
                birthday = datetime.date(int(item['year']), int(item['month']), int(item['mday']))
            user.birthday = birthday

            user.is_active = item['status'] == '1'

            if item['franch'] == '10':
                user.status = User.STATUS_FRANCHISEE
            elif item['retail'] == '10':
                user.status = User.STATUS_CUSTOMER
            elif item['retail'] == '0':
                user.status = User.STATUS_WHOLESALE

            user.save()

            for addr in item['addresses']:
                try:
                    address = Address.objects.get(id=int(addr['id']))
                except Address.DoesNotExist:
                    address = Address(id=int(addr['id']))

                address.user = user
                if not address.city:
                    address.city = addr['city']
                if not address.postal_code:
                    address.postal_code = ''
                if not address.street:
                    address.street = ''
                if not address.house:
                    address.house = ''
                if not address.flat:
                    address.flat = ''
                if not address.phone:
                    address.phone = addr.get('to_phone', addr.get('fax', ''))
                if not address.email:
                    address.email = addr.get('to_email', '')
                address.receiver_title = addr.get('to_name', addr.get('name', ''))
                address.original_string = addr['address']

                address.save()
            '''