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


Python UserData.get_by_key_name方法代码示例

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


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

示例1: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_by_key_name [as 别名]
	def get(self,site_key):
		
		# Get the file by the provided key name
		user_data = UserData.get_by_key_name(site_key)
		if not user_data:
			return self.error(404)
		blob_info = user_data.blob_info
		
		# Figure out hostname so we can give 'full links'
		host_name = '/'.join([k for k in self.request.url.split('/')[:3]])
		
		# Build the response
		resp = {
			'name':blob_info.filename,
			'creation':blob_info.creation.strftime("%Y-%m-%d %H:%M:%S"),
			'download_url':'%s/%s' % (host_name,site_key),
			'url':'%s/%s' % (host_name,site_key),
			'type':blob_info.content_type,
			'size':blob_info.size,
			'size_in_kb':(blob_info.size)/1024,
			'info_url':'%s/i/%s' % (host_name,site_key),
			'thumbnail_url': get_serving_url(blob_info) if blob_info.content_type in IMAGE_MIMETYPES else ''
		}
		
		if self.request.get('format') == 'json':
			# If the requested format is json render to json
			return self.response.out.write(json.dumps(resp))
		else:
			# Otherwise render to html
			self.response.out.write(template.render('templates/viewer.html', resp))
开发者ID:topher515,项目名称:sharewithme,代码行数:32,代码来源:views.py

示例2: basic_auth_required

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_by_key_name [as 别名]
 def basic_auth_required(self, include_viewers=False):
     # scheme = os.environ.get('wsgi.url_scheme')
     # if scheme != 'https':
     #    # Basic auth should be done via https only
     #    return False
     auth = os.environ.get("HTTP_AUTHORIZATION", None)
     auth_msg = 'Basic realm="%s on AppEngine"' % self.reponame
     if not auth:
         # lacking auth info
         self.response.headers["WWW-Authenticate"] = auth_msg
         return False
     (basic, _, auth) = auth.partition(" ")
     if basic != "Basic":
         # Mechanism is not Basic.
         self.response.headers["WWW-Authenticate"] = auth_msg
         return False
     (username, _, password) = base64.b64decode(auth).partition(":")
     if username.find("@") < 0:
         username += "@gmail.com"
     userdata = UserData.get_by_key_name("user_" + username)
     if not userdata or str(userdata.passphrase) != str(password):
         # passphrase mismatch.
         self.response.headers["WWW-Authenticate"] = auth_msg
         return False
     if not self.repo.check_user_perm(userdata.key(), include_viewers):
         # Userdata mismatch.
         self.response.headers["WWW-Authenticate"] = auth_msg
         return False
     # Otherwise, valid user.
     logging.info("%s pushed into %s." % (username, self.reponame))
     return True
开发者ID:pombredanne,项目名称:SmartNotes,代码行数:33,代码来源:hgapp_mod.py

示例3: get_current_user

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_by_key_name [as 别名]
def get_current_user():
    u = users.get_current_user()
    if not u:
        return None
    return UserData.get_by_key_name("user_" + u.email())
开发者ID:pombredanne,项目名称:SmartNotes,代码行数:7,代码来源:utils.py


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