本文整理汇总了Python中profiles.models.Profile类的典型用法代码示例。如果您正苦于以下问题:Python Profile类的具体用法?Python Profile怎么用?Python Profile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Profile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_reg
def user_reg(request):
username = request.POST.get('username')
email = request.POST.get('email')
password = request.POST.get('password')
name = request.POST.get('student_name')
gender = request.POST.get('gender')
registerTime = datetime.now()
if not (username and email and password):
return HttpResponse(json.dumps({"error_code": "Can not be empty!", }), status=400)
try:
upr = User.objects.get(username=username) #check if there is duplicated username
except User.DoesNotExist:
upr = None
if upr is not None:
return HttpResponse(json.dumps({"error": "用户名已被占用", }))
try:
upr = User.objects.get(email=email) #check if there is duplicated email
except User.DoesNotExist:
upr = None
if upr is not None:
return HttpResponse(json.dumps({"error": "Email已被使用", }))
try:
validate_email(email)
except ValidationError:
return HttpResponse(json.dumps({"error": "Email格式不正确", }))
upr = User.objects.create_user(username, email, password)
pr = Profile(user=upr, name=name, gender=gender, registerTime=registerTime)
pr.save()
return HttpResponse(json.dumps({"id": upr.id, }))
示例2: create
def create(self, validated_data):
user = Profile(**validated_data)
user.set_password(validated_data['password'])
user.save()
# FIXME
self.fields.pop('password')
return user
示例3: create_team
def create_team(request, username):
"""
Display the TeamCreationForm
"""
if request.method == 'POST':
form = TeamCreationForm(request.POST)
if form.is_valid() and request.user.pk == form.cleaned_data['creator']:
team = User.objects.create_user(form.cleaned_data['name'])
team_creator_attrs = dict(
team=team,
user=request.user,
permission=4,
creator=True
)
team_creator = TeamMember(**team_creator_attrs)
team_creator.save()
try:
profile = team.get_profile()
except Profile.DoesNotExist:
profile = Profile(user=team)
profile.organization = True
profile.creator_id = request.user.pk
profile.save()
HttpResponseRedirect(reverse('update_team', args=(form.cleaned_data["name"],)))
else:
form = TeamCreationForm(initial={'creator': request.user.pk})
return render_to_response('teams/team_create.html',
{'form': form, 'username': username},
context_instance=RequestContext(request))
示例4: test_profile
def test_profile(self):
from profiles.models import Profile
p = Profile()
self.assertEqual(len(p.my_packages()), 0)
r = MockGithubRepo()
self.assertEqual(p.url_for_repo(r), None)
示例5: get_profile
def get_profile(user):
try:
return Profile.all().filter("user = ", user)[0]
except IndexError:
profile = Profile(user=user, notification=5)
profile.save()
return profile
示例6: handle_label
def handle_label(self, username, **options):
from django.contrib.auth.models import User
from profiles.models import Profile
if '@' in username:
kwargs = {'email': username}
else:
kwargs = {'username': username}
try:
profile = Profile.objects.get(**kwargs)
except Profile.DoesNotExist:
try:
user = User.objects.get(**kwargs)
except User.DoesNotExist:
raise CommandError("User '%s' does not exist" % username)
print "Adding profile for %s" % username
initial = dict([(f.name, getattr(user, f.name)) for f in user._meta.fields])
profile = Profile(user_ptr=user, **initial)
profile.save()
for f in user._meta.many_to_many:
getattr(profile, f.name).add(*getattr(user, f.name).all())
else:
raise CommandError("Profile '%s' already exists" % username)
示例7: create_profile
def create_profile(user, gender=None, lname=None):
if gender is None:
gender = get_random_gender()
fname = get_random_fname(gender)
if lname is None:
lname = get_random_lname()
zc = get_random_zip()
photo = adult_photo(gender)
profile = Profile()
profile.user = user
profile.first_name = fname
profile.last_name = lname
profile.zip_code = zc
profile.gender = gender
profile.save()
f = open(photo, 'r')
np = Photo(album=profile.album, caption="Profile", original_image=File(f))
np.save()
profile.set_profile_pic(np)
return profile
示例8: User_Profile_Registration
def User_Profile_Registration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'POST':
form = RegistrationForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['profile_pic'])
user = User.objects.create_user(username=form.cleaned_data['username'], email = form.cleaned_data['email'], password = form.cleaned_data['password'])
user.first_name = form.cleaned_data['first_name']
user.last_name=form.cleaned_data['last_name']
user.save()
profile = Profile(user = user, countries=form.cleaned_data['countries'], about_me = form.cleaned_data['about_me'], birth_date = form.cleaned_data['birth_date'])
profile.profile_pic=form.cleaned_data['profile_pic']
profile.save()
registredUser = authenticate(username = form.cleaned_data['username'], password= form.cleaned_data['password'])
if registredUser is not None:
login(request, registredUser)
return HttpResponseRedirect('/')
else:
return HttpResponseRedirect('/registered')
else:
form = RegistrationForm()
context = { 'form' : form }
return render_to_response('register.html', context, context_instance=RequestContext(request))
return HttpResponseRedirect('/')
示例9: handle
def handle(self, *args, **options):
for u in User.objects.all():
p = Profile()
p.member = u
p.save()
self.stdout.write('Profiles synced!')
示例10: save
def save(self, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.email= self.cleaned_data['email']
user.username=user.email
profile= Profile(first_name=user.first_name, last_name=user.last_name, is_student=self.cleaned_data["is_student"], email=user.email, username=user.username)
profile.save()
user.save()
示例11: test_add_user
def test_add_user(self):
user = AppUser(user=User(email="[email protected]"),
username="test",
email="[email protected]",
is_staff=True).save()
assert not Profile.all().count()
profile = get_profile(user)
assert profile.notification == 5
assert Profile.all().count()
示例12: create_default_profile
def create_default_profile(app, created_models, verbosity, **kwargs):
try:
user = User.objects.get(id=1)
except User.DoesNotExist:
user = User(id=1, username="default_user", email=settings.DEFAULT_FROM_EMAIL)
user.save()
profile = Profile(user=user, first_name="Notification")
profile.save()
示例13: register
def register(request):
''' Registration for new users and new profiles '''
# if the user is already logged in, send them to their profile
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
# form was submitted
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = User.objects.create_user(username=username,password=password)
user.save()
age = form.cleaned_data['age']
zipcode = form.cleaned_data['zipcode']
state = form.cleaned_data['state']
gender = form.cleaned_data['gender']
one_k = form.cleaned_data['one_k']
five_k = form.cleaned_data['five_k']
ten_k = form.cleaned_data['ten_k']
one_mile = form.cleaned_data['one_mile']
five_mile = form.cleaned_data['five_mile']
ten_mile = form.cleaned_data['ten_mile']
half_marathon = form.cleaned_data['half_marathon']
full_marathon = form.cleaned_data['full_marathon']
ultra_marathon = form.cleaned_data['ultra_marathon']
trail_run = form.cleaned_data['trail_run']
cross_country = form.cleaned_data['cross_country']
short_distance = form.cleaned_data['short_distance']
long_distance = form.cleaned_data['long_distance']
competitive = form.cleaned_data['competitive']
profile = Profile(
user=user, age=age,zipcode=zipcode,state=state,
gender=gender,one_k=one_k,five_k=five_k,
ten_k=ten_k,one_mile=one_mile,five_mile=five_mile,
ten_mile=ten_mile,half_marathon=half_marathon,
full_marathon=full_marathon,ultra_marathon=ultra_marathon,
trail_run=trail_run,cross_country=cross_country,
short_distance=short_distance,long_distance=long_distance,
competitive=competitive)
profile.save()
user = authenticate(username=username,password=password)
auth_login(request,user)
return HttpResponseRedirect('/profile/')
# form was not valid
else:
context = {'form': form}
return render(request,'profiles/register.html', context)
# user is not submitting the form
else:
form = RegistrationForm()
context = { 'form': form }
return render(request,'profiles/register.html', context)
示例14: form_valid
def form_valid(self, form):
"""Form Valid
If form valid User save in database with his profile.
Generate Activation key with expire date.
For User's email sended confirmation letter
Return:
Redirect
"""
form.save()
user_email = form.cleaned_data['email']
activation_key = self.generate_activation_key(user_email)
key_expires = self.generate_key_expires(settings.KEY_EXPIRE_TERM)
user = User.objects.get(email=user_email)
user.groups.add(Group.objects.get(name='customers'))
slug = self.create_slug(user)
new_profile = Profile(
user=user,
activation_key=activation_key,
key_expires=key_expires,
slug=slug
)
new_profile.save()
email_data = {
'username': user.username,
'activation_key': activation_key
}
email = SendEmailClass(
subject=_('Account Confirmation'),
sender=settings.EMAIL_HOST_USER,
to=settings.EMAIL_SUPERUSERS,
template=settings.EMAIL_TEMPLATES['confirmation'],
data=email_data
)
email.send()
return render(
self.request,
settings.REGISTRATION_TEMPLATES['thanks'],
context={
'username': user.username,
'email': user.email
}
)
示例15: get_profile
def get_profile(request):
user = request.user
if user.is_authenticated():
try:
profile = user.get_profile()
except Profile.DoesNotExist:
profile = Profile(user=user, name=user.username)
profile.save()
else:
profile = "Anonymous"
return {"profile": profile}