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


Python models.UserProfile类代码示例

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


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

示例1: recalculate_reputation

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,代码行数:28,代码来源:views.py

示例2: get_profile

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,代码行数:7,代码来源:procedures.py

示例3: join

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,代码行数:25,代码来源:views.py

示例4: retrieve

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,代码行数:8,代码来源:profile.py

示例5: create_user

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,代码行数:8,代码来源:factory.py

示例6: create

 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,代码行数:9,代码来源:serializers.py

示例7: setUp

 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,代码行数:9,代码来源:tests.py

示例8: init

def init():
    admin = User.objects.create_user(username="admin", password="admin1234")
    admin.is_staff = True
    admin.is_superuser = True
    admin.save()
    admin_profile = UserProfile(user=admin,name="최고관리자")
    admin_profile.save()

    staff = User.objects.create_user(username="staff", password="staff1234")
    staff.is_staff = True
    staff.save()
    staff_profile = UserProfile(user=staff,name="일반회원")
    staff_profile.save()

    user = User.objects.create_user(username="user", password="user1234")
    user.save()
    profile = UserProfile(user=user,name="비회원")
    profile.save()


    board = Board(name="board", order=0)
    board.save()

    for i in range(45):
        article = Article(
                author=staff_profile,
                title='title'+str(i), 
                board=board,
                contents='contents',
                notice=False,
                read=0)
        article.save()
开发者ID:etaehyun4,项目名称:kfac,代码行数:32,代码来源:addDB.py

示例9: setUp

    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,代码行数:11,代码来源:tests.py

示例10: register

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,代码行数:54,代码来源:views.py

示例11: process_job

	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,代码行数:14,代码来源:views.py

示例12: registration

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,代码行数:50,代码来源:views.py

示例13: setUp

 def setUp(self, mock_bar_models_authorize_source, mock_bar_models_charge_source, mock_account_models_stripe):
     # mock_account_models_customer.default_source = '123'
     mock_account_models_stripe.Customer.create.return_value = {"id": "13542lknlknlkn"}
     mock_bar_models_authorize_source.return_value = {"id": "jnsdflkgj34r"}
     # Create groups
     group = Group(name="Bar Owners")
     group.save()
     g = Group(name="Drinkers")
     g.save()
     # Create a user
     email = "[email protected]"
     password = "password"
     self.firstname = "Bob"
     self.lastname = "Dyllan"
     self.dob = datetime.datetime.now()
     self.user = UserProfile.new(email, password, self.firstname, self.lastname, self.dob)
     self.user.groups.add(group)
     self.client = APIClient(enforce_csrf_checks=True)
     self.client.force_authenticate(user=self.user)
     d = {
         "street": "123 Street",
         "city": "Des Moines",
         "province": "IA",
         "postal": "50305",
         "country": "US",
         "lat": 41.0,
         "lng": -91.0,
     }
     bar = Bar.new("Test Bar 1", d, self.user)
     bar.save()
     self.bar = bar
     m = StripeMerchant(user=self.user, account_id="123", pub_key="123", refresh_token="123", access_token="123")
     m.save()
开发者ID:rlfrahm,项目名称:djangular,代码行数:33,代码来源:test_api.py

示例14: test_bar_payment_user_uses_only_accepted_tabs

    def test_bar_payment_user_uses_only_accepted_tabs(
        self, mock_bar_models_charge_source, mock_bar_models_authorize_source
    ):
        """
		Ensure that a payment only use tabs that have been accepted
		For this test you need:
		- A bar
		- A user
		- Another user
		- A tab created by each user
		"""
        self.user.customer.default_source = "123"
        self.user.customer.save()
        mock_bar_models_authorize_source.return_value = {"id": "jnsdflkgj34r"}
        mock_bar_models_charge_source.return_value = {"id": "jnsdflkgj34r"}
        # Create another user
        user = UserProfile.new("[email protected]", "password", "Ryan", "Frahm", datetime.datetime.now())
        user.groups.add(Group.objects.filter(name="Drinkers")[0])
        # Create a 2 tabs
        # This one should not be accepted
        tab2 = Tab.new(20.00, self.user.email, "ijbwflgkbsdf", user)
        # This one should be automatically accepted
        tab1 = Tab.new(20.00, self.user.email, "ijbwflgkbsdf", self.user)
        url = reverse("api:bar-pay", args=(1,))
        amount = 10
        d = {"amount": amount}
        response = self.client.post(url, d, format="json")
        self.assertEqual(len(response.data.get("transactions")), 1)
        self.assertIsNotNone(response.data.get("sale"))
        # The user's tab should now be $10
        self.assertEqual(response.data.get("tab"), 10)
        transactions = response.data.get("transactions")
        self.assertEqual(transactions[0]["status"], "authorized")
        self.assertEqual(transactions[0]["amount"], 10.00)
        self.assertEqual(transactions[0]["tab_id"], tab1.pk)
开发者ID:rlfrahm,项目名称:djangular,代码行数:35,代码来源:test_api.py

示例15: handle

 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,代码行数:16,代码来源:addstudents.py


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