本文整理汇总了Python中users.models.Profile.save方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.save方法的具体用法?Python Profile.save怎么用?Python Profile.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.models.Profile
的用法示例。
在下文中一共展示了Profile.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def handle(self, *args, **options):
for user in User.objects.all():
if Profile.objects.filter(user=user).count() == 0:
print "No profile for user: %s" % (user,)
new_profile = Profile(user=user, activation_key=generate_activation_key(user.username))
new_profile.save()
print "Created new profile for username: %s" % (user.username,)
示例2: get_user_profile
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def get_user_profile(user):
""" Returns user profile. Creates one if needed """
if not (user and user.is_authenticated()):
return None
pr = cache.get("users_profile:auth_user=%s" % user.id, None)
if pr:
return pr
pr = get_profile_by_email_or_phone(user.username)
if not pr:
pr = Profile.objects.filter(user=user).order_by("id")[:2]
if len(pr) > 1:
fb_log.info("Multiple profiles for user: %s" % user.username)
if pr:
pr = pr[0]
if not pr:
pr = Profile(user=user)
pr.created_on = datetime.now()
pr.save()
if is_valid_email(user.username):
try:
email = Email(email=user.username, user=pr, type="primary")
email.save()
except:
pass
if is_valid_mobile(user.username):
try:
phone = Phone(phone - user.username, user=pr, type="primary")
phone.save()
except:
pass
cache.set("users_profile:auth_user=%s" % user.id, pr)
return pr
示例3: create_user
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def create_user(username, email_id="", password=None, first_name="", last_name=""):
""" This function called for new user sign up on p. interface. Thus username should be a valid phone number."""
usr = None
profile = None
if not username:
return usr, profile
username = username.strip()
is_type = "id"
if is_valid_mobile(username):
is_type = "mobile"
try:
usr = User(username=username, email="")
if password is None or password == "":
# use set_unusable_password to allow user to set his password in future
usr.set_unusable_password()
else:
usr.set_password(password)
if first_name:
usr.first_name = first_name
if last_name:
usr.last_name = last_name
usr.save()
profile = Profile(
user=usr, created_on=datetime.now(), primary_phone="", primary_email="", secondary_email=""
)
if first_name and last_name:
profile.full_name = "%s %s" % (first_name, last_name)
profile.save()
phone = Phone(user=profile, phone=username, type="primary")
phone.is_verified = True
phone.verified_on = datetime.now()
phone.save()
except Exception, e:
log.exception("Error create_user username: %s Exception: %s" % (username, repr(e)))
return None, None
示例4: registrar_usuario
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def registrar_usuario(request):
if request.POST:
f=RegistrationForm(request.POST)
if f.errors:
messages.error(request, 'El formulario contiene errores')
return render_to_response("registro_caja.html", {'form':f}, RequestContext(request))
else:
data = f.cleaned_data
user=User()
user.username=data["username"]
passwd=get_pronounceable_password(1,2)
user.set_password(passwd)
user.email = data['email']
user.first_name = data['first_name']
user.last_name = data['last_name']
user.save()
profile = Profile()
profile.user=user
profile.telefono = data['phone_number']
profile.celular = data['cellphone']
profile.direccion = data['address']
profile.tipo = CLIENTE
profile.save()
messages.success(request, 'Usuario creado con exito')
return render_to_response('mostrar_usuario.html', {'user':user,'passwd':passwd}, RequestContext(request))
else:
f=RegistrationForm()
return render_to_response("registro_caja.html", {'form':f}, RequestContext(request))
示例5: register
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def register(request):
if request.method == 'POST' and not request.user.is_authenticated():
username = request.POST.get('username')
email = request.POST.get('email')
password = request.POST.get('password')
confirm = request.POST.get('confirm')
try:
existing_user = User.objects.get(username=username)
context = RequestContext(request, {'register_message': 'Username {} already exists.'.format(username)})
return render(request, 'home.html', context)
except ObjectDoesNotExist:
pass
try:
existing_user = User.objects.get(email=email)
context = RequestContext(request, {'register_message': 'E-mail {} already exists.'.format(email)})
return render(request, 'home.html', context)
except ObjectDoesNotExist:
pass
if password == confirm:
new_user = User.objects.create_user(username, email=email, password=password)
new_profile = Profile()
new_profile.user = new_user
new_profile.save()
return redirect('home')
else:
context = RequestContext(request, {'register_message': 'Passwords do not match.'.format(email)})
return render(request, 'home.html', context)
else:
return redirect('home')
示例6: add_agents
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def add_agents():
from users.models import Profile
from django.contrib.auth.models import User
f = open('chaupaati')
lines = f.readlines()
for line in lines:
print line
line = line.strip()
print line.split(',')
password, name, loginid = line.split(',')
name = name.strip()
first_name = name.split(' ')[0]
loginid = loginid.strip()
password = password.strip()
u = User.objects.create_user(loginid, '[email protected]', password)
u.name = name
u.save()
agent = Profile()
agent.user = u
agent.full_name = '%s%s' % (name,password)
agent.primary_phone = '%s%s' % (first_name,password)
agent.is_agent = True
agent.save()
示例7: addUser
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def addUser(request):
form = UserForm(request.POST)
if form.is_valid():
try:
with transaction.atomic():
enterprise = Enterprise()
enterprise.save()
request.session['idEnterprise'] = enterprise.id;
location= Location(enterprise=enterprise, lat=0, lng=0, name='Main Office')
location.save()
user = User(location = location, email=form.cleaned_data['email'],
password=form.cleaned_data['password'])
user.save()
request.session['idUser'] = user.id;
profile = Profile(user = user, role="Administrator")
profile.save()
return render(request, 'users/dashboard.html')
except Exception as e:
print(e)
messages.error(request, 'Sorry, Internal Error')
else:
messages.error(request, 'Please fill the form')
return HttpResponseRedirect('/signup')
示例8: profile
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def profile(user, **kwargs):
"""Return a saved profile for a given user."""
defaults = {"user": user}
defaults.update(kwargs)
p = Profile(**defaults)
p.save()
return p
示例9: form_valid
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def form_valid(self, form):
# profile 따로 저장해줌
# 꼼수인데 방법이 되네요
user = form.save()
p = Profile()
p.user = user
p.save()
messages.success(self.request, '계정이 생성되었습니다')
return super(CreateUser, self).form_valid(form)
示例10: profile
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def profile(user, **kwargs):
"""Return a saved profile for a given user."""
defaults = {'user': user, 'name': 'Test K. User', 'bio': 'Some bio.',
'website': 'http://support.mozilla.com',
'timezone': None, 'country': 'US', 'city': 'Mountain View'}
defaults.update(kwargs)
p = Profile(**defaults)
p.save()
return p
示例11: signup
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def signup(request):
from auth.models import User
from auth import load_backend, login
from users.models import Profile, EmailVerify
from market_buy.forms import BuyerForm
form = BuyerForm(request.POST or None)
if form.is_valid():
""" Generate Auth User """
user = User.objects.create_user(form.cleaned_data["username"],
form.cleaned_data["email"],
form.cleaned_data["password1"])
user.first_name = form.cleaned_data["first_name"]
user.last_name = form.cleaned_data["last_name"]
user.is_active = False
user.save()
""" Set profile """
profile = Profile(user=user)
profile.save()
""" Send mail to confirm account """
email_verify = EmailVerify(user=user, user_activation=True)
code = email_verify.generate_code()
email_verify.save()
# TODO: remove this
send_mail_account_confirmation(user, email_verify.code, request.marketplace)
# return HttpResponseRedirect(reverse('confirmemail', args=[code]))
# for backend in settings.AUTHENTICATION_BACKENDS:
# if user == load_backend(backend).get_user(user.pk):
# user.backend = backend
# break
# if hasattr(user, 'backend'):
# login(request, user)
if request.session.get('sell_signup',False):
request.flash['message'] = _("<h5>Please check your email and confirm your account to start selling...</h5>")
request.flash['severity'] = "success"
return HttpResponseRedirect(reverse('market_sell_signup'))
else:
request.flash['message'] = _("<h5>Please check your email and confirm your account. Once confirmed you can Buy or Sell on GreatCoins.com</h5>")
request.flash['severity'] = "success"
return HttpResponseRedirect(reverse('market_home'))
else:
#request.method == GET
if request.GET.has_key('sell_signup'):
request.session['sell_signup'] = request.GET.get('sell_signup','') == '1'
return render_to_response('%s/buy/register.html'% request.marketplace.template_prefix,
{'form': form},
RequestContext(request))
示例12: attach_fb
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def attach_fb(request):
if request.method == "POST":
data = request.POST
facebookid = data["id"]
email = data["email"]
first_name = data["first_name"]
last_name = data["last_name"]
user, profile = None, None
u_email = None
try:
u_email = UserEmail.objects.get(email=email)
profile = u_email.user
user = profile.user
except UserEmail.DoesNotExist:
try:
user = User.objects.get(Q(email=email) | Q(username=email))
except User.DoesNotExist:
user = User.objects.create_user(email, email, None)
user.first_name = first_name
user.last_name = last_name
user.save()
if not user.first_name:
user.first_name = first_name
user.save()
if not user.last_name:
user.last_name = last_name
user.save()
try:
profile = Profile.objects.get(user=user)
except Profile.DoesNotExist:
profile = Profile(user=user, full_name="%s %s" % (first_name, last_name))
# if not profile.full_name: overwrite facebook name
profile.full_name = "%s %s" % (first_name, last_name)
profile.facebook = facebookid
profile.save()
if not u_email:
u_email = UserEmail(email=email, user=profile, type="subscription")
u_email.save()
if request.user:
auth.logout(request)
request.session.flush()
user = auth.authenticate(facebook_user=user, **dict(request=request))
request.session["logged_through_facebook"] = True
if user:
request.session["atg_username"] = user.username
set_logged_in_user(request, user)
log.info("FACEBOOK USER LOGGED IN: %s" % user)
return HttpResponse("OK")
else:
return HttpResponse("OK")
return HttpResponse("FAILED")
示例13: add_user
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def add_user(doc):
if doc['mobile'] in sellers: return
u = User()
try:
u = User.objects.get(username=doc['mobile'])
except User.DoesNotExist:
pass
u.username = doc['mobile']
if 'timestamp' in doc:
u.timestamp = doc['timestamp'].strftime('%Y-%m-%d %H:%M:%S')
else:
if 'modificationTime' in doc:
u.timestamp = doc['modificationTime'].strftime('%Y-%m-%d %H:%M:%S')
u.save()
p = Profile()
try:
p = Profile.objects.get(primary_phone=doc['mobile'])
if p.id != doc['id']:
record_duplicate(p.id, doc['id'])
return
except Profile.DoesNotExist:
pass
p.id = doc['id']
p.user = u
p.full_name = doc.get('name','')
p.gender = doc.get('gender','').lower()
if len(p.gender) > 1:
p.gender = p.gender[0]
if doc.get('dateOfBirth',None):
p.date_of_birth = doc['dateOfBirth'].strftime('%Y-%m-%d')
p.primary_phone = doc['mobile']
p.secondary_phone = doc.get('mobile2','')
p.primary_email = doc.get('email','').split(',')[0]
p.secondary_email = doc.get('email2','').split(',')[0]
p.buyer_or_seller = 'buyer'
p.type = doc.get('type','individual')
p.marketing_alerts = doc.get('dealAlerts','neutral')
p.salt = doc.get('salt','')
p.passcode = doc.get('passcode','')
p.created_on = u.timestamp
p.save()
示例14: register
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def register(self, request, **cleaned_data):
"""Custom registration view.
"""
print('Starting registration')
print(cleaned_data)
u = User.objects.create_user(
cleaned_data['username'],
'',
cleaned_data['password1'])
p = Profile()
p.user = u
p.save()
messages.success(self.request,
'Thank you for registering. Now you can login.')
示例15: home
# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import save [as 别名]
def home(request):
if request.user.is_authenticated():
return render(request, 'dashboard.html')
else:
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = authenticate(username=request.POST["username"], password=request.POST["password"])
if user:
auth.login(request, user)
profile = Profile(user=user, last_login_source=request.META["REMOTE_ADDR"])
profile.save()
return render(request, 'dashboard.html')
return render(request, 'index.html')