def handle_noargs(self, **options): from ProfileApp.models import UserProfile from django.contrib.auth.models import User users = User.objects.all() for user in users: if not UserProfile.objects.filter(user_id=user.id): profile = UserProfile(user_id=user.id) profile.save()
def register_user(request): username = request.POST['username'] if User.objects.filter(username = username).exists(): return HttpResponseRedirect(reverse('users:protected')) first_name = request.POST['first_name'] last_name = request.POST['last_name'] email = request.POST['email'] password = request.POST['password'] birthday = request.POST['birthday'] location = request.POST['location'] description = request.POST['description'] user = User.objects.create_user(username, email, password) userprofile = UserProfile(user=user, username=username, first_name=first_name, last_name=last_name, birthday=birthday, location=location, description=description, spoiler_protection=False) userprofile.save() login(request, user) return HttpResponseRedirect(reverse('users:protected'))
def register(request): args = {} args.update(csrf(request)) if request.POST: register_form = RegisterForm(request.POST) if register_form.is_valid(): new_user = register_form.save() user = auth.authenticate( username=register_form.cleaned_data['username'], password=register_form.cleaned_data['password1'] ) group = Group.objects.get(name='registered_user') group.user_set.add(user) profile = UserProfile(user_id=new_user.pk) profile.save() if request.is_ajax(): return HttpResponse( "OK", content_type='text/html' ) return redirect('/auth/login.html') else: args['register_form'] = register_form else: args['register_form'] = RegisterForm() html = render_to_response( 'register_content.html', args, context_instance=RequestContext(request) ).serialize()[42:] if request.is_ajax(): return HttpResponse( html, content_type='text/html' ) return render_to_response( 'register.html', { "register_content": html, "articles": get_articles(request.user) } )