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


Python Context.req方法代码示例

本文整理汇总了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()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:29,代码来源:consoleadmin.py

示例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()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:59,代码来源:consoleadmin.py


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