本文整理汇总了Python中core.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ajax_sale_add
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)
示例2: test_create_player_from_user
def test_create_player_from_user(self):
user = User(login='test_login')
user.name = 'test_name'
player = PlayerOrig.from_user(user=user)
self.assertEqual(player.name, user.name)
self.assertEqual(player.user, user)
self.assertEqual(player.id, user.id)
示例3: actualizar_registro
def actualizar_registro(cls, documento, nombres, apellidos,
usuario, clave, role, rutas):
existe_documento = cls.existe_documento(documento)
if existe_documento and usuario:
u = User.query(User.documento == documento).get()
u.nombres = nombres
u.apellidos = apellidos
if clave:
u.clave_hash = User.make_pw_hash(usuario, clave)
elif u.usuario != usuario and not cls.existe_usuario(usuario) and clave:
u.clave_hash = User.make_pw_hash(usuario, clave)
u.usuario = usuario
u.role = role
u.put()
rutasEliminar = cls.query_all_rutas(u.key)
if rutasEliminar:
for r in rutasEliminar:
if r.usuario.get().usuario == u.usuario:
r.key.delete()
if rutas:
for rut in rutas:
ruta_key = ndb.Key(urlsafe=rut)
rta = ruta_key.get()
nueva_ruta = UserRuta(ruta=rta.key, usuario=u.key)
nueva_ruta.put()
return ["alert-success", "La actualización ha sido exitoso"]
else:
return ["alert-danger", "No se pudo completar la actualización"]
示例4: test_helper_no_profile
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))
示例5: test_eq
def test_eq(self):
user = User(login='test_login')
user._id = 1
user2 = User(login='test_login2')
player = PlayerOrig.from_user(user=user)
player2 = PlayerOrig.from_user(user=user)
self.assertEqual(player, player2)
player3 = PlayerOrig.from_user(user=user2)
self.assertNotEqual(player, player3)
self.assertNotEqual(player3, player3)
self.assertNotEqual(player3, None)
示例6: add_user
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
示例7: test_ne
def test_ne(self):
user = User(login='test_login')
user._id = 1
player = PlayerOrig.from_user(user=user)
user2 = User(login='test_login')
user2._id = 2
player2 = PlayerOrig.from_user(user=user2)
user3 = User(login='test_login2')
player3 = PlayerOrig.from_user(user=user2)
self.assertNotEqual(player, player2)
self.assertNotEqual(player, player3)
示例8: UserRegHandler
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)
示例9: create
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), ))
示例10: create
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), ))
示例11: system_users
def system_users():
user = auth.is_logged_in(request)
permission = auth.is_sys_admin(user)
return listing(request, None, User.select(),
'system_users', 'system_manage_users',
user=user)
示例12: select_by_user
def select_by_user(user):
if user.is_admin:
qs = ControllerUser.objects.all()
else:
users = User.select_by_user(user)
qs = ControllerUser.objects.filter(user__in=users)
return qs
示例13: existe_documento
def existe_documento(cls, documento):
if documento:
if User.query(User.documento == documento).fetch():
return True
else:
return False
else:
return False
示例14: blog_user
def blog_user(user_id, blog_id):
# Obtains user edit in blog context.
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_admin(user, blog)
user_to_edit = User.find(user_id)
return edit_user(user_to_edit, editing_user=user, context=blog_context, blog=blog)
示例15: site_user
def site_user(user_id, site_id):
# Obtains user edit in site context.
user = auth.is_logged_in(request)
site = Site.load(site_id)
permission = auth.is_site_admin(user, site)
user_to_edit = User.find(user_id)
return edit_user(user_to_edit, editing_user=user, context=site_context, site=site)