Example #1
0
    def create_user(self, username, email, password):
        '''
		'''
        try:
            user = User.objects.filter(username__iexact=username)
        except:
            user = None
        if user:
            return False

        try:
            user = User.objects.filter(email__iexact=email)
        except:
            user = None
        if user:
            return False

        try:
            user = UserProfile.objects.filter(email_unconfirmed__iexact=email)
        except:
            user = None
        if user:
            return False

        try:
            new_user = User.objects.create_user(username=username,
                                                password=password)
            new_user.is_active = False
            new_user.save()
        except:
            return False

        confirm_key = generate_sha1()
        account = self.create(user=new_user, \
                  confirm_key=confirm_key, \
                  confirm_key_creat_time = now(), \
                  email_unconfirmed = email, \
                  last_active = now())
        account.send_confirm_email()

        profile = UserProfile(user=new_user)
        try:
            anonymous = User.objects.get(pk=ANONYMOUS_ID)
        except:
            anonymous = self.create_anonymous()
        profile.avatar = anonymous.userprofile.avatar
        profile.username = username
        profile.save()

        # print 'send create_user_done signal'
        # create_user_done.send(sender='UserAccount', user=new_user)
        filename = get_gravatar(account.email_unconfirmed)
        if filename:
            avatar = Avatar()
            avatar.avatar_save(filename)
            remove(filename)
            profile.avatar = avatar
            profile.save()

        return new_user
Example #2
0
	def create_user(self, username, email, password):
		'''
		'''
		try:
			user = User.objects.filter(username__iexact=username)
		except:
			user = None
		if user:
			return False
			
		try:
			user = User.objects.filter(email__iexact=email)
		except:
			user = None
		if user:
			return False
		
		try:
			user = UserProfile.objects.filter(email_unconfirmed__iexact = email)
		except:
			user = None
		if user:
			return False
		
		try:
			new_user = User.objects.create_user(username=username, password=password)
			new_user.is_active = False
			new_user.save()
		except:
			return False
		
		confirm_key = generate_sha1()
		account = self.create(user=new_user, \
		          confirm_key=confirm_key, \
		          confirm_key_creat_time = now(), \
		          email_unconfirmed = email, \
		          last_active = now())
		account.send_confirm_email()
		
		profile = UserProfile(user=new_user)
		try:
			anonymous = User.objects.get(pk=ANONYMOUS_ID)
		except:
			anonymous = self.create_anonymous()
		profile.avatar = anonymous.userprofile.avatar
		profile.username = username
		profile.save()
		
		# print 'send create_user_done signal'
		# create_user_done.send(sender='UserAccount', user=new_user)
		filename = get_gravatar(account.email_unconfirmed)
		if filename:
			avatar = Avatar()
			avatar.avatar_save(filename)
			remove(filename)
			profile.avatar = avatar
			profile.save()
		
		return new_user
Example #3
0
    def create_anonymous(self):
        '''
		'''
        anonymous = User(id=ANONYMOUS_ID, \
                         username=ANONYMOUS_USERNAME, \
                         password=ANONYMOUS_PASSWORD) # this password will
        # never be used!
        anonymous.save()
        avatar = Avatar()
        avatar.avatar_save(MEDIA_ROOT + ANONYMOUS_USERNAME + '.jpg')

        profile = UserProfile(user=anonymous)
        profile.avatar = avatar
        profile.name = ANONYMOUS_NAME
        profile.save()

        # there while add some other thing

        return anonymous
Example #4
0
	def create_anonymous(self):
		'''
		'''
		anonymous = User(id=ANONYMOUS_ID, \
		                 username=ANONYMOUS_USERNAME, \
		                 password=ANONYMOUS_PASSWORD) # this password will 
		                                              # never be used!
		anonymous.save()
		avatar = Avatar()
		avatar.avatar_save(MEDIA_ROOT + ANONYMOUS_USERNAME + '.jpg')
		
		profile = UserProfile(user=anonymous)
		profile.avatar=avatar
		profile.name = ANONYMOUS_NAME
		profile.save()
		
		# there while add some other thing
		
		return anonymous
Example #5
0
    def save(self, t):
        data = self.cleaned_data
        t.detail = data['detail']

        if data['avatar']:
            img = data['avatar']
            anonymous = get_tag_avatar()
            if t.avatar == anonymous:
                avatar = Avatar()
                avatar.avatar_save(img)
                t.avatar = avatar
            else:
                t.avatar.avatar_delete()
                t.avatar.avatar_save(img)

        try:
            t.save()
        except:
            pass

        return t
Example #6
0
	def save(self, t):
		data = self.cleaned_data
		t.detail = data['detail']
		
		if data['avatar']:
			img = data['avatar']
			anonymous = get_tag_avatar()
			if t.avatar == anonymous:
				avatar = Avatar()
				avatar.avatar_save(img)
				t.avatar = avatar
			else:
				t.avatar.avatar_delete()
				t.avatar.avatar_save(img)
		
		try:
			t.save()
		except:
			pass
		
		return t
Example #7
0
	def save(self, d):
		data = self.cleaned_data
		d.name = data['name'][:NAME_MAX_LEN]
		d.detail = data['detail']
		
		if data['avatar']:
			img = data['avatar']
			anonymous = get_tag_avatar()
			if d.avatar == anonymous:
				avatar = Avatar()
				avatar.avatar_save(img)
				d.avatar = avatar
			else:
				d.avatar.avatar_delete()
				d.avatar.avatar_save(img)
		
		try:
			d.save()
		except:
			pass
		
		return d
Example #8
0
    def save(self, profile, data):
        if profile.name != data['name']:
            profile.change_name(data['name'][:NAME_MAX_LEN])

        profile.website = data['website']
        profile.signature = data['signature'][:SIGNATURE_MAX_LEN]
        profile.detail = data['detail']

        if data['avatar']:
            img = data['avatar']
            anonymous = User.objects.get(pk=ANONYMOUS_ID)
            if profile.avatar != anonymous.userprofile.avatar:
                profile.avatar.avatar_delete()
                profile.avatar.avatar_save(img)
            else:
                avatar = Avatar()
                avatar.avatar_save(img)
                profile.avatar = avatar
        try:
            profile.save()
        except:
            pass
        return profile
Example #9
0
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase

'''
class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)
'''

from avatars.models import Avatar
a = Avatar()
a.avatar_save("marvin.jpg")
Example #10
0
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase
'''
class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)
'''

from avatars.models import Avatar
a = Avatar()
a.avatar_save("marvin.jpg")