示例#1
0
def add_user(doc):
    if doc['mobile'] in sellers: return

    u = User()
    try:
        u = User.objects.get(username=doc['mobile'])
    except User.DoesNotExist:
        pass
    u.username = doc['mobile']
    if 'timestamp' in doc:
        u.timestamp = doc['timestamp'].strftime('%Y-%m-%d %H:%M:%S')
    else:
        if 'modificationTime' in doc:
            u.timestamp = doc['modificationTime'].strftime('%Y-%m-%d %H:%M:%S')
    u.save()

    p = Profile()
    try:
        p = Profile.objects.get(primary_phone=doc['mobile'])
        if p.id != doc['id']:
            record_duplicate(p.id, doc['id'])
            return
    except Profile.DoesNotExist:
        pass

    p.id = doc['id']
    p.user = u
    p.full_name = doc.get('name','')
    p.gender = doc.get('gender','').lower()
    if len(p.gender) > 1:
        p.gender = p.gender[0]
    if doc.get('dateOfBirth',None):
        p.date_of_birth = doc['dateOfBirth'].strftime('%Y-%m-%d')

    p.primary_phone = doc['mobile']
    p.secondary_phone = doc.get('mobile2','')

    p.primary_email = doc.get('email','').split(',')[0]
    p.secondary_email = doc.get('email2','').split(',')[0]

    p.buyer_or_seller = 'buyer'
    p.type = doc.get('type','individual')

    p.marketing_alerts = doc.get('dealAlerts','neutral')

    p.salt = doc.get('salt','')
    p.passcode = doc.get('passcode','')


    p.created_on = u.timestamp
    p.save()
示例#2
0
def add_user(doc):
    if doc['mobile'] in sellers: return

    u = User()
    try:
        u = User.objects.get(username=doc['mobile'])
    except User.DoesNotExist:
        pass
    u.username = doc['mobile']
    if 'timestamp' in doc:
        u.timestamp = doc['timestamp'].strftime('%Y-%m-%d %H:%M:%S')
    else:
        if 'modificationTime' in doc:
            u.timestamp = doc['modificationTime'].strftime('%Y-%m-%d %H:%M:%S')
    u.save()

    p = Profile()
    try:
        p = Profile.objects.get(primary_phone=doc['mobile'])
        if p.id != doc['id']:
            record_duplicate(p.id, doc['id'])
            return
    except Profile.DoesNotExist:
        pass

    p.id = doc['id']
    p.user = u
    p.full_name = doc.get('name', '')
    p.gender = doc.get('gender', '').lower()
    if len(p.gender) > 1:
        p.gender = p.gender[0]
    if doc.get('dateOfBirth', None):
        p.date_of_birth = doc['dateOfBirth'].strftime('%Y-%m-%d')

    p.primary_phone = doc['mobile']
    p.secondary_phone = doc.get('mobile2', '')

    p.primary_email = doc.get('email', '').split(',')[0]
    p.secondary_email = doc.get('email2', '').split(',')[0]

    p.buyer_or_seller = 'buyer'
    p.type = doc.get('type', 'individual')

    p.marketing_alerts = doc.get('dealAlerts', 'neutral')

    p.salt = doc.get('salt', '')
    p.passcode = doc.get('passcode', '')

    p.created_on = u.timestamp
    p.save()
示例#3
0
def signup_view(request):
    """Sign up view"""

    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['passwd']
        password_confirmation = request.POST['passwd_confirmation']
        gender = request.POST['gender']
        identification = request.POST['identification']
        age = request.POST['age']

        if password != password_confirmation:
            return render(request, 'users/signup.html',
                          {'error': 'Password confirnmation does not match'})

        if len(identification) <= 6:
            return render(request, 'users/signup.html',
                          {'error': 'Identification number is not valid'})

        if int(age) >= 150:
            return render(request, 'users/signup.html',
                          {'error': 'The age is not correct'})

        if gender == "":
            return render(request, 'users/signup.html',
                          {'error': 'The gender selection is not correct'})

        try:
            user = User.objects.create_user(username=username,
                                            password=password)
        except IntegrityError:
            return render(request, 'users/signup.html',
                          {'error': 'Username is already in use'})

        user.first_name = request.POST['first_name']
        user.last_name = request.POST['first_last_name']
        user.save()

        profile = Profile(user=user)
        profile.first_name = request.POST['first_name']
        profile.first_last_name = request.POST['first_last_name']
        profile.second_last_name = request.POST['second_last_name']
        profile.identification = identification
        profile.age = age
        profile.gender = gender
        profile.save()

    return render(request, 'users/signup.html')