本文整理汇总了Python中trac.mimeview.Context.req方法的典型用法代码示例。如果您正苦于以下问题:Python Context.req方法的具体用法?Python Context.req怎么用?Python Context.req使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.mimeview.Context
的用法示例。
在下文中一共展示了Context.req方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_remove
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import req [as 别名]
def _do_remove(self, identifier):
# Get downloads API component.
api = self.env[DownloadsApi]
# Create context.
context = Context('downloads-consoleadmin')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
context.req = FakeRequest(self.env, self.consoleadmin_user)
# Get download by ID or filename.
try:
download_id = int(identifier)
download = api.get_download(context, download_id)
except ValueError:
download = api.get_download_by_file(context, identifier)
# Check if download exists.
if not download:
raise AdminCommandError(_('Invalid download identifier: %(value)s',
value = identifier))
# Delete download by ID.
api.delete_download(context, download_id)
# Commit changes in DB.
db.commit()
示例2: _do_add
# 需要导入模块: from trac.mimeview import Context [as 别名]
# 或者: from trac.mimeview.Context import req [as 别名]
def _do_add(self, filename, *arguments):
# Get downloads API component.
api = self.env[DownloadsApi]
# Create context.
context = Context('downloads-consoleadmin')
db = self.env.get_db_cnx()
context.cursor = db.cursor()
context.req = FakeRequest(self.env, self.consoleadmin_user)
# Convert relative path to absolute.
if not os.path.isabs(filename):
filename = os.path.join(self.path, filename)
# Open file object.
file, filename, file_size = self._get_file(filename)
# Create download dictionary from arbitrary attributes.
download = {'file' : filename,
'size' : file_size,
'time' : to_timestamp(datetime.now(utc)),
'count' : 0}
# Read optional attributes from arguments.
for argument in arguments:
# Check correct format.
argument = argument.split("=")
if len(argument) != 2:
AdminCommandError(_('Invalid format of download attribute:'
' %(value)s', value = argument))
name, value = argument
# Check known arguments.
if not name in ('description', 'author', 'tags', 'component', 'version',
'architecture', 'platform', 'type'):
raise AdminCommandError(_('Invalid download attribute:'
' %(value)s', value = name))
# Transform architecture, platform and type name to ID.
if name == 'architecture':
value = api.get_architecture_by_name(context, value)['id']
elif name == 'platform':
value = api.get_platform_by_name(context, value)['id']
elif name == 'type':
value = api.get_type_by_name(context, value)['id']
# Add attribute to download.
download[name] = value
self.log.debug(download)
# Upload file to DB and file storage.
api._add_download(context, download, file)
# Close input file and commit changes in DB.
file.close()
db.commit()