Esempio n. 1
0
 def __exclude_custom_fields(self):
     remote_custom_fields = self.get_custom_field_definitions()
     for field in self.fields:
         customs = filter(lambda x: x['id'] == field['definition']['id'],
                          remote_custom_fields)
         if len(customs) > 0:
             custom = customs[0]
             if custom['type'] == 'list' and not field['value'] in custom[
                     'options']:
                 print Colorizer.Yellow('Excluding field : %s ' % field)
                 self.fields.remove(field)
                 print Colorizer.Yellow('Field Excluded')
Esempio n. 2
0
 def __exclude_custom_fields(self):
     remote_custom_fields = self.get_custom_field_definitions()
     for field in self.fields:
         customs = filter(lambda x: x['id'] == field['definition']['id'],
                          remote_custom_fields)
         try:
             custom = customs[0]
             if custom['type'] == 'list' and not field['value'] in custom[
                     'options']:
                 print(
                     Colorizer.Yellow('Excluding field : {} ',
                                      format(field)))
                 self.fields.remove(field)
                 print(Colorizer.Yellow('Field Excluded'))
         except:
             pass
Esempio n. 3
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('#######################################'))
Esempio n. 4
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('#######################################'))
Esempio 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
Esempio n. 6
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('-------------')