当前位置: 首页>>代码示例>>Python>>正文


Python UserProfile.save方法代码示例

本文整理汇总了Python中account.models.UserProfile.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.save方法的具体用法?Python UserProfile.save怎么用?Python UserProfile.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在account.models.UserProfile的用法示例。


在下文中一共展示了UserProfile.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: join

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def join(request):
    """注册"""
    if request.POST.get('_method', '') == 'put':
        username = request.POST.get('username', '')
        email = request.POST.get('email','')
        password = request.POST.get('password', '')
        try:
            user = User.objects.create_user(username=username,email=email,password=password)
            profile = UserProfile(
                user_id=str(user.id),
                nickname=username,
                email = email
            )
            profile.save()
        except:
            get_trace.print_trace()

        resp = jsonresponse.creat_response(200)
        data = {
            'url': '/login/'
        }
        resp.data = data
        return resp.get_response()
    else:
        return render_to_response('join.html', {})
开发者ID:Mark24Code,项目名称:mShanbay,代码行数:27,代码来源:views.py

示例2: get_profile

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def get_profile(userobj):
    try:
        profile = UserProfile.objects.get(user=userobj)
    except UserProfile.DoesNotExist:
        profile = UserProfile(user=userobj)
        profile.save()
    return profile
开发者ID:MtMoon,项目名称:cst25,代码行数:9,代码来源:procedures.py

示例3: save

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
    def save(self):
        email = self.cleaned_data["email"]
        first_name = self.cleaned_data["first_name"]
        last_name = self.cleaned_data["last_name"]
        password = self.cleaned_data["password"]
        password_c = self.cleaned_data["password_c"]
        bio = self.cleaned_data["bio"]
        random_username = hashlib.sha224(email).hexdigest()[:30]
        activation_code = hashlib.sha224(email).hexdigest()[:50]
        
        user = User()
        user.username = random_username
        user.email = email
        user.first_name = first_name
        user.last_name = last_name
        user.is_active = False
        user.set_password(password)
        user.save()

        user_profile = UserProfile()
        user_profile.bio = bio
        user_profile.user = user
        user_profile.activation_code = activation_code
        user_profile.save()
        send_user_activation_mail.delay(activation_code, email)
开发者ID:iskeltan,项目名称:blox,代码行数:27,代码来源:forms.py

示例4: recalculate_reputation

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def recalculate_reputation(profile: UserProfile):
    comments = Comment.objects.filter(author=profile)
    photos = Photo.objects.filter(author=profile)
    reactions = Reaction.objects.filter(author=profile).count()

    reputation = 0
    for comment in comments:
        reputation += comment.experience
    for photo in photos:
        reputation += photo.experience
    reputation += reactions

    items = Item.objects.filter(author=profile)
    for item in items:
        reputation += 5
        if item.ratings.count() > 5:
            reputation += 5
        if item.comments.count() > 5:
            reputation += 5
        if item.photos.count() > 5:
            reputation += 5
        if item.flags > 5:
            reputation -= 15
        if 0 < item.flags <= 5:
            reputation -= 5

    profile.reputation = reputation
    profile.save()
开发者ID:BijoySingh,项目名称:Washroom-Finder-Django,代码行数:30,代码来源:views.py

示例5: retrieve

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def retrieve(request):
    ''' note that this requires an authenticated user before we try calling it '''
    try:
        profile=request.user.profile
    except UserProfile.DoesNotExist:
        profile=UserProfile(user=request.user)
        profile.save()
    return profile
开发者ID:Mrwales,项目名称:ecomstore,代码行数:10,代码来源:profile.py

示例6: create_user

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def create_user(username='testuser', email='[email protected]', password='testuser', first_name='John', last_name='Doe', job_title='scrum master', office='opendream', has_image=False, timezone='Asia/Bangkok'):
    user = User.objects.create_user(username, email, password)
    account = UserProfile(first_name=first_name, last_name=last_name, user=user, job_title=job_title, office=office, timezone=timezone)
    if has_image:
        account.image = DjangoFile(open('static/tests/avatar.png'), 'avatar.png')
    account.save()

    return user
开发者ID:opendream,项目名称:livestory,代码行数:10,代码来源:factory.py

示例7: create

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
 def create(self, validated_data):
   """
   Create and return a new 'User' instance, given the validated data
   """
   user = User.objects.create_user(validated_data['username'], validated_data['email'], validated_data['password'])
   user.save()
   profile = UserProfile(user=user)
   profile.save()
   return user
开发者ID:J88G,项目名称:djangular,代码行数:11,代码来源:serializers.py

示例8: setUp

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
 def setUp(self):
     # Every test needs a client.
     self.client = Client()
     password = make_password('admin', salt=None, hasher='default')
     user = User(username='admin', password=password, email='[email protected]')
     user.save();
     userprofile = UserProfile(user=user, usertype='4', department='admin', phone='admin')
     userprofile.save()
     self.client.login(username='admin', password='admin')
开发者ID:bbaobelief,项目名称:neptune,代码行数:11,代码来源:tests.py

示例9: register

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def register(request):

    if request.POST:
        username = request.POST.get('org.username',None)
        password = request.POST.get('password',None)
        confirmpwd = request.POST.get('confirmpwd',None)
        password = username
        confirmpwd = username
        email = request.POST.get('org.email',None)
        
        role_name_str = request.POST.get('org.role_name', None)
        
        department = request.POST.get('org.parent_organization_name',None)
        
        
        phone = request.POST.get('phone',None)
        '''验证重复帐号名'''
        usernames = User.objects.filter(username__iexact=username)
        '''验证重复email'''
        emails = User.objects.filter(email__iexact=email)
        if usernames:
            return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','accountindex'), "callbackType":request.POST.get('callbackType',None), "message":u'用户名已经存在不能添加', "info":u'用户名已经存在不能添加',"result":u'用户名已经存在不能添加'}), mimetype='application/json')
        
        
        '''验证两次输入密码是否一致'''
        if password != confirmpwd:
            return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','accountindex'), "callbackType":request.POST.get('callbackType',None), "message":u'两次密码输入不一致', "info":u'两次密码输入不一致',"result":u'两次密码输入不一致'}), mimetype='application/json')
        
        if emails:
            return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','accountindex'), "callbackType":request.POST.get('callbackType',None), "message":u'EMAIL已经存在不能添加', "info":u'EMAIL已经存在不能添加',"result":u'EMAIL已经存在不能添加'}), mimetype='application/json')
        if password != None and password != '':
            password = make_password(password, salt=None, hasher='default')
            user = User(username=username, password=password, email=email)
        else:
            user = User(username=username, email=email)
        user.save()
        userprofile = UserProfile(user=user, department=department, phone=phone)
        userprofile.save()
        
        if role_name_str != None and role_name_str != '':
            role_name_list = role_name_str.split(',')
            for role_name in role_name_list:
                if role_name != None and role_name != '':
                    try:
                        role = Role.objects.get(role_name__exact=role_name)
                        role.users.add(user)
                    except:
                        return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','accountindex'), "callbackType":request.POST.get('callbackType',None), "message":u'存在无效角色名请重新选择或置空'}), mimetype='application/json')
        
        
        Log(username=request.user.username, content=u"成功创建用户: " + username, level=1).save()
        return HttpResponse(simplejson.dumps({"statusCode":200, "navTabId":request.POST.get('navTabId','accountindex'), "callbackType":request.POST.get('callbackType','closeCurrent'), "message":u'添加成功'}), mimetype='application/json')
    else:
        return render_to_response('account/register.html', {'account_usertype_dict':account_usertype_dict})
开发者ID:yindashan,项目名称:dwz,代码行数:56,代码来源:views.py

示例10: setUp

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
    def setUp(self):
        # Every test needs a client.
        self.client = Client()
        password = make_password('admin', salt=None, hasher='default')
        user = User(username='admin', password=password, email='[email protected]')
        user.save();
        userprofile = UserProfile(user=user, department='admin', phone='admin')
        userprofile.save()
        #系统自带的login函数,不会触发自定义的login函数
#        self.client.login(username='admin', password='admin')
        self.client.post('/account/login/', {'username':'admin', 'password':'admin'})
开发者ID:bbaobelief,项目名称:neptune,代码行数:13,代码来源:tests.py

示例11: process_job

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
	def process_job(self):
		try:
			user = User.objects.get(pk=self.kwargs["pk"])
		except User.DoesNotExist:
			raise Http404

		try:
			up = UserProfile.objects.get(user=user)
		except UserProfile.DoesNotExist:
			up = UserProfile(user=user)

		up.authToken = id_generator(24)
		up.save()
		return True
开发者ID:froscon,项目名称:SaBoT,代码行数:16,代码来源:views.py

示例12: registration

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def registration(request, register_success_url="login", template="account/registration.html"):
    form = RegistrationForm()

    if request.POST:
        form = RegistrationForm(request.POST)

        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
        
            user = User.objects.create_user(username=email,
                email=email,
                password=password)

            user.first_name = first_name
            user.last_name = last_name
            user.save()

            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_key = sha.new(salt+user.username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)

            user_profile = UserProfile(
            user=user,
            activation_key=activation_key,
            key_expires=key_expires)

            user_profile.save()
            
            current_site = Site.objects.get_current()
            subject = "welcome to my blog"
            message =  ('Please click the link below to'
                'activate your user account \n''%s%s%s') % (
                    current_site, "/account/confirm/", activation_key)

            sender = EMAIL_HOST_USER
            recipients = [email]

            
            mail_sender(subject=subject, message=message,
                        sender=sender, recipients=recipients)

            authenticate(email=email, password=password)


            return redirect(register_success_url)

    return render(request, template, {'form': form})
开发者ID:FatmaTosun,项目名称:MyBlog-CoolBlue,代码行数:52,代码来源:views.py

示例13: handle

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
 def handle(self, *args, **options):
     fn = options['input']
     csv_reader = csv.reader(open(fn))
     group = Group.objects.get(name='students')
     
     for row in csv_reader:
         sn = row[0]
         name = row[1]
         try: 
             u = User.objects.create_user(sn, '', sn)
             u.groups.add(group)
             profile = UserProfile(real_name=name, student_number=sn, user=u)
             profile.save()
         except IntegrityError:
             pass
         self.stdout.write(name.decode('utf-8').encode('cp936'))
开发者ID:Gin-APTX4869,项目名称:homework_free,代码行数:18,代码来源:addstudents.py

示例14: PNewUser

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def PNewUser(request):
	json_data=status.objects.filter(status='ERR',MSG='PD')
	errors=""
	if request.method == 'POST':
		#userprofile_form = UserProfileForm(request.POST)
		user_form = UserForm(request.POST)
		#if userprofile_form.is_valid() and user_form.is_valid():
		if user_form.is_valid():
			user_clean_data = user_form.cleaned_data
			created_user = User.objects.create_user(user_clean_data['username'], user_clean_data['email'], user_clean_data['password1'])
			created_user.first_name=request.POST['firstname']
			created_user.last_name=request.POST['lastname']
			created_user.is_active = False
			created_user.save()
			pinHash = str(hash("CLT"+ created_user.username + created_user.email))[3:9]
			userprofile = UserProfile(user=created_user, hash=pinHash, pwdhash=0) #hash=hashlib.sha224("CLT" + created_user.username + created_user.email).hexdigest())
			#userprofile.user = created_user
			#userprofile.phone_num1 = userprofile_form.cleaned_data['phone_num1']
			#userprofile.hash = hashlib.sha224("CLT" + created_user.username + created_user.email).hexdigest()
			userprofile.save()
			#subject = "new provider notice"
			#accept_link = 'http://cl.kazav.net/account/validate_prov/' + str(created_user.id) + '/' + userprofile.hash + '/'
			#html_message = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">Welcome to CLT<BR> Name: ' + created_user.first_name + ' ' + created_user.last_name + '<BR> <a href="' + accept_link + '"> Validate Me </a> '
			#text_message = 'Welcome to CLT. Name: ' + created_user.first_name + ' ' + created_user.last_name + '      Validate yourself at: ' + accept_link 
			#user_mail=created_user.email
			#msg = EmailMultiAlternatives(subject, text_message, 'CLT Server<[email protected]>', [user_mail])
			#msg.attach_alternative(html_message,"text/html")
			#msg.send()
			textmessage="Hi " + request.POST['firstname'] + " and welcome to CLT. This is your PIN code for activating your account: " + pinHash
			account_sid = "AC442a538b44777e2897d4edff57437a24"
			auth_token  = "be3a4e5fbf058c5b27a2904efd05d726"
			client = TwilioRestClient(account_sid, auth_token)
			#DEL COMMENT TO ENABLE SMS			message = client.sms.messages.create(body=textmessage,to="+"+created_user.username,from_="+16698005705")
			#new_user = authenticate(username=request.POST['username'], password=request.POST['password1'])
			#login(request, new_user)
			json_data = status.objects.filter(status='OK')
		else:
			json_data = status.objects.filter(status='WRN')
			if user_form.errors.items() :
				errors = ",[" + str(dict([(k, v[0].__str__()) for k, v in user_form.errors.items()])) + "]"
			#if userprofile_form.errors.items():
			#	errors += ",[" + str(dict([(k, v[0].__str__()) for k, v in userprofile_form.errors.items()])) + "]"
	json_dump = "[" + serializers.serialize("json", json_data)
	json_dump += errors + "]"
	return HttpResponse(json_dump.replace('\'','"'))
开发者ID:gabik,项目名称:clt,代码行数:47,代码来源:views.py

示例15: register

# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import save [as 别名]
def register(request):
    if request.user.is_authenticated():
        redirect(reverse('home'))

    context = {}
    if request.method == 'GET':
        context['form'] = RegisterForm()
        return render(request, 'account/register.html', context)

    form = RegisterForm(request.POST)
    context['form'] = form

    if not form.is_valid():
        return render(request, 'account/register.html', context)

    new_user = User.objects.create_user(username=form.cleaned_data['email'], password=form.cleaned_data['password1'])
    new_user.is_active = False
    new_user.first_name = form.cleaned_data['fname']
    new_user.last_name = form.cleaned_data['lname']
    new_user.save()

    token = default_token_generator.make_token(new_user)
    if form.cleaned_data['user_type'] == 'c':
        is_customer = True
    else:
        is_customer = False
    user_profile = UserProfile(is_customer=is_customer, token=token, user=new_user)
    try:
        user_profile.save()
    except IntegrityError:
        context['errors'] = 'another user has already used this email address'
        return render(request, 'account/register.html', context)

    subject = 'Confirmation from Yummy'
    message = 'Click this link to activate your account: ' + "http://128.237.180.208:8000" + \
              reverse('activate', kwargs={'token': token})
    from_addr = '[email protected]'
    recipients = [form.cleaned_data['email']]
    # send the activation email to the registered email address asynchronously by starting a daemon thread
    t = threading.Thread(target=send_mail, args=[subject, message, from_addr, recipients], kwargs={'fail_silently': True})
    t.setDaemon(True)
    t.start()

    context['email'] = form.cleaned_data['email']
    return render(request, 'account/activate-required.html', context)
开发者ID:ghylxdw,项目名称:yummy,代码行数:47,代码来源:views.py


注:本文中的account.models.UserProfile.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。