Exemple #1
0
  def register(self, request, **kwargs):
    """
    Register a new user account, which will initially be inactive.

    It also creates corresponding user profile.
    """
    
    user = super(ProfileBackend, self).register(request, **kwargs)
    profile, created = utils.get_profile_model().objects.get_or_create(user=user)
    
    # lambda-object to the rescue
    form = lambda: None
    form.cleaned_data = kwargs
    
    # First name, last name and e-mail address are stored in user object
    forms_models.construct_instance(form, user)
    user.save()
    
    # Other fields are stored in user profile object
    forms_models.construct_instance(form, profile)
    profile.save()
    
    user_profile_registered.send(sender=self.__class__, user=user, profile=profile, request=request)
    
    return user
	def handle_noargs(self, **options):
		"""
		Populates database with user profiles for all users missing them.
		"""
		
		verbosity = int(options.get('verbosity', 1))
		model = utils.get_profile_model()
		for user in auth_models.User.objects.all():
			profile, created = model.objects.get_or_create(user=user)
			if verbosity == 2 and created:
				# TODO: Change to self.stdout.write
				print 'Created %s.' % profile
		transaction.commit_unless_managed()
def command_signal(sender, app, created_models, **kwargs):
	if utils.get_profile_model() in created_models:
		management.call_command('createprofiles', **kwargs)
from django.db.models import signals as models_signals

from web.account import utils

class Command(management_base.NoArgsCommand):
	"""
	This class defines an action for manage.py which populates database with user profiles for all users missing them.
	"""
	
	help = "Populate database with user profiles for all users missing them."

	def handle_noargs(self, **options):
		"""
		Populates database with user profiles for all users missing them.
		"""
		
		verbosity = int(options.get('verbosity', 1))
		model = utils.get_profile_model()
		for user in auth_models.User.objects.all():
			profile, created = model.objects.get_or_create(user=user)
			if verbosity == 2 and created:
				# TODO: Change to self.stdout.write
				print 'Created %s.' % profile
		transaction.commit_unless_managed()

def command_signal(sender, app, created_models, **kwargs):
	if utils.get_profile_model() in created_models:
		management.call_command('createprofiles', **kwargs)

models_signals.post_syncdb.connect(command_signal, sender=utils.get_profile_model().__module__)