Example #1
0
def migrate_address(doc):
    from locations.models import Address, Country
    from accounts.models import Account
    from users.models import Profile
    from utils import utils
    add = Address()
    add.type = 'user'
    add.profile = Profile.objects.get(primary_phone=doc['mobile'])
    add.name = doc.get('deliveryName','')
    add.phone = doc.get('deliveryPhone','')
    add.pincode = doc.get('pincode2','')
    if doc.get('address2','').strip():
        add.address = doc.get('address2','')
    if doc.get('country2','').strip():
        add.country = utils.get_or_create_country(doc.get('country2',''))
    else:
        add.country = Country.objects.get(name='India')
    if doc.get('state2','').strip():
        add.state = utils.get_or_create_state(doc.get('state2',''), add.country, True)
        if doc.get('city2', ''):
            add.city = utils.get_or_create_city(doc.get('city2',''), add.state, True)
    try:
        if add.address and add.city and add.country and add.state and add.profile:
            add.save()
            amap = AddressMap(address=add)
            amap.save()
    except Exception, e:
        print repr(e)
Example #2
0
def migrate_address(doc):
    from locations.models import Address, Country
    from accounts.models import Account
    from users.models import Profile
    from utils import utils
    add = Address()
    add.type = 'user'
    add.profile = Profile.objects.get(primary_phone=doc['mobile'])
    add.name = doc.get('deliveryName', '')
    add.phone = doc.get('deliveryPhone', '')
    add.pincode = doc.get('pincode2', '')
    if doc.get('address2', '').strip():
        add.address = doc.get('address2', '')
    if doc.get('country2', '').strip():
        add.country = utils.get_or_create_country(doc.get('country2', ''))
    else:
        add.country = Country.objects.get(name='India')
    if doc.get('state2', '').strip():
        add.state = utils.get_or_create_state(doc.get('state2', ''),
                                              add.country, True)
        if doc.get('city2', ''):
            add.city = utils.get_or_create_city(doc.get('city2', ''),
                                                add.state, True)
    try:
        if add.address and add.city and add.country and add.state and add.profile:
            add.save()
            amap = AddressMap(address=add)
            amap.save()
    except Exception, e:
        print repr(e)
Example #3
0
    addr.pincode = doc.get('pincode','')
    if doc.get('address','').strip():
        addr.address = doc.get('address','')
    if doc.get('country','').strip():
        addr.country = utils.get_or_create_country(doc.get('country',''))
    else:
        addr.country = Country.objects.get(name='India')
    if doc.get('state','').strip():
        addr.state = utils.get_or_create_state(doc.get('state',''), addr.country, True)
        if doc.get('city', ''):
            addr.city = utils.get_or_create_city(doc.get('city',''), addr.state, True)
    try:
        if addr.address and addr.city and addr.country and addr.state and addr.profile:
            if not addr.is_same_as(add):
                addr.save()
                amap = AddressMap(address=addr)
                amap.save()
    except Exception, e:
        print repr(e)

def migrate_active_user_addresses():
    count_query = solr_search('isActive:true')
    total = int(str(count_query.numFound))
    batch_size = 1000
    retrieved = 0

    print 'Found total of %s users' % total

    while retrieved < total:
        print 'Fetching %s results starting from %s' % (batch_size, retrieved)
        params = {'start':retrieved,'rows':batch_size}
Example #4
0
        addr.address = doc.get('address', '')
    if doc.get('country', '').strip():
        addr.country = utils.get_or_create_country(doc.get('country', ''))
    else:
        addr.country = Country.objects.get(name='India')
    if doc.get('state', '').strip():
        addr.state = utils.get_or_create_state(doc.get('state', ''),
                                               addr.country, True)
        if doc.get('city', ''):
            addr.city = utils.get_or_create_city(doc.get('city', ''),
                                                 addr.state, True)
    try:
        if addr.address and addr.city and addr.country and addr.state and addr.profile:
            if not addr.is_same_as(add):
                addr.save()
                amap = AddressMap(address=addr)
                amap.save()
    except Exception, e:
        print repr(e)


def migrate_active_user_addresses():
    count_query = solr_search('isActive:true')
    total = int(str(count_query.numFound))
    batch_size = 1000
    retrieved = 0

    print 'Found total of %s users' % total

    while retrieved < total:
        print 'Fetching %s results starting from %s' % (batch_size, retrieved)