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()
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()