本文整理汇总了Python中profiles.models.Profile.save方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.save方法的具体用法?Python Profile.save怎么用?Python Profile.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profiles.models.Profile
的用法示例。
在下文中一共展示了Profile.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: thanks
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
def thanks(request, redirect_url=settings.LOGIN_REDIRECT_URL):
# Now that we've got the magic tokens back from Twitter, we need to exchange
# for permanent ones and store them...
oauth_token = request.session['request_token']['oauth_token']
oauth_token_secret = request.session['request_token']['oauth_token_secret']
twitter = Twython(settings.TWITTER_KEY, settings.TWITTER_SECRET,
oauth_token, oauth_token_secret)
# Retrieve the tokens we want...
authorized_tokens = twitter.get_authorized_tokens(request.GET['oauth_verifier'])
# If they already exist, grab them, login and redirect to a page displaying stuff.
try:
user = User.objects.get(username=authorized_tokens['screen_name'])
except User.DoesNotExist:
# We mock a creation here; no email, password is just the token, etc.
user = User.objects.create_user(authorized_tokens['screen_name'], "[email protected]", authorized_tokens['oauth_token_secret'])
profile = Profile()
profile.user = user
profile.oauth_token = authorized_tokens['oauth_token']
profile.oauth_secret = authorized_tokens['oauth_token_secret']
profile.save()
user = authenticate(
username=authorized_tokens['screen_name'],
password=authorized_tokens['oauth_token_secret']
)
login(request, user)
redirect_url = request.session.get('next_url', redirect_url)
return HttpResponseRedirect("/")
示例2: handle
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
def handle(self, *args, **options):
for u in User.objects.all():
p = Profile()
p.member = u
p.save()
self.stdout.write('Profiles synced!')
示例3: user_reg
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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, }))
示例4: create_profile
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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
示例5: create
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
def create(self, validated_data):
user = Profile(**validated_data)
user.set_password(validated_data['password'])
user.save()
# FIXME
self.fields.pop('password')
return user
示例6: create_team
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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))
示例7: User_Profile_Registration
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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('/')
示例8: get_profile
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
def get_profile(user):
try:
return Profile.all().filter("user = ", user)[0]
except IndexError:
profile = Profile(user=user, notification=5)
profile.save()
return profile
示例9: handle_label
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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)
示例10: register_complete
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
def register_complete(request, id_booster, key):
user = authenticate(username=id_booster, password=key)
if not user:
raise Http404
if request.method == "POST":
form = ProfileCoreForm(request.POST)
if form.is_valid():
# User
user.first_name = form.cleaned_data["first_name"].lower().title()
user.last_name = form.cleaned_data["last_name"].upper()
user.set_password(form.cleaned_data["password"])
user.is_active = True
user.save()
# create corresponding profile
profile = Profile()
profile.user_id = user.id
profile.id_booster = user.username
profile.promotion = form.cleaned_data["promotion"]
profile.set_last_name(user.last_name)
profile.save()
# log & redirect
user_auth = authenticate(username=user.username, password=form.cleaned_data["password"])
login(request, user_auth)
return redirect("accounts-register-rules")
else:
form = ProfileCoreForm()
context = {"form": form, "pending_user": user}
return direct_to_template(request, "accounts/register_complete.html", extra_context=context)
示例11: save
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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()
示例12: create_default_profile
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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: create_profile
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
def create_profile(user, fname, lname, zip):
profile = Profile()
profile.user = user
profile.first_name = fname
profile.last_name = lname
profile.zip_code = zip
profile.save()
return profile
示例14: register
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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)
示例15: form_valid
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import save [as 别名]
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
}
)