コード例 #1
0
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))
コード例 #2
0
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))
コード例 #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))
コード例 #4
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
コード例 #5
0
    def test3_profile_interest_in_company(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should link an interest(Company)')

        self.user.profile.add_interest(self.company)
        interests = self.user.profile.get_interests()

        self.assertGreater(len(interests), 0, Colorizer.Red('No Company linked'))
コード例 #6
0
    def test8_delete_profile(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] deleting profile should delete related interest')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)
        self.user.profile.delete()

        self.assertEqual(len(Interest.objects.all()), 0, Colorizer.Red('Deleting profile does not remove related interest objects'))
コード例 #7
0
ファイル: test_connector.py プロジェクト: xecron/dsp-explorer
    def test2_get_alternate_city_names(self):
        print Colorizer.LightPurple('\n[TEST PROFILE LOCATION] assert should respond')

        latlng = self.user.profile.location.lat+','+self.user.profile.location.lng
        response = OpenDataConnector.get_city_alternate_name_by_latlng(latlng)

        self.assertIsNotNone(
            response,
            Colorizer.Red('City alternate names is not present on response')
        )
コード例 #8
0
ファイル: test_project.py プロジェクト: xecron/dsp-explorer
 def test1_create_project(self):
     print Colorizer.LightPurple('\n[TEST project] should create a project')
     project = Project(
         title='Prova project',
         picture='images/profile/default_user_icon.png',
         details='Prova description'
     )
     project.profile = self.user.profile
     project.save()
     self.assertTrue(Project.objects.get(title='Prova project'), Colorizer.Red('Create project Error'))
コード例 #9
0
    def test2_profile_interest_in_challenge(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should link an interest(Challenge)')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')

        self.user.profile.add_interest(challenge)
        interests = self.user.profile.get_interests()

        self.assertGreater(len(interests), 0, Colorizer.Red('No Challenge linked'))
コード例 #10
0
    def test5_get_interested_from_challenge(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should return a list of profile interested in a challenge')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)

        profiles = challenge.interested()

        self.assertTrue(all(isinstance(x, Profile) for x in profiles), Colorizer.Red('Challenge related interest are not a porofile list'))
コード例 #11
0
    def test7_delete_interest_from_profile(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should should delete interest(challenge) from profile')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)

        self.user.profile.delete_interest(Challenge, challenge.id)
        challenges = self.user.profile.get_interests(Challenge)

        self.assertEqual(len(challenges), 0, Colorizer.Red('User interest(challenge) is not deleted'))
コード例 #12
0
ファイル: test_connector.py プロジェクト: xecron/dsp-explorer
    def test1_api_response(self):
        print Colorizer.LightPurple('\n[TEST PROFILE LOCATION] assert should respond correctly')

        latlng = self.user.profile.location.lat+','+self.user.profile.location.lng
        response = OpenDataConnector.get_by_latlng(latlng)

        self.assertLessEqual(
            response.status_code,
            202,
            Colorizer.Red('Update Response Error: \n code: %s \n Info : %s' % (response.status_code, response))
        )
コード例 #13
0
    def test4_profile_filter_interest_challenge(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should return only interests that are Challenges')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)

        self.user.profile.add_interest(self.company)
        interests = self.user.profile.get_interests(Challenge)

        self.assertTrue(all(isinstance(x, Challenge) for x in interests), Colorizer.Red('Filter interest does not return a list of challenge'))
コード例 #14
0
def run():
    profiles = Profile.objects.all()
    users = User.objects.all()
    for profile in profiles:
        try:
            profile.user
        except User.DoesNotExist:
            print(
                Colorizer.Red('User doesnt exist for profile with ID : ' +
                              str(profile.id)))
            profile.delete()
            print(Colorizer.Cyan('Removing profile'))
    for user in users:
        try:
            user.profile
        except Profile.DoesNotExist:
            print(
                Colorizer.Red('Profile doesnt exist for user ID: ' +
                              str(user.id) + ', EMAIL: ' + user.email))
            user.delete()
            print(Colorizer.Cyan('Removing user with EMAIL: ' + user.email))
コード例 #15
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('#######################################'))
コード例 #16
0
    def test1_add_country_aliases(self):
        print Colorizer.LightPurple(
            '\n[TEST PROFILE LOCATION] assert should add country aliases if doesnt exist'
        )

        # response = RestCountriesConnector.get_city_alias(self.location['country'])

        print 'country aliases'
        print self.user.profile.location.country_alias

        self.assertIsNotNone(
            None,
            Colorizer.Red('City alternate names is not present on response'))
コード例 #17
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('#######################################'))
コード例 #18
0
    def test6_get_interested_from_project(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should return a list of profile interested in a project')

        project = Project(
            title='Prova project',
            picture='images/profile/default_user_icon.png',
            details='Prova description'
        )
        project.profile = self.user.profile
        project.save()
        self.user.profile.add_interest(project)

        profiles = project.interested()

        self.assertTrue(all(isinstance(x, Profile) for x in profiles), Colorizer.Red('Challenge related interest are not a porofile list'))
コード例 #19
0
ファイル: test_project.py プロジェクト: xecron/dsp-explorer
    def test2_add_project_contributor(self):
        print Colorizer.LightPurple('\n[TEST project] should add a contributor to project')
        project = Project(
            title='Prova project',
            picture='images/profile/default_user_icon.png',
            details='Prova description'
        )
        project.profile = self.user.profile
        project.save()
        project.contributors.add(self.user.profile)
        project.save()

        new_project = Project.objects.get(title='Prova project')

        self.assertGreater(len(new_project.contributors.all()), 0, Colorizer.Red('Add contributor to project error'))
コード例 #20
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 '-------------'
コード例 #21
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('-------------')
コード例 #22
0
def get_test_user(user_email):
    user = User.objects.filter(email=user_email)
    return user if len(user) > 0 else User.objects.filter(
        email='*****@*****.**')


def pair_crm_ids():
    users = User.objects.all()
    for u in users:
        try:
            party = Party(u)
            party_crm_id = party.get()['id']
            profile = Profile.get_by_email(u)
            profile.set_crm_id(party_crm_id)
        except Exception as e:
            print 'PAIR CRM IDs %s' % u
            print 'PAIR CRM IDs %s' % e

    sys.exit("Paring finished")


if __name__ == "__main__":
    pair_crm_ids() if len(
        sys.argv) > 1 and sys.argv[1] == 'pair_crm_ids' else None
    user = get_test_user(sys.argv[1]) if len(sys.argv) > 1 else None
    if len(user) > 0:
        errored, partially_updated = update_crm(user)
        print_results(errored, partially_updated)
    else:
        print Colorizer.Red('No user found')
コード例 #23
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('-------------')
コード例 #24
0
 def test_2_check_reset_token(self):
     user = User.create(**self.userdata)
     profile = Profile.create(user=user, **self.userdata)
     print profile.reset_token
     self.assertIsNot(profile.reset_token, None, Colorizer.Red('Error during profile creation'))
コード例 #25
0
 def test1_create_challenge(self):
     print Colorizer.LightPurple('\n[TEST CHALLENGE] should create an interest(challenge)')
     Challenge.create('test challenge')
     self.assertTrue(Challenge.objects.get(title='test challenge'), Colorizer.Red('Create Challenge Error'))
コード例 #26
0
 def test_1_create(self):
     user = User.create(**self.userdata)
     profile = Profile.create(user=user, **self.userdata)
     self.assertIsInstance(profile, Profile, Colorizer.Red('Error during profile creation'))