Example #1
0
    def save(self):
        data = self.cleaned_data
        password = data.get('password1')
        u = User()

        u.username = data.get('username')
        u.password = make_password(password)
        u.email = data.get('email')
        u.first_name = data.get('first_name')
        u.last_name = data.get('last_name')
        u.is_active = True
        u.is_superuser = False
        u.save()

        up = Profile()
        up.user = u
        up.info = data.get('info')

        if data.get('avatar') is None:
            image_url = 'http://api.adorable.io/avatars/100/%s.png' % u.username
            content = urllib.urlretrieve(image_url)
            up.avatar.save('%s.png' % u.username, File(open(content[0])), save=True)
        else:
            avatar = data.get('avatar')
            up.avatar.save('%s_%s' % (u.username, avatar.name), avatar, save=True)

        up.save()

        return authenticate(username=u.username, password=password)
Example #2
0
    def handle(self, *args, **options):
        fake = Factory.create()
        fakeru = Factory.create('ru_RU')

        number = int(options['number'])
        
        for i in range(0, number):
            profile = fake.simple_profile()

            u = User()
            u.username = profile['username']
            u.first_name = fakeru.first_name()
            u.last_name = fakeru.last_name()
            u.email = profile['mail']
            u.password = make_password('tp2015')
            u.is_active = True
            u.is_superuser = False
            u.save()

            up = Profile()
            up.user = u
            up.info = '%s [%s]' % (fakeru.company(), fakeru.catch_phrase())

            image_url = 'http://api.adorable.io/avatars/100/%s.png' % u.username
            content = urllib.urlretrieve(image_url)
            up.avatar.save('%s.png' % u.username, File(open(content[0])), save=True)
            up.save()

            self.stdout.write('[%d] added user %s' % (u.id, u.username))
Example #3
0
    def save(self):
        data = self.cleaned_data
        password = data.get('password1')
        u = User()

        u.username = data.get('username')
        u.password = make_password(password)
        u.email = data.get('email')
        u.first_name = data.get('first_name')
        u.last_name = data.get('last_name')
        u.is_active = True
        u.is_superuser = False
        u.save()

        up = Profile()
        up.user = u
        up.info = data.get('info')

        if data.get('avatar') is None:
            image_url = 'http://api.adorable.io/avatars/100/%s.png'\
                        % u.username
            content = urllib.urlretrieve(image_url)
            up.avatar.save('%s.png' % u.username,
                           File(open(content[0])),
                           save=True)
        else:
            avatar = data.get('avatar')
            up.avatar.save('%s_%s' % (u.username, avatar.name),
                           avatar,
                           save=True)

        up.save()

        return authenticate(username=u.username, password=password)
Example #4
0
    def handle(self, *args, **options):
        fake = Factory.create()
        fakeru = Factory.create('ru_RU')

        number = int(options['number'])

        for i in range(0, number):
            profile = fake.simple_profile()

            u = User()
            u.username = profile['username']
            u.first_name = fakeru.first_name()
            u.last_name = fakeru.last_name()
            u.email = profile['mail']
            u.password = make_password('tp2015')
            u.is_active = True
            u.is_superuser = False
            u.save()

            up = Profile()
            up.user = u
            up.info = '%s (%s)' % (fakeru.company(), fakeru.company())

            image_url = 'http://api.adorable.io/avatars/100/%s.png'\
                        % u.username
            content = urllib.urlretrieve(image_url)
            up.avatar.save('%s.png' % u.username,
                           File(open(content[0])),
                           save=True)
            up.save()

            self.stdout.write('[%d] added user %s' % (u.id, u.username))