當前位置: 首頁>>代碼示例>>Python>>正文


Python User.save方法代碼示例

本文整理匯總了Python中core.models.User.save方法的典型用法代碼示例。如果您正苦於以下問題:Python User.save方法的具體用法?Python User.save怎麽用?Python User.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在core.models.User的用法示例。


在下文中一共展示了User.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: authenticate

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
    def authenticate(self, saml_authentication=None):
        if not saml_authentication:  # Using another authentication method
            return None

        if saml_authentication.is_authenticated():
            attributes = saml_authentication.get_attributes()
            user_changed = False
            try:
                user = User.objects.get(username=saml_authentication.get_attributes()['uid'][0])
            except User.DoesNotExist:
                user = User(username=saml_authentication.get_attributes()['uid'][0])
                user.set_unusable_password()
                user.username = attributes['uid'][0]

            map_fields = {
                'realname': 'cn',
                'email': 'mail'
            }

            # ensure realname for users from webid don't contain unverified note
            if 'cn' in attributes:
                attributes['cn'][0] = attributes['cn'][0].replace(' (unverified)', '')

            for field, samlfield in map_fields.items():
                if getattr(user, field) != attributes[samlfield][0]:
                    setattr(user, field, attributes[samlfield][0])
                    user_changed = True

            if user_changed:
                user.save()

            return user
        return None
開發者ID:cybrairai,項目名稱:internsystem,代碼行數:35,代碼來源:auth_backend.py

示例2: ajax_sale_add

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
def ajax_sale_add(request):
    r_client = request.POST.get('client')
    r_task = request.POST.get('task')
    r_email = request.POST.get('email')
    r_password = request.POST.get('password')
    client = Client.objects.get(pk=int(r_client))
    task = Task.objects.get(pk=int(r_task))
    try:
        User.objects.get(email=r_email)
    except User.DoesNotExist:
        user = User(email=r_email, password=r_password, type=User.UserType.client)
        user.set_password(r_password)
        user.save()
        sale = Sale(
            user=user,
            city=client.city,
            manager=client.manager,
            moderator=client.moderator,
            legal_name=client.name,
            actual_name=client.name,
            legal_address=client.actual_address,
            password=r_password
        )
        sale.save()
        task.status = 1
        task.save()
        return HttpResponseRedirect(reverse('sale:update', args=(sale.id, )))
    return_url = reverse('client:task-list') + '?error=1'
    return HttpResponseRedirect(return_url)
開發者ID:od-5,項目名稱:distrubutor,代碼行數:31,代碼來源:ajax.py

示例3: test_helper_no_profile

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
 def test_helper_no_profile(self):
     u = User()
     u.first_name = "John"
     u.last_name = "Smith"
     u.save()
     self.assertEquals(False, helpers.user_has_profile(u))
     p = Person()
     p.user = u
     p.save()
     self.assertEquals(True, helpers.user_has_profile(u))
開發者ID:cmc333333,項目名稱:collab,代碼行數:12,代碼來源:test_models.py

示例4: add_user

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
def add_user(auth, fields):
    user = authenticate(username=auth.get('username'),
                        password=auth.get('password'))
    auth['tenant'] = user.site.login_base

    sites = _get_sites(fields.get('site')) 
    if sites: fields['site'] = sites[0]     
    user = User(**fields)
    user.os_manager = OpenStackManager(auth=auth, caller = user)
    user.save()
    return user
開發者ID:Dchouras,項目名稱:planetLab,代碼行數:13,代碼來源:users.py

示例5: UserRegHandler

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
def UserRegHandler(request):
    NewAccount = Account()
    NewAccount.username = request.POST['username'].encode('utf-8')
    NewAccount.password = request.POST['password'].encode('utf-8')
    NewAccount.urtype = request.POST['urtype'].encode('utf-8')
    NewAccount.created = datetime.now()
    NewUser = User()
    NewUser.name = request.POST['name'].encode('utf-8')
    NewUser.mobile = request.POST['mobile'].encode('utf-8')
#    NewUser.address = request.POST['address'].encode('utf-8')
    NewUser.save()
    NewAccount.urid = NewUser.id
    NewAccount.save()
    return HttpResponse(NewAccount.id) 
開發者ID:shane-Git,項目名稱:EzMeal,代碼行數:16,代碼來源:views.py

示例6: create

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
    def create(self):
        xos_args = self.get_xos_args()

        if not xos_args.get("site",None):
             raise Exception("Site name must be specified when creating user")
        if ("firstname" not in xos_args) or ("lastname" not in xos_args):
             raise Exception("firstname and lastname must be specified when creating user")

        user = User(**xos_args)
        user.save()

        self.postprocess(user)

        self.info("Created User '%s'" % (str(user), ))
開發者ID:vpramo,項目名稱:xos-1,代碼行數:16,代碼來源:user.py

示例7: create

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
    def create(self):
        nodetemplate = self.nodetemplate

        xos_args = self.get_xos_args()

        if not xos_args.get("site",None):
             raise Exception("Site name must be specified when creating user")

        user = User(**xos_args)
        user.save()

        self.postprocess(user)

        self.info("Created User '%s'" % (str(user), ))
開發者ID:digideskio,項目名稱:xos,代碼行數:16,代碼來源:user.py

示例8: facebook_connect

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
def facebook_connect(user_data):
    try:
        # Logging in with Facebook
        user = User.objects.get(facebook_id=user_data['id'])
        user.tz_offset = user_data['timezone']
        user.save()
    except User.DoesNotExist:
        # Creating new account with Facebook
        user = User()
        user.email = user_data['email']
        user.facebook_id = user_data['id']
        user.tz_offset = user_data['timezone']
        user.set_password(random_string())
        user.save()
    return user
開發者ID:elesant,項目名稱:HackBase,代碼行數:17,代碼來源:facebook.py

示例9: test_call_register_channel

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
    def test_call_register_channel(self):
        '''
        Test registration to a channel
        '''

        u = User()
        u.username = "sample_post"
        u.first_name = "sample_post"
        u.email = "[email protected]"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "PostSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid5'
        sub1.save()


        resp = ask_subscribe_channel(ch1, sub1.device_id)

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
        self.client.login(username='test_user', password='password')

        data = {
                'channel' : ch1.name,
                'token' : sub1.token,
                'browser' : 'chrome',
                'device_id' : sub1.device_id
        }

        response = self.client.post(reverse('browser-registration'), json.dumps(data), sub1.token)

        self.assertTrue(response.status_code, 200)
開發者ID:Mikelord2,項目名稱:pushetta-api-django,代碼行數:49,代碼來源:test.py

示例10: test_call_delete

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
    def test_call_delete(self):
        '''
        Test deleting of a registration of a device from a channel
        '''

        u = User()
        u.username = "sample_del"
        u.first_name = "sample_del"
        u.email = "[email protected]"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "DelSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid6'
        sub1.save()


        resp = ask_subscribe_channel(ch1, sub1.device_id)

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
        self.client.login(username='test_user', password='password')

        response = self.client.delete(reverse('browser-get-registration', kwargs={'device_id': sub1.device_id,
                                                                       'channel_name' : ch1.name}))

        self.assertEqual(response.status_code, 200)

        channels = SubscriberManager().get_device_subscriptions(sub1.device_id)
        sub_channel = next((x for x in channels if x == ch1.name.lower()), None)

        self.assertIsNone(sub_channel)
開發者ID:Mikelord2,項目名稱:pushetta-api-django,代碼行數:48,代碼來源:test.py

示例11: get_all_users

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
def get_all_users(request):
    response_auth = requests.post('http://oll.tv/ispAPI/auth2/', data={
        'login': 'mtel',
        'password': 'x_g~-5~(;ZY'
    })
    response_content = response_auth.json()
    #print response_content
    response_get_user_list = requests.post('http://oll.tv/ispAPI/getUserList/', data={
        'offset': '',
        'hash': response_content['hash']
    })
    get_user_list_json = response_get_user_list.json()
    get_user_list = get_user_list_json['data']
    num = 0
    for i in get_user_list:
        num = num + 1
        u = User(email=i['email'], account=i['account'], birth_date=i['birth_date'], gender=i['gender'], firstname=i['firstname'], lastname=i['lastname'], phone=i['phone'], region=i['region'], receive_news=i['receive_news'], index=['index'], status=i['active'], registration_date=i['reg_date'], oll_id=i['ID'])
        u.save()
    return render(request, 'olltv/get_all_users.html', locals())
開發者ID:ximepa,項目名稱:xbills,代碼行數:21,代碼來源:views.py

示例12: api_user_register

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
def api_user_register(request):
    benchmark_start = time.time()
    response = prepare_response(request)
    status = 200
    form = UserRegisterForm(request.POST)
    errors = get_validation_errors(form)
    if form.is_valid():
        data = form.cleaned_data
        new_user = User(email=data['email'])
        new_user.set_password(data['password'])
        new_user.save()
        response['new_user_id'] = new_user.id
        status = 201
    else:
        response['errors'] = errors
        status = 400
    response['meta']['status'] = status
    benchmark_end = time.time()
    response['meta']['execution_time'] = benchmark_end - benchmark_start
    return build_response(response, status=status)
開發者ID:elesant,項目名稱:BirthdayStarter,代碼行數:22,代碼來源:views.py

示例13: post

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
 def post(self):
     login = self.get_argument("login")
     password = self.get_argument("password")
     password_confirm = self.get_argument("password_confirm")
     if len(password) >= 4 and (password == password_confirm):
         users = yield User.find(login=login)
         if len(users):
             self.write_error(500, "Already exist")
             return
         user = User(login=login)
         user.set_password(new_password=password)
         user.save()
         self.set_secure_cookie("user", login)
         self.get_user_from_cookies = lambda : login
         session = self.project_session
         session['current_user'] = user
         session.save()
         self.redirect("/")
     else:
         self.write_error(500, 'Incorrect password')
開發者ID:0lmer,項目名稱:tornado-poker,代碼行數:22,代碼來源:auth.py

示例14: test_call_get

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
    def test_call_get(self):
        '''
        Test check if a device is registered to a channel
        '''

        u = User()
        u.username = "sample_un"
        u.first_name = "Sample_un"
        u.email = "[email protected]"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "GetSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid4'
        sub1.save()


        resp = ask_subscribe_channel(ch1, 'devid4')

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
        self.client.login(username='test_user', password='password')

        response = self.client.get(reverse('browser-get-registration', kwargs={'device_id': 'devid4', 'channel_name' : 'GetSub'}) )
        
        self.assertTrue(response.status_code, 200)
開發者ID:Mikelord2,項目名稱:pushetta-api-django,代碼行數:42,代碼來源:test.py

示例15: UserModelTest

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import save [as 別名]
class UserModelTest(TestCase):

    def setUp(self):
        self.user = User(
            name='Michael',
            email='[email protected]',
            password='123'
        )

    def test_user_creation(self):
        """
        user creation
        """
        self.user.save()

        self.assertEqual(1, self.user.pk)

    def test_user_unicode(self):
        """
        unicode
        """
        self.user.save()

        self.assertEqual(self.user.__unicode__(), 'Michael - [email protected]')
開發者ID:michaeltcoelho,項目名稱:shortener,代碼行數:26,代碼來源:test_models.py


注:本文中的core.models.User.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。