Example #1
0
def index(user):
    user_count = Profile.objects(user_id=user[0]).count()
    role = Role.objects(name="Citizen").first()
    channel = Channel.objects(slug=map_channel(user[4])).first()

    if user_count == 0:
        #channels = []
        coordinates = str(user[11]) + "," + str(user[12])
        profile = Profile(user_id=int(user[0]),
                    full_name=user[1],
                    sign_up_with="mobile_number",
                    sign_up_ip_address=str(ipaddress.IPv4Address(user[2])),
                    avatar=str(user[3]),
                    roles=[role.id],
                    channels=[{"id": channel.id, "slug": channel.slug, 
                    "mac_address": user[5], "sign_up": True, "device_token": user[6],
                    "last_login_at": user[7],
                    "settings": {"email_notifications_preferred": True, 
                    "sms_notifications_preferred": True, 
                    "push_notifications_preferred": True}}],
                    locations=[{"app_name": channel.app_name, 
                            "location": {"name": user[8], "coordinates": coordinates, 
                            "ward_id": user[9],
                            "city_id": user[10]}}])
        
        profile.save()

        print('User: '******' indexed')
    else:
        print('User: '******' already exists')

    return True
Example #2
0
def index(user):
    user_count = Profile.objects(user_id=user[0]).count()
    role = Role.objects(name="Citizen").first()
    source_id = 1 if user[4] == 0 else user[4]
    channel = Channel.objects(slug=map_channel(source_id)).first()

    if user_count == 0:
        #channels = []
        latitude = user[11]
        longitude = user[12]
        coordinates = [float(longitude), float(latitude)
                       ] if latitude and longitude else None
        city_id = None if user[10] == 0 else user[10]
        full_name = (user[1].lower().title()) if user[1] else 'Citizen'
        profile = Profile(user_id=int(user[0]),
                          full_name=full_name,
                          sign_up_with="mobile_number",
                          sign_up_ip_address=str(ipaddress.IPv4Address(
                              user[2])),
                          avatar=user[3],
                          roles=[role.id],
                          channels=[{
                              "id": channel.id,
                              "slug": channel.slug,
                              "mac_address": user[5],
                              "sign_up": True,
                              "device_token": user[6],
                              "last_login_at": user[7],
                              "settings": {
                                  "email_notifications_preferred": True,
                                  "sms_notifications_preferred": True,
                                  "push_notifications_preferred": True
                              }
                          }],
                          locations=[{
                              "app_name": channel.app_name,
                              "location": {
                                  "name": user[8],
                                  "coordinates": coordinates,
                                  "ward_id": user[9],
                                  "city_id": city_id
                              }
                          }])

        profile.save()

        #role.update(push__profile_ids=str(profile.id))

        #print('User: '******'==' + str(profile.id) + ' indexed')
        print('User: '******' indexed')
    else:
        print('User: '******' already exists')

    return True