本文整理汇总了Python中web.models.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# look up usrs
users = User.get_all()
params = {
'users': users
}
return self.render_template('admin/users.html', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:12,代码来源:adminhandlers.py
示例2: get
def get(self):
# get the authcode and desired action
authcode = self.request.get('authcode')
action = self.request.get('action')
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
secret = user_info.tfsecret
totp = pyotp.TOTP(secret)
# build paramater list
params = {}
# verify
if action == "enable" and totp.verify(authcode):
# authorized to enable
user_info.tfenabled = True
user_info.put()
elif action == "disable" and totp.verify(authcode):
# authorized to disable
user_info.tfenabled = False
user_info.put()
else:
# not authorized - javascript will handle adding a user message to the UI
params['response'] = "error"
params['result'] = "two factor auth failed"
self.response.set_status(401)
self.response.headers['Content-Type'] = 'application/json'
return self.render_template('api/response.json', **params)
# respond
params['response'] = "success"
params['result'] = "two factor auth successful"
self.response.headers['Content-Type'] = "application/json"
return self.render_template('api/response.json', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:35,代码来源:userhandlers.py
示例3: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
# check for url param or referer
url = ""
if 'url' in self.request.GET:
url = urllib2.unquote(self.request.GET['url'])
# if we have a URL, we deal with it
if url:
project = Project.get_by_url(url)
if not project:
# create a new project for this user
self.form.url.data = url
return self.post()
else:
# go to the existing project
return self.redirect_to('account-projects-detail', project_id = project.key.id())
# params build out
params = {
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
return self.render_template('project/new.html', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:31,代码来源:projecthandlers.py
示例4: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# load token and produce form page or show instructions
if self.request.get("token"):
self.form.token.data = self.request.get("token")
# group choices pulldown
self.form.group.choices = []
# add list of user's groups, if any
groups = GroupMembers.get_user_groups(user_info.key)
for group in groups:
self.form.group.choices.insert(0, (group.key.id(), group.name))
# public group
self.form.group.choices.insert(0, ("public", "Public"))
# render new appliance page
parms = {"gform": self.gform, "appliance_token": self.request.get("token")}
return self.render_template("appliance/new.html", **parms)
else:
# render instructions
return self.render_template("appliance/instructions.html")
开发者ID:StackMonkey,项目名称:site,代码行数:26,代码来源:appliancehandlers.py
示例5: get
def get(self, cloud_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# get the cloud in question
cloud = Cloud.get_by_id(long(cloud_id))
# bail if cloud doesn't exist or not owned by this user
if not cloud or cloud.owner != user_info.key:
return self.redirect_to('account-clouds')
# look up cloud's instances
instances = Instance.get_by_cloud(cloud.key)
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
# params build out
params = {
'cloud': cloud,
'instances': instances,
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
return self.render_template('cloud/edit.html', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:27,代码来源:cloudhandlers.py
示例6: post
def post(self, cloud_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# load the cloud in question
cloud = Cloud.get_by_id(long(cloud_id))
# bail if cloud doesn't exist or not owned by this user
if not cloud or cloud.owner != user_info.key:
return self.redirect_to('account-clouds')
# check what was returned from form validates
if not self.form.validate():
self.add_message("The %s cloud was not updated." % cloud.name, "info")
return self.redirect_to('account-clouds')
# load form values
name = self.form.name.data.strip()
description = self.form.description.data.strip()
# save the new cloud in our database
cloud.name = name
cloud.description = description
cloud.put()
# log to alert
self.add_message("Cloud %s updated!" % name, "success")
# give it a few seconds to update db, then redirect
time.sleep(1)
return self.redirect_to('account-clouds')
开发者ID:StackMonkey,项目名称:site,代码行数:32,代码来源:cloudhandlers.py
示例7: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
# load projects pulldown
self.form.project.choices = []
# public + private
projects = Project.get_available(user_info.key)
for project in projects:
self.form.project.choices.insert(0, (str(project.key.id()), project.name))
# insert images into list for wisp
self.form.image.choices=[('custom', "Dynamic Image URL")]
images = Image.get_all()
for image in images:
self.form.image.choices.insert(0, (str(image.key.id()), image.description))
# params build out
params = {
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
return self.render_template('wisp/new.html', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:29,代码来源:wisphandlers.py
示例8: delete
def delete(self, wisp_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# pull the entry from the db
wisp = Wisp.get_by_id(long(wisp_id))
# if we found it and own it, delete
if wisp and wisp.owner == user_info.key:
# delete any associated bids, if they exist
InstanceBid.delete_by_wisp(wisp.key)
# delete the wisp
wisp.key.delete()
self.add_message('Wisp successfully deleted!', 'success')
else:
self.add_message('Wisp was not deleted. Something went horribly wrong somewhere!', 'warning')
# hangout for a second
time.sleep(1)
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
channel.send_message(channel_token, 'reload')
return
开发者ID:StackMonkey,项目名称:site,代码行数:28,代码来源:wisphandlers.py
示例9: delete
def delete(self, cloud_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# pull the entry from the db
cloud = Cloud.get_by_id(long(cloud_id))
# check the number of instances
count = Instance.get_count_by_cloud(cloud.key)
# deny if it has instances
if count > 0:
self.add_message('You may not delete a cloud with instances!', 'info')
# if we found it and own it, delete
elif cloud and cloud.owner == user_info.key:
cloud.key.delete()
self.add_message('Cloud successfully deleted!', 'success')
else:
self.add_message('Cloud was not deleted. Something went horribly wrong somewhere!', 'warning')
# hangout for a second
time.sleep(1)
# use the channel to tell the browser we are done and reload
channel_token = self.request.get('channel_token')
channel.send_message(channel_token, 'reload')
return
开发者ID:StackMonkey,项目名称:site,代码行数:28,代码来源:cloudhandlers.py
示例10: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# look up user's groups
groups = GroupMembers.get_user_groups(user_info.key)
# create an object with group_id and member counts
group_count = {}
for group in groups:
# get the member counts
count = GroupMembers.get_group_user_count(group.key)
group_count[group.key.id()] = count
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
# params build out
params = {
'groups': groups,
'group_count': group_count,
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
return self.render_template('groups/list.html', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:27,代码来源:grouphandlers.py
示例11: delete
def delete(self, project_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# pull the entry from the db
project = Project.get_by_id(long(project_id))
# if we found it and own it
if project and project.owner == user_info.key:
# patch all wisps using project to stock
Wisp.patch_to_stock(project.key)
# delete the project
project.key.delete()
self.add_message('Project successfully deleted!', 'success')
else:
self.add_message('Project was not deleted. Something went horribly wrong somewhere!', 'warning')
# hangout for a second
time.sleep(1)
# use the channel to tell the browser we are done and reload
channel_token = self.request.get('channel_token')
channel.send_message(channel_token, 'reload')
return
开发者ID:StackMonkey,项目名称:site,代码行数:26,代码来源:projecthandlers.py
示例12: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# look up wisps
wisps = Wisp.get_by_user(user_info.key)
# redirect if we don't have any wisps
if not wisps:
return self.redirect_to('account-wisps-new')
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
# params build out
params = {
'wisps': wisps,
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
# check for default
default = False
for wisp in wisps:
if wisp.default:
default = True
if not default:
print "wtf"
self.add_message("Please set a wisp to be default!", "error")
return self.render_template('wisp/wisps.html', **params)
开发者ID:DavidJohnstonCEO,项目名称:utter-pool,代码行数:32,代码来源:wisphandlers.py
示例13: delete
def delete(self, group_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# find the the entry
group = Group.get_by_id(long(group_id))
# this member's membership
membership = GroupMembers.get_by_userid_groupid(user_info.key, group.key)
# list of users that have the group enabled
members = GroupMembers.get_group_users(group.key)
# remove this user's membership
membership.key.delete()
# if this user is not the group owner, we simply notify we are done
if not group or group.owner != user_info.key:
# use the channel to tell the browser we are done and reload
self.add_message('Group was removed from account.', 'success')
channel_token = self.request.get('channel_token')
channel.send_message(channel_token, 'reload')
return
# was there more than just this member?
if len(members) > 1:
# find the next user by date and assign them as owner
entry = GroupMembers.get_new_owner(user_info.key, group.key)
print "new owner is %s" % entry.member
new_owner = entry.member
group.owner = new_owner
group.put()
# find member's appliances that match this group and remove
appliances = Appliance.get_by_user_group(user_info.key, group.key)
for appliance in appliances:
appliance.group = None # public group
appliance.put()
else:
# no more members, so delete the group
group.key.delete()
self.add_message('Group successfully deleted!', 'success')
# remove group from any and all appliances (heavy handed)
appliances = Appliance.get_by_group(group.key)
for appliance in appliances:
appliance.group = None # public group
appliance.put()
# hangout for a second
time.sleep(1)
# use the channel to tell the browser we are done and reload
channel_token = self.request.get('channel_token')
channel.send_message(channel_token, 'reload')
return
开发者ID:StackMonkey,项目名称:site,代码行数:57,代码来源:grouphandlers.py
示例14: post
def post(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# check what was returned from form validates
if not self.form.validate():
for key, value in self.form.errors.iteritems():
self.add_message("Fix the %s. %s" % (key, value[0]), "error")
return self.get()
# load form values
url = self.form.url.data.strip()
# check if we have it already
if Project.get_by_url(url):
self.add_message("A project with that URL already exists.", "error")
return self.redirect_to('account-projects')
# get the basic repo data
response = github.repo_base(url)
if response['response'] == 'success':
repo = response['result']['repo']
else:
repo = None
self.add_message(response['result']['message'], 'error')
return self.redirect_to('projects')
# save the new project in our database
project = Project()
project.url = url.lower().strip('/')
project.name = repo['name'] # this one is editable later
project.repo_name = repo['name'] # this one is not
project.address = None
project.amount = 0
project.description = repo['description']
project.owner = user_info.key
project.public = False
project.port = 80
project.put()
# give it a second
time.sleep(1)
# check if the repo has the utterio directory
response = project.sync()
# log to alert
if response['response'] == "success":
self.add_message("Project %s successfully added!" % project.name, "success")
else:
self.add_message("%s" % response['result']['message'], "fail")
# redirect
return self.redirect_to('account-projects-detail', project_id = project.key.id())
开发者ID:StackMonkey,项目名称:site,代码行数:54,代码来源:projecthandlers.py
示例15: get
def get(self):
# basics
ip = self.request.remote_addr
# setup channel to do page refresh
channel_token = generate_token()
refresh_channel = channel.create_channel(channel_token)
# various pulldown initialization
self.form.flavor.choices=[]
self.form.wisp.choices=[]
self.form.cloud.choices=[]
# add list of user's flavors, if any
flavors = Flavor.flavors_with_instances_on_sale()
for flavor in flavors:
self.form.flavor.choices.insert(0, (flavor.name, flavor.description))
# used for determining element layout
wisp = None
cloud = None
# if the user is logged in, we build out the list of their wisps
if self.user_id:
# lookup user's auth info and wisps
user_info = User.get_by_id(long(self.user_id))
wisps = Wisp.get_by_user(user_info.key)
for wisp in wisps:
self.form.wisp.choices.insert(0, (wisp.key.id(), wisp.name))
# load clouds
clouds = Cloud.get_by_user(user_info.key)
# create default cloud if none
if not clouds:
cloud = Cloud.create_default(user_info.key)
clouds.append(cloud)
self.add_message("Default cloud created.", 'success')
for cloud in clouds:
self.form.cloud.choices.insert(0, (cloud.key.id(), cloud.name))
# params build out (injects the last wisp, if there was one)
params = {
'remote_ip': ip,
'wisp': wisp,
'cloud': cloud,
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
return self.render_template('lab/launcher.html', **params)
开发者ID:StackMonkey,项目名称:site,代码行数:52,代码来源:labhandlers.py
示例16: post
def post(self):
to = self.request.get("to")
group_id = self.request.get("group_id")
invitor_id = self.request.get("invitor_id")
invite_url = self.request.get("invite_url")
# admin of the pool
sender = config.contact_sender
# test to see if the sender_id and group number is real
invitor = User.get_by_id(long(invitor_id))
group = Group.get_by_id(long(group_id))
# if we found the sending user and group
if invitor and group:
# rest of the email stuff
subject = "You've Been Invited to the %s Group on %s" % (group.name, config.app_name)
body = """
Howdy!
You've been invited to the %s group on %s by %s. Acceptance of the group invite will require linking the site to your Google account.
%s
This invite will allow you to start instances which are managed exclusively by appliances in the %s group. Your membership also allows you to add your own OpenStack cluster and appliance to the group. This is a very good thing for all involved.
If this email comes as a complete surprise to you, simply delete it. We may yet meet again.
Cheers,
%s
%s
""" % (group.name, config.app_name, invitor.username, invite_url, group.name, config.app_owner, config.app_name)
logEmail = LogEmail(
sender = sender,
to = to,
subject = subject,
body = body,
when = utils.get_date_time("datetimeProperty")
)
logEmail.put()
try:
mail.send_mail(sender, to, subject, body)
except Exception as ex:
logging.error("Failed attempt to send invite email because %s." % ex)
else:
# doing nothing, you fuckers
logging.error("Failed attempt to send invite email.")
开发者ID:StackMonkey,项目名称:site,代码行数:50,代码来源:emailhandlers.py
示例17: get
def get(self):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# look up appliances
clouds = Cloud.get_by_user(user_info.key)
# setup channel to do page refresh
channel_token = user_info.key.urlsafe()
refresh_channel = channel.create_channel(channel_token)
# params build out
params = {
'clouds': clouds,
'refresh_channel': refresh_channel,
'channel_token': channel_token
}
return self.render_template('cloud/clouds.html', **params)
开发者ID:DavidJohnstonCEO,项目名称:utter-pool,代码行数:19,代码来源:cloudhandlers.py
示例18: post
def post(self, group_id = None):
# lookup user's auth info
user_info = User.get_by_id(long(self.user_id))
# get the group in question
group = Group.get_by_id(long(group_id))
# get this user's membership
is_member = GroupMembers.is_member(user_info.key, group.key)
# bail if group doesn't exist or user not a member
if not group or not is_member:
return self.redirect_to('account-groups')
# check what was returned from form validates
if not self.form.validate():
self.add_message("The email form did not validate.", "error")
return self.redirect_to('account-groups-configure', group_id = group.key.id())
# load form values
email = self.form.email.data.strip()
# create the invite
member = GroupMembers.invite(email, group.key, user_info.key)
time.sleep(1)
# build an invite URL, load the email_url, and then execute the task to send invite
invite_url = "%s%s?token=%s" % (self.request.host_url, self.uri_for('account-groups-invites'), member.token)
email_url = self.uri_for('tasks-sendinvite')
taskqueue.add(url = email_url, params={
'to': str(email),
'group_id': group.key.id(),
'invitor_id' : user_info.key.id(),
'invite_url' : invite_url
})
# log to alert
self.add_message("User invited to group!", "success")
return self.redirect_to('account-groups-configure', group_id = group.key.id())
开发者ID:StackMonkey,项目名称:site,代码行数:41,代码来源:grouphandlers.py
注:本文中的web.models.models.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论