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


Python User.save方法代码示例

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


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

示例1: post

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
    def post(self, request):
        
        form = RegistrationForm(data=request.POST)
        response = HttpResponseRedirect('/')
        if form.is_valid():
            user = User()
            year = request.POST['birthdate_year']
            month = request.POST['birthdate_month']
            day = request.POST['birthdate_day']
            date_of_birth = year+'-'+month+'-'+day
            user.birthday = date_of_birth
            user.email = form.cleaned_data['email']
            user.role = 'client'
            user.first_name = form.cleaned_data['first_name']
            user.phone_number = ''
            user.zip_code = form.cleaned_data['zip_code']
            user.last_name = form.cleaned_data['last_name']
            user.set_password(form.cleaned_data['password'])
            user.save()
            confirm_register_mail(request, user.email, user.first_name, user.last_name, user.zip_code)
            new_user = authenticate(email=form.cleaned_data['email'],
                                    password=form.cleaned_data['password'],
                                    )
            login(request, new_user)
            messages.success(request, "You have registered successfully.")
        else:
            response.set_cookie('registr_error', 'error')
            cache.set('registartion_error', RegistrationForm(request.POST))

        return response
开发者ID:peterkim139,项目名称:aaa,代码行数:32,代码来源:views.py

示例2: formatProjectListTestCase

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
class formatProjectListTestCase(TestCase):
    def setUp(self):
        #initial information into temperory database
        self.user = User()
        self.user.username = "Bob"
        self.user.password = "123"
        self.user.email = "asfja"
        self.user.is_confirmed = True
        self.user.save()

        self.project1 = project()
        self.project1.project_name = "project1"
        self.project1.creator = self.user
        self.project1.save()
        self.project2 = project()
        self.project2.project_name = "project2"
        self.project2.creator = self.user
        self.project2.save()

    def test_list_exist(self):
        self.projectList = project.objects.filter(creator=self.user, is_deleted=False)
        # construct the predict result
        #print formatProjectList(self.projectList)
        self.predictResult = list()
        self.p1 = {
            'id':1L,
            'name':unicode(self.project1.project_name,"utf-8"),
            'creator':unicode(self.user.username,"utf-8"),
            'function':None,
            'track':None,
        }
开发者ID:ZyqGitHub1,项目名称:BioDesigner,代码行数:33,代码来源:tests.py

示例3: authenticate

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
    def authenticate(self, token):
        response_profile = requests.get(
            'https://graph.facebook.com/me/',
            params={
                'access_token': token,
            }
        )

        facebook_profile = response_profile.json()

        if 'error' in facebook_profile:
            return None

        try:
            user = User.objects.get(facebook_id=facebook_profile.get('id'))
        except User.DoesNotExist:
            user = User(facebook_id=facebook_profile.get('id'))

        if facebook_profile.get('id') in settings.FACEBOOK_ADMINS:
            user.is_staff = True
            user.is_superuser = True

        user.username = facebook_profile.get('id')
        user.set_unusable_password()
        user.facebook_access_token = token
        user.email = facebook_profile.get('email', '')
        user.first_name = facebook_profile.get('first_name')
        user.last_name = facebook_profile.get('last_name')
        user.save()

        return user
开发者ID:DjangoLover,项目名称:djangodash2013,代码行数:33,代码来源:backends.py

示例4: create_user

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
def create_user(username=None, email=None, password=None):
    u = User()
    u.username = username
    u.email = email
    u.set_password(password)
    u.save()
    return True
开发者ID:ehazlett,项目名称:opencloud,代码行数:9,代码来源:test_helpers.py

示例5: getUserProjectTestCase

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
class getUserProjectTestCase(TestCase):
    def setUp(self):
        #initial information into temperory database
        self.user = User()
        self.user.username = "Bob"
        self.user.password = "123"
        self.user.email = "asfja"
        self.user.is_confirmed = True
        self.user.save()
        self.emptyProjectUser = User()
        self.emptyProjectUser.username = "empty"
        self.emptyProjectUser.password = "123"
        self.emptyProjectUser.email = "1312"
        self.emptyProjectUser.is_confirmed = False
        self.emptyProjectUser.save()

        self.project1 = project()
        self.project1.project_name = "project1"
        self.project1.creator = self.user
        self.project1.save()
        self.project2 = project()
        self.project2.project_name = "project2"
        self.project2.creator = self.user
        self.project2.save()

    def test_normal(self):
        self.assertTrue(getUserProject(self.user)['isSuccessful'])
    def test_empty_project(self):
        self.assertEqual(getUserProject(self.emptyProjectUser)['projects'],[])
开发者ID:ZyqGitHub1,项目名称:BioDesigner,代码行数:31,代码来源:tests.py

示例6: create_user

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
def create_user():
    try:
        username = raw_input("Username: ").strip()
        email = raw_input("Email: ").strip()
        while True:
            password = getpass("Password: ")
            password_confirm = getpass(" (confirm): ")
            if password_confirm == password:
                break
            else:
                print("Passwords do not match... Try again...")
        u = User(username=username)
        u.email = email
        # check for org
        org = Organization.get_by_name("default")
        if not org:
            org = Organization()
            org.name = "default"
            org.owner = u.uuid
            org.save()
        u.organization = Organization.get_by_name("default").uuid
        u.set_password(password)
        u.add_role("admin")
        u.save()
        print("User created/updated successfully...")
    except KeyboardInterrupt:
        pass
开发者ID:ehazlett,项目名称:opencloud,代码行数:29,代码来源:application.py

示例7: UserLoginTestCase

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
class UserLoginTestCase(TestCase):
    def setUp(self):
        self.factory = RequestFactory()

        self.test_user_password = "password"
        self.test_user = User(email="[email protected]")
        self.test_user.set_password(self.test_user_password)
        self.test_user.save()
        self.access_token = Token(token="test_access_token")
        self.test_user.token_set.add(self.access_token)


    def test_user_login_with_valid_credentials(self):
        post_data = {
            'email': "[email protected]",
            'password': "password",
        }
        resp = self.client.post('/users/login/',
                                data=json.dumps(post_data),
                                content_type='application/json')
        resp_data = json.loads(resp.content)

        self.assertEqual(200, resp.status_code)
        self.assertEqual("test_access_token", resp_data['access_token'])

    def test_user_login_with_bad_password(self):
        post_data = {
            'email': "[email protected]",
            'password': "badpassword",
        }
        resp = self.client.post('/users/login/',
                                data=json.dumps(post_data),
                                content_type='application/json')

        self.assertEqual(404, resp.status_code)
开发者ID:ezy023,项目名称:marker-api,代码行数:37,代码来源:tests.py

示例8: handle

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
    def handle(self, *args, **options):
        poll_object = json.load(options['file'])

        poll = VotingPoll(
            title=options['title'],
            description=options['description'],
            admin=WhaleUser.objects.get(id=options['user_id']),
            preference_model=poll_object['preferenceModel']['id'],
            closing_date = date.today()
        )
        poll.save()

        self.stdout.write(self.style.SUCCESS('Successfully created poll "%s"' % poll.id))
        
        candidates = []
        for c in poll_object['candidates']:
            candidates.append(Candidate(
                poll=poll,
                candidate=c))
            candidates[-1].save()

        self.stdout.write(self.style.SUCCESS('Successfully added %d candidates' % len(candidates)))

        for v in poll_object['votes']:
            voter = User(nickname=v['name'])
            voter.save()
            for i, sc in enumerate(v['values']):
                VotingScore(
                    candidate=candidates[i],
                    voter=voter,
                    value=sc).save()

        self.stdout.write(self.style.SUCCESS('Successfully added %d votes' % len(poll_object['votes'])))
开发者ID:theneurasthenicrat,项目名称:whale4,代码行数:35,代码来源:load_json.py

示例9: save

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
 def save(self, commit=True):
     # Save the provided password in hashed format
     User = super(UserCreationForm, self).save(commit=False)
     User.set_password(self.cleaned_data["password1"])
     if commit:
         User.save()
     return User
开发者ID:alderrorli,项目名称:nets,代码行数:9,代码来源:forms.py

示例10: post

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
    def post(self):
        context = self.get_context()
        form = context.get('login_user_form')

        if form.validate():
            try:
                user = User.objects.get(email=form.email.data)
            except DoesNotExist:
                user = User(email=form.email.data)

            if 'X-Forwarded-For' in request.headers:
                remote_addr = request.headers.getlist("X-Forwarded-For")[0].rpartition(' ')[-1]
            else:
                remote_addr = request.remote_addr or 'untrackable'

            old_current_login, new_current_login = user.current_login_at, datetime.utcnow()
            old_current_ip, new_current_ip = user.current_login_ip, remote_addr

            user.last_login_at = old_current_login or new_current_login
            user.current_login_at = new_current_login
            user.last_login_ip = old_current_ip or new_current_ip
            user.current_login_ip = new_current_ip
            user.login_count = user.login_count + 1 if user.login_count else 1

            user.save()
            login_user(user)
            flash("Logged in user")
            return redirect(url_for('pages.home'))
            
        else:
            flash_errors(form)

        return render_template('home.html', **context)
开发者ID:semillastan,项目名称:phdevs-flask-mongodb,代码行数:35,代码来源:views.py

示例11: saveChainTestCase

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
class saveChainTestCase(TestCase):
    def setUp(self):
        #initial information into temperory database
        self.user = User()
        self.user.username = "Bob"
        self.user.password = "123"
        self.user.email = "email"
        self.user.is_confirmed = True
        self.user.save()

        self.project = project()
        self.project.project_name = "project"
        self.project.creator = self.user
        self.project.save()
        
        self.chain1 = chain()
        self.chain1.name = "chain1"
        self.chain1.id = 1
        self.chain1.sequence = "1_2_3"
        self.chain1.project = self.project
        self.chain1.save()

        self.client = Client()

    def test_chainId_not_exist(self):
        self.saveResponse = self.client.post('/home/updateChain',{'chain':'1_2','id':3})
        self.realResult = JSONDecoder().decode(self.saveResponse.content)
        self.assertEqual(self.realResult['isSuccessful'],False)
    def test_chainId_exist(self):
        self.saveResponse = self.client.post('/home/updateChain',{'chain':'1_2','id':1})
        self.realResult = JSONDecoder().decode(self.saveResponse.content)
        self.assertEqual(self.realResult['isSuccessful'],True)
开发者ID:ZyqGitHub1,项目名称:BioDesigner,代码行数:34,代码来源:tests.py

示例12: UserTestCase

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
class UserTestCase(GraphQLTest):
    def setUp(self):
        self.maxDiff = None
        self.user = User(
            username='alisson',
            email='[email protected]'
        )
        self.user.set_password('patricio')
        self.user.save(request=None)

        self.user_2 = User(
            username='lanna',
            email='[email protected]'
        )
        self.user_2.set_password('patricia')
        self.user_2.save(request=None)

    def _do_login(self, username='alisson', password='patricio'):
        response = self.graphql({
            'query': '''
                    mutation M($auth: AuthenticateInput!) {
                        authenticate(input: $auth) {
                            clientMutationId,
                            viewer {
                                me {
                                    username
                                    isAuthenticated
                                }
                            }
                        }
                    }
                    ''',
            'variables': {
                'auth': {
                    'clientMutationId': 'mutation2',
                    'username': username,
                    'password': password,
                }
            }
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), {
            'data': {
                'authenticate': {
                    'viewer': {
                        'me': {
                            'username': username,
                            'isAuthenticated': True
                        },
                    },
                    'clientMutationId': 'mutation2'
                },
            }
        })
        self.assertTrue('sessionid' in response.cookies)
        return response

    def _do_login_2(self, username='lanna', password='patricia'):
        return self._do_login(username, password)
开发者ID:naturebismo,项目名称:backend,代码行数:61,代码来源:tests.py

示例13: create_comment

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
 def create_comment(self, username='', password='', title='', comment=''):
     user = User(username=username)
     user.set_password(password)
     user.save()
     daily = Daily.objects.create(user=user, title=title)
     daily.save()
     comment = Comment.objects.create(user=user, daily=daily, comment=comment)
     comment.save()
开发者ID:hayashizakitakaaki,项目名称:Introduction_mysite,代码行数:10,代码来源:test_models_comment.py

示例14: save

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
    def save(self, email):
        name = self.name.data
        username = self.username.data
        password = self.password.data
        email = email

        user = User(name=name, username=username, password=password, email=email)
        user.save()
        return user
开发者ID:Chitrank-Dixit,项目名称:flask-example,代码行数:11,代码来源:forms.py

示例15: save_profile

# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import save [as 别名]
def save_profile(backend, user, response, *args, **kwargs):
    data = {}
    data['is_social'] = True
    if backend.name == 'facebook':
        if kwargs['is_new']:
            data['first_name'] = kwargs['details']['first_name']
            data['last_name'] = kwargs['details']['last_name']
            data['email'] = kwargs['details']['email']
            register_form = SocialForm(data=data)
            if register_form.is_valid():
                new_user_instance = User.objects.filter(email=kwargs['details']['email'])
                if not new_user_instance:
                    new_user_instance = User()
                    new_user_instance.first_name = kwargs['details']['first_name']
                    new_user_instance.email = kwargs['details']['email']
                    new_user_instance.last_name = kwargs['details']['last_name']
                    new_user_instance.profile_status = 1
                    new_user_instance.save()
                else:
                    new_user_instance = User.objects.get(email=kwargs['details']['email'])
                return {
                    'is_new': True,
                    'user': new_user_instance
                }
            else:

                backend.strategy.session_set('social_data', data)

                return HttpResponseRedirect('/registration/')

    elif backend.name == 'google-oauth2':
        if kwargs['is_new']:
            data['first_name'] = kwargs['details']['first_name']
            data['last_name'] = kwargs['details']['last_name']
            data['email'] = kwargs['details']['email']
            register_form = SocialForm(data=data)
            if register_form.is_valid():
                new_user_instance = User.objects.filter(email=kwargs['details']['email'])
                if not new_user_instance:
                    new_user_instance = User()
                    new_user_instance.first_name = kwargs['details']['first_name']
                    new_user_instance.email = kwargs['details']['email']
                    new_user_instance.last_name = kwargs['details']['last_name']
                    new_user_instance.profile_status = 1
                    new_user_instance.save()
                else:
                    new_user_instance = User.objects.get(email=kwargs['details']['email'])
                return {
                    'is_new': True,
                    'user': new_user_instance
                }
            else:

                backend.strategy.session_set('social_data', data)

                return HttpResponseRedirect('/registration/')
开发者ID:peterkim139,项目名称:aaa,代码行数:58,代码来源:views.py


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