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


Python User.objects方法代码示例

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


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

示例1: handle

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
    def handle(self, **kwargs):
        while True:
            username = self._get_string('Username')
        
            if User.objects(username=username).count() > 0:
                print "That username is already in use"
                continue
            else:
                break
        
        while True:
            email = self._get_string('Email', required=False)
        
            if User.objects(email=email).count() > 0:
                print "That email is already in use"
                continue
            else:
                break
            
        password = self._get_string('Password', getpass.getpass)
        first_name = self._get_string('First name')
        last_name = self._get_string('Last name')

        u = User(username=username)
        u.first_name = first_name
        u.last_name = last_name
        u.email = email
        u.set_password(password)
        u.is_staff = True
        u.is_superuser = False
        u.save()

        print 'User "%s %s" successfully added' % (first_name, last_name)
开发者ID:mzupan,项目名称:intake,代码行数:35,代码来源:adduser.py

示例2: test_should_create_default_superuser

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
 def test_should_create_default_superuser(self):
     FakeCommand().handle()
     self.assertEqual(1, User.objects().count())
     user = User.objects().first()
     user_profile = UserProfile.objects().first()
     self.assertEqual('admin', user.username)
     self.assertTrue(check_password('password', user.password))
     self.assertNotEqual('password', user.password)
     self.assertEqual('[email protected]', user_profile.email)
     self.assertEqual(self.kampala, user_profile.location)
     self.assertEqual('N/A', user_profile.phone)
     self.assertEqual('Admin', user_profile.name)
     self.assertEqual('Administrator', user_profile.user.group.name)
开发者ID:unicefuganda,项目名称:necoc,代码行数:15,代码来源:test_create_super_user.py

示例3: signup

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def signup(request):
    if request.method == 'POST':
        name = request.POST.get('name','')
        pw = request.POST.get('password','')
        email = request.POST.get('email','')
        
        if not verifyCaptcha(request.POST.get('g-recaptcha-response','')):
            messages.error(request, "Captcha could not be validated")
            return redirect('website:index')
        
        
        #check if either is only whitespace
        if isNoneOrEmptyOrBlankString(name) or isNoneOrEmptyOrBlankString(pw) or isNoneOrEmptyOrBlankString(email):
            return HttpResponseBadRequest('username and/or password is empty')

        if len(User.objects(username=name)) != 0:
            messages.error(request, "Username" + name + "already taken")
            return redirect('website:index')

        if len(User.objects(email=email)) != 0:
            messages.error(request, "Email" + email + "already taken")
            return redirect('website:index')

        maxLength = len("IraklisDimitriadis") #this should be a good maxLength

        if len(name) > maxLength:
            messages.error(request, "Your name is too long. Use less than "+maxLength+" letters.")
            return redirect('website:index')

        user = User.create_user(name,pw,email)
        user.save()
        UserExtension(user=user,karma=0).save()
        
       

        #log user in after registrartion
        user = authenticate(username=name,password=pw)
        if user is not None:
            if user.is_active:
                login(request, user)
                messages.success(request, 'Your account was created. Click OK to begin using Lemur.')
                return redirect('website:catalogue')

        
    elif request.method == 'GET':
        return redirect('website:index')

       

    messages.error(request, "The server let's you know, that something unexpected happened.")
    return redirect('website:index')
开发者ID:phikui,项目名称:Lemur,代码行数:53,代码来源:views.py

示例4: test_should_handle_existing_profile

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
 def test_should_handle_existing_profile(self):
     UserProfile(phone='N/A', name='Admin', location=self.kampala, email='[email protected]').save()
     FakeCommand().handle()
     self.assertEqual(1, User.objects().count())
     user = User.objects().first()
     user_profile = UserProfile.objects().first()
     self.assertEqual('admin', user.username)
     self.assertTrue(check_password('password', user.password))
     self.assertNotEqual('password', user.password)
     self.assertEqual('[email protected]', user_profile.email)
     self.assertEqual(self.kampala, user_profile.location)
     self.assertEqual('N/A', user_profile.phone)
     self.assertEqual('Admin', user_profile.name)
     self.assertEqual('Administrator', user_profile.user.group.name)
开发者ID:unicefuganda,项目名称:necoc,代码行数:16,代码来源:test_create_super_user.py

示例5: hybrid_authentication

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def hybrid_authentication(username=None,password=None):
    try:
        if email_re.search(username):
            user = User.objects(email=username).first()
        else:
            user = User.objects(username=username).first()
        if len(user) != 0:
            if password and user.check_password(password):
                    return user
            else:
                return None
        else:
            return None
    except:
        return None
开发者ID:heaven00,项目名称:The-Challenge,代码行数:17,代码来源:functions.py

示例6: patientinfo

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def patientinfo(request):
   message = ""
   if request.method == 'POST':
      if request.POST['requestType'] == 'newPatient':
         firstName = request.POST['firstName']
         lastName = request.POST['lastName']
         birthDate = request.POST['birthDate']
         
         if(helper.validate(birthDate)):
            username = firstName + lastName         
            userNum = len(User.objects(__raw__={'username':{'$regex': '^' + username, '$options' : 'i'}}))

            user = User.create_user(username + str(userNum), 'password')
            user.first_name = firstName
            user.last_name = lastName
            user.save()
            ion_user = IonUser(user=user, group='patient', birthdate=birthDate)
            ion_user.save()
       
            newPatient = patient(firstName=firstName, lastName=lastName, activeMeds = [], user=ion_user)
            newPatient.save()
         else:
            message = "Invalid birth date format. (should be mm-dd-yyyy)"

      if request.POST['requestType'] == 'deletePatient':
         id = request.POST['id']
         patient.objects(id=id)[0].delete()
         # don't know if we actually want to give people the ability to delete medical records...
   return render_to_response('patientinfo.html', {'Patients': patient.objects, 'message': message},
                              context_instance=RequestContext(request))
开发者ID:ludi1001,项目名称:IonMedicationSystem,代码行数:32,代码来源:views.py

示例7: index

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def index(request):
	message = None
	
	#Login
	if request.method == 'POST' and request.POST['name'] and request.POST['password']:
		username = str(request.POST['name']).lower()
		
		u = authenticate(username=username, password=request.POST['password'])
		if u is None:
			if request.POST.has_key('should_register'):
				if len(User.objects(username=request.POST['name'])) == 0:
					u = User(username=username)
					u.set_password(request.POST['password'])
					u.save()
					auth_login(request, authenticate(username=username, password=request.POST['password']))
				else:
					message = 'Sorry, that username is taken :('
			else:
				message = 'Sorry, the name or password was wrong. Do you not have an account yet? Just fill out the form and check "New Account"'
		else:
			auth_login(request, u)
		
	chat = Chat.objects.order_by('+time')

	return render_to_response('chat/chat.html', {
		'message': message,
		'chat': chat[len(chat)-50:],
		'user': request.user,
	})
开发者ID:benmills,项目名称:pond,代码行数:31,代码来源:views.py

示例8: index

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def index(request):
	lisUserProfile = {}
# 	print('begin')
# 	for user in lisUserProfile:
# 		print(user.company)
# 	print('finish')
	c = {'lisUserProfile':lisUserProfile,}
	if request.method == 'GET':
		return render(request, 'myapp/search-mentor.html', c)
	elif request.method == 'POST':
		try:
			keyword = request.POST['search']
			users = User.objects(Q(first_name__icontains=keyword) | Q(last_name__icontains=keyword))
			#search data
# 			lisUserProfile = UserProfile.objects(user_id__in=users,is_mentor=True)
			lisUserProfile = UserProfile.objects(user_id__in=users)
			
			listAllCurriculumn = Curriculumn.objects()
			listCurriculumn =Curriculumn.objects(name__icontains=keyword)
			c = {'lisUserProfile':lisUserProfile,'listCurriculumn':listCurriculumn,'listAllCurriculumn':listAllCurriculumn,'search':keyword}
			#get data from mongodb
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/search-mentor.html", c)
		except Exception:
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/search-mentor.html", c)
	return render(request, 'myapp/search-mentor.html', c)
开发者ID:cuongnmeas,项目名称:ase,代码行数:31,代码来源:SearchMentor.py

示例9: test_search_form_return_correct_event

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
    def test_search_form_return_correct_event(self):
        user=User.create_user('john','john')
	request = HttpRequest() 
	user=User.objects(username='john')
	self.client.login(username='john',password='john')

	response = self.client.post('/eventslist/addevent',data={'title': 'Concierto','description': 'Es un concierto','category': 'Musica','lat':'49.8','lng':'4.7'}) 
        self.assertEqual(Event.objects(title='Concierto').count(),1) 
	self.assertEqual(str(Event.objects(title='Concierto')),'[<Event: Concierto-49.84.7-Es un concierto-Musica>]')

	response = self.client.post('/',data={'title': 'Concierto','category': 'Musica','lat':'49.8','lng':'4.7','distance':'4'}) 
	
	self.assertContains(response,'<td>Concierto</td>')
	self.assertContains(response,'<td>Es un concierto</td>')
	self.assertContains(response,'<td>Musica</td>')
	User.objects(username='john').delete()
开发者ID:eltxabi,项目名称:proyecto,代码行数:18,代码来源:tests.py

示例10: employee_department

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def employee_department(request, employee_id):
    
    # @todo: respect DRY with employee method
    employee = Employee.objects(id=employee_id).first()
    if not employee:
        user = User.objects(id=employee_id).first()
        if user:
            employee = Employee.from_user(user)
        else:
            raise Http404
    
    if request.method == 'POST' and 'department' in request.POST:
        department_id = request.POST['department']
        
        if department_id:
            department = Department.objects(id=department_id).first()
        else:
            department = None
        
        employee.department = department
        employee.save()
        success(request, _('Department for employee changed'))
        return redirect('picket-admin-employees')
    else:
        return HttpResponseBadRequest()
开发者ID:lig,项目名称:picket_deadend,代码行数:27,代码来源:views.py

示例11: user

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def user(request):
	"""A context processor that adds the user to template context"""
	profile = {}
	is_mentor = False
	if (request.user.is_authenticated()==True) and(request.user is not None):
		try:
			user_images = request.session['user_images']
		except Exception as e:
			user_images = ""
	if (request.user.is_authenticated()==True) and(request.user is not None):
		try:
			isMentor = Mentor.objects.get(user=request.user)
			if len(isMentor):
				is_mentor = True
		except Exception as e:
			is_mentor = False
	if (request.user.is_authenticated()==True) and(request.user is not None):
		loggedUser = User.objects(username=str(request.user))
		return {
			'user': request.user,
			'profile':profile,
			'is_mentor':is_mentor,
			'loggedUser':loggedUser[0],
			'user_images':user_images
		}
	else:
		return {
		'user': request.user,
		'profile':profile,
		'is_mentor':is_mentor,
		'loggedUser':[],
		'user_images':""
	}
开发者ID:ngotuan12,项目名称:ASEProject,代码行数:35,代码来源:context_processors.py

示例12: index

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
def index(request):
	lisUserProfile = UserProfile.objects
# 	print('begin')
# 	for user in lisUserProfile:
# 		print(user.images)
# 	print('finish')
	c = {'lisUserProfile':lisUserProfile,}
	if request.method == 'GET':
		return render(request, 'myapp/people-directory.html', c)
	elif request.method == 'POST':
		try:
			keyword = request.POST['keyword']
			users = User.objects(first_name__icontains=keyword)#search data
			lisUserProfile = UserProfile.objects(user_id__in=users)
			c = {'lisUserProfile':lisUserProfile,'keyword':keyword}
# 			profile = Profile()
# 			profile.name = 'Nusja Nawancali'
# 			profile.image_url='images/user3.png'
# 			profile.address='Phuket, Thailand'
# 			profile.location='Product Manager'
# 			profile.company='SomeCompany, Inc.'
# 			profile.save()

			#get data from mongodb
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/people-directory.html", c)
		except Exception:
			c.update(csrf(request))
			c.update(context_processors.user(request))
			return render_to_response("myapp/people-directory.html", c)
	return render(request, 'myapp/test.html', c)
开发者ID:cuongnmeas,项目名称:ase,代码行数:34,代码来源:PeopleDirectory.py

示例13: clean_email

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
 def clean_email(self):
     email = self.cleaned_data['email']
     user = User.objects(email=email)
     if len(user) == 0:
         return email
     else: 
         raise forms.ValidationError(self.error_messages['email_exists'])
开发者ID:heaven00,项目名称:The-Challenge,代码行数:9,代码来源:forms.py

示例14: handle

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
 def handle(self, **kwargs):
     username = self._get_string('Username')
     user = User.objects(username=username).first()
     if user:
         user.delete()
         print 'User "%s" successfully removed' % (username)
     else:
         print 'Error! Could not find user with username "%s"' % username
开发者ID:mzupan,项目名称:intake,代码行数:10,代码来源:deluser.py

示例15: clean_username

# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import objects [as 别名]
 def clean_username(self):
     username = self.cleaned_data.get('username')
     try:
         user = User.objects(username=username)
     except User.DoesNotExist:
         return username
     else:
         raise forms.ValidationError(_('This username is already in use.'))
开发者ID:taras1k,项目名称:Let-eat-bee,代码行数:10,代码来源:forms.py


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