在trac中处理升级后的文件以供插件使用 [英] Processing an upoaded file within trac for a plugin use

查看:98
本文介绍了在trac中处理升级后的文件以供插件使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为trac.edgewall.org编写插件,但我缺少sthg.阅读了网站trac.edgewall.org制作的所有教程之后.
因此,我尝试使用POST方法将此文件上传到服务器,这是一个简化的示例:

I''m trying to write a plugin for trac.edgewall.org but I''m missing sthg. after reading all the tutorials made by the site trac.edgewall.org.
So I''m trying to upload a file to the sever using the POST method this a simplified example :

<form id="MyForm" name="input" action="" method="post">
<label for="attachment">URL :</label>
<input type="file" name="GanttFile" value=""/>
</form>


现在,我正在尝试处理上载的文件,对其进行读取,然后进行一些修改,而不是保存它,或者要求用户选择他要保存文件的位置(从trac数据库中导出一些数据)...我仍在此级别被阻止:


Now I''m trying to process the uploaded file ,read it and do some modifications than save it or ask the user to choose where he wants to save the file (export some data from the trac database)...I''m still blocked at this level :

def process_request(self, req):
    data = {}
    if req.method=='POST':
        file=req.args.get('GanttFile', 'value')
        # and now I'm blocked !! how can I modify this file
        # and then redirect or save it !


如果我尝试显示变量** file **的内容,我只是得到文件名而不是所有路径吗?
通过执行以下操作:


and if I try to display the content of the variable **file** I just get the name of the file not all the path ?
By doing something like this :

<input type="text" name="file" value ="$file" />


并在我的源代码中:


and in my source code :

def process_request(self, req):
    data = {}
    if req.method=='POST':
        file=req.args.get('GanttFile', 'value')
        # display the content
        data.update({
            'file': file
        })


有任何想法吗?
谢谢


Any idea or ideas ?
Thanks

推荐答案

文件" / >


并在我的源代码中:


and in my source code :

def process_request(self, req):
    data = {}
    if req.method=='POST':
        file=req.args.get('GanttFile', 'value')
        # display the content
        data.update({
            'file': file
        })


有任何想法吗?
谢谢


Any idea or ideas ?
Thanks


实际上上面的代码正在运行.
问题是使用了Firefox ...命令
Actually the code above is working .
The problem was the use of Firefox ...the command
file=req.args.get('GanttFile', 'value')



在firefox中:只是文件名
在IE中:绝对路径.

有没有办法使这两种浏览器都可以使用?
谢谢



In firefox : just the name of the file
In IE: the absolute path.

Is there a manner to make this works for the two browsers ?
Thanks


所以我将代码放在这里,供那些想重用它或提供更好建议的人使用:

Python类别:


So I''m putting my code here for those who wants to reuse it or for better suggestions :

The Python class :


class ProjectPlugin(Component):
    implements(INavigationContributor, IRequestHandler, ITemplateProvider)

    # INavigationContributor methods
    def get_active_navigation_item(self, req):
        return 'helloworldv2linkIdentifier'

    def get_navigation_items(self, req):
        yield ('mainnav', 'helloworldv2linkIdentifier',
               tag.a('Gantt Export', href=req.href.myapppp()))


    # IRequestHandler methods
    def match_request(self, req):
        return re.match(r'/myapppp(?:_trac)?(?:/.*)?


这篇关于在trac中处理升级后的文件以供插件使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆