def add_new_reg_user(request):
    sid = transaction.savepoint()  # Transaction open
    try:
        try:
            Profile.objects.get(username=request.POST.get('primary_contact'))
            data = {'success': 'exist', 'message': "Mobile No Already Exist."}
        except Profile.DoesNotExist:
            if Profile.objects.filter(
                    email=request.POST.get('email')).exists():
                data = {
                    'success': 'exist',
                    'message': "Email Id Already Exist."
                }
            else:
                user_data = Profile(
                    username=request.POST.get('primary_contact'),
                    primary_contact=request.POST.get('primary_contact'),
                    email=request.POST.get('email'),
                    first_name=request.POST.get('first_name'),
                    last_name=request.POST.get('last_name'),
                    pan_card=request.POST.get('pan_card'),
                    user_type=2)
                user_data.save()

                user_data.set_password(request.POST.get('password'))

                user_data.alternate_contact = request.POST.get(
                    'alternate_contact')
                user_data.address = request.POST.get('address')
                user_data.city = request.POST.get('city')
                user_data.town = request.POST.get('town')
                user_data.pincode = request.POST.get('pincode')
                user_data.landmark = request.POST.get('landmark')
                user_data.state = request.POST.get('state')

                user_data.beneficiary_name = request.POST.get(
                    'beneficiary_name')
                user_data.account_no = request.POST.get('account_no')
                user_data.ifsc_code = request.POST.get('ifsc_code')
                user_data.bank_name = request.POST.get('bank_name')

                user_data.pan_image = request.FILES['pancard_image']
                user_data.save()

                transaction.savepoint_commit(sid)
                data = {'success': 'true'}
    except Exception as exc:
        print('Exception For Register User | add_new_reg_user', exc)
        print('exception ', str(traceback.print_exc()))
        transaction.rollback(sid)
        data = {'error': 'true'}
    return HttpResponse(json.dumps(data), content_type='application/json')
Exemple #2
0
    def register_user(self, validated_data):
        sid = transaction.savepoint()  # Transaction open
        try:
            user_data = Profile(
                username=validated_data['primary_contact'],
                primary_contact=validated_data['primary_contact'],
                email=validated_data['email'],
                first_name=validated_data['first_name'],
                last_name=validated_data['last_name'],
                pan_card=validated_data['pan_card'],
                user_type=2)
            user_data.save()

            user_data.set_password(validated_data['password'])

            user_data.alternate_contact = validated_data['alternate_contact']
            user_data.address = validated_data['address']
            user_data.city = validated_data['city']
            user_data.town = validated_data['town']
            user_data.pincode = validated_data['pincode']
            user_data.landmark = validated_data['landmark']
            user_data.state = validated_data['state']

            user_data.beneficiary_name = validated_data['beneficiary_name']
            user_data.account_no = validated_data['account_no']
            user_data.ifsc_code = validated_data['ifsc_code']
            user_data.bank_name = validated_data['bank_name']
            user_data.save()

            try:
                pancard_image = json.loads(validated_data['pancard_image'])
                pan_image_file = get_image_file(str(pancard_image["image"]))
                name = pancard_image["name"]
                user_data.pan_image = SimpleUploadedFile(
                    name, pan_image_file,
                    getattr(pancard_image, "content_type",
                            "application/octet-stream"))
                user_data.save()
            except:
                pass

            transaction.savepoint_commit(sid)
            return user_data
        except Exception as exc:
            print('Exception For Register User | RegistrationSerializer', exc)
            print('exception ', str(traceback.print_exc()))
            transaction.rollback(sid)
            return None