def add_location_to_user(user):
    try:
        if user.profile.place:
            place = json.loads(user.profile.place)

            location = Location.create(
                lat=repr(place['lat']),
                lng=repr(place['long']),
                city=place['city'],
                state=place['state'] if 'state' in place else '',
                country=place['country'],
                country_short=place['country_short'],
                post_code=place['post_code'] if 'post_code' in place else '',
                city_alias=place['city'] + ',')
            user.profile.location = location
            user.profile.latlong = ','.join(
                [format(place['lat'], '.6f'),
                 format(place['long'], '.6f')])
            user.profile.save()

    except Exception as e:
        print(Colorizer.Red('###############################'))
        print(Colorizer.Red('[ERROR Add location error]'))
        print(Logger.error(e))
        print(Colorizer.Red('###############################'))
    else:
        print(Colorizer.Green('LOCATION OK: ' + user.email))
def add_place_to_profile(profile):
    try:
        profile.sanitize_place(force=True)
    except Exception as e:
        print(Colorizer.Red('###############################'))
        print(Colorizer.Red('sanitize place error'))
        print(Colorizer.Red(e))
        print(Colorizer.Red('###############################'))
    else:
        print(Colorizer.Green('PLACE OK: ' + profile.user.email))
Ejemplo n.º 3
0
def run():
    profiles = Profile.objects.all()
    for profile in profiles:
        try:
            update_activities(profile.user)
        except Exception as e:
            print(Colorizer.Red('####################################'))
            print(Colorizer.Red('Error updating activities'))
            print(Colorizer.Red(e))
            print(Colorizer.Red('####################################'))
        else:
            print(Colorizer.Green('Acitivity updated :' + profile.user.email))
Ejemplo n.º 4
0
def user_sync_template(callback=lambda x: x, args=[]):
    errored = []
    profiles = Profile.objects.filter(user__email=args[0]) \
        if len(args) > 0 \
        else Profile.objects.all()
    print(' ')
    print(Colorizer.Yellow('############ START UPDATING ###########'))
    print(' ')
    for k, profile in enumerate(profiles):
        counter = '(' + str(k) + ' of ' + str(len(profiles)) + ')'
        results = callback(profile)
        if results is not True:
            print(
                Colorizer.Red(counter + 'UPDATE ERROR : ' +
                              profile.user.email))
            [print('   ' + line) for line in str(results['error']).split('\n')]
            errored.append(results)
        else:
            print(
                Colorizer.Cyan(counter) + '' +
                Colorizer.Green('User updated: ') + profile.user.email)

    print(Colorizer.Yellow(' '))
    print(Colorizer.Yellow('############### RESULTS ###############'))
    print('')
    print(
        Colorizer.Green(
            str(len(profiles) - len(errored)) +
            ' USERS WAS SUCCESFULLY UPDATED'))
    print(' ')
    print(Colorizer.Red(str(len(errored)) + ' USERS WITH ERRORS'))
    for error in errored:
        print('    ')
        print('    ' + Colorizer.Red(error['user'].email + ' - UUID: ' +
                                     str(error['user'].id)))
        print('      | EXCEPTION: ')
        [print('      | ' + line) for line in str(error['error']).split('\n')]
    print(Colorizer.Yellow(' '))
    print(Colorizer.Yellow('#######################################'))
Ejemplo n.º 5
0
def update_crm(user=None):
    errored = []
    partially_updated = []
    party = None

    users = user or User.objects.all()

    for user in users:
        try:
            print('--------------------')
            print('UPDATING USER : %s' % user)
            print('--------------------')
            print(' ')
            party = Party(user)
            party.create_or_update()
            print Colorizer.Green('UPDATED %s' % user)
            print(' ')

        except Profile.DoesNotExist as e:
            print Colorizer.custom('[ERROR USER MALFORMED] : %s ' % e, 'white',
                                   'purple')
            print(' ')

        except CRMValidationException as e:
            try:
                print Colorizer.Red(
                    'Try to exclude incompatible custom fields for user: %s' %
                    user)
                party.safe_create_or_update()
                partially_updated.append(user.email)
                print Colorizer.Yellow('UPDATED partially: %s' % user)
                print(' ')

            except Exception as safe_exc:
                print Colorizer.Red('[ ERROR IN SAFE UPDATE ] : %s' % safe_exc)
                print json.dumps(party.as_dict(), indent=1)
                print(' ')

                print Colorizer.Red('ERROR UPDATING USER : %s' % user)
                print('ERROR: %s' % e)
                print(' ')
                errored.append(user.email)

        except Exception as e:
            print Colorizer.Red('ERROR UPDATING USER : %s' % user)
            print('ERROR: %s' % e)
            print(' ')

    return errored, partially_updated
Ejemplo n.º 6
0
def print_results(errored=None, partially_updated=None):
    # PRINT RESULTS
    print '-------------'
    print 'TOTAL RESULTS'
    print '-------------'

    if len(errored):
        print Colorizer.Red('%s errored users' % len(errored))
        # logger.error('ERROR updating users : %s' % errored)
        print errored

    if len(partially_updated):
        print Colorizer.Purple('%s partially updated users : ' %
                               len(partially_updated))
        print(partially_updated)

    elif not len(errored) and not len(partially_updated):
        print Colorizer.Green('No errored users')
    print '-------------'
Ejemplo n.º 7
0
def update_default_profile_image(users):
    errored = []
    sanititized = []
    for user in users:
        try:
            if user.profile.picture == 'images/profile/default_user_icon.png':
                print('--------------------')
                print('UPDATING USER : %s' % user)
                print('--------------------')
                print(' ')
                if user.profile.gender == 'male':
                    user.profile.picture = 'images/profile/male.svg'
                if user.profile.gender == 'female':
                    user.profile.picture = 'images/profile/female.svg'
                if user.profile.gender == 'other':
                    user.profile.picture = 'images/profile/other.svg'
                sanititized.append(user.email)
                user.profile.save()
        except Profile.DoesNotExist as e:
            errored.append(user.email)
            print(
                Colorizer.custom('[ERROR USER MALFORMED] : %s ' % e, 'white',
                                 'purple'))
            print(' ')
    # PRINT RESULTS
    print('-------------')
    print('TOTAL RESULTS')
    print('-------------')

    if len(errored):
        print(Colorizer.Red('%s errored users' % len(errored)))
        print(errored)

    if len(sanititized):
        print(Colorizer.Purple('%s updated users : ' % len(sanititized)))
        print(sanititized)

    elif not len(errored) and not len(sanititized):
        print(Colorizer.Green('no updates or errors'))
    print('-------------')
Ejemplo n.º 8
0
def run(*args):
    errored = []
    profiles = Profile.objects.filter(user__email=args[0]) \
        if len(args) > 0 \
        else Profile.objects.all()

    print(Colorizer.Yellow(' '))
    print(Colorizer.Yellow('############### RESULTS ###############'))
    print('')
    print(
        Colorizer.Green(
            str(len(profiles) - len(errored)) +
            ' USERS WAS SUCCESFULLY UPDATED'))
    print(' ')
    print(Colorizer.Red(str(len(errored)) + ' USERS WITH ERRORS :'))
    for error in errored:
        print('    ')
        print('    ' + Colorizer.Red(error['user'].email + ' UUID: ' +
                                     str(error['user'].id)))
        print('      | EXCEPTION: ')
        [print('      | ' + line) for line in str(error['error']).split('\n')]
    print(Colorizer.Yellow(' '))
    print(Colorizer.Yellow('#######################################'))
Ejemplo n.º 9
0
def create_or_update_party(users):
    errored = []
    sanititized = []
    party = None
    for user in users:
        try:
            print('--------------------')
            print('UPDATING USER : %s' % user)
            print('--------------------')
            print(' ')
            # logger.debug('UPDATING %s' % user)
            party = Party(user)
            party.create_or_update()
            # logger.debug('UPDATED')
            print(Colorizer.Green('UPDATED %s' % user))
            print(' ')

        except Profile.DoesNotExist as e:
            print(
                Colorizer.custom('[ERROR USER MALFORMED] : %s ' % e, 'white',
                                 'purple'))
            print(' ')

        except Exception as e:
            try:
                print(
                    Colorizer.Red(
                        'Try to exclude incompatible custom fields for user: %s'
                        % user))
                party.safe_create_or_update()
                sanititized.append(user.email)
                print(Colorizer.Yellow('UPDATED partially: %s' % user))
                print(' ')

            except Exception as safe_exc:
                print(Colorizer.Red('[ ERROR IN SAFE UPDATE ] : %s' %
                                    safe_exc))
                print(json.dumps(party.as_dict(), indent=1))
                print((' '))

                print(Colorizer.Red('ERROR UPDATING USER : %s' % user))
                print('ERROR: %s' % e)
                print(' ')
                errored.append(user.email)

    # PRINT RESULTS
    print('-------------')
    print('TOTAL RESULTS')
    print('-------------')

    if len(errored):
        print(Colorizer.Red('%s errored users' % len(errored)))
        # logger.error('ERROR updating users : %s' % errored)
        print(errored)

    if len(sanititized):
        print(
            Colorizer.Purple('%s partially updated users : ' %
                             len(sanititized)))
        print(sanititized)

    elif not len(errored) and not len(sanititized):
        print(Colorizer.Green('No errored users'))
    print('-------------')