开发者

Downloadlink for a file dynamically created by a Trac- Wikimacro

开发者 https://www.devze.com 2023-03-11 00:23 出处:网络
I\'ve been given the task to write a plugin for Trac. It should provide burndown data for the ticketcount and estimations filed in the issue tracking system.

I've been given the task to write a plugin for Trac. It should provide burndown data for the ticketcount and estimations filed in the issue tracking system. The user writes his request as a wikimacro and is provided a link/ button for downloading the burndown as a csv-file, output as a chart is also planned, but has lower priority.

I've got a working solution for processing the data but I'm left with the following problem.

My Question

How can I provide a downloadlink/- button on the Wikipage for a file which is dynamically created by the users request?

I've seen some attempts to send files in the trac source itself and other plugins, but since I'm new to web programming that doesn't really help.

Update1 I've been trying to solve the problem the way Felix suggested, which opened up a new problem for me. This (stupid) example should demonstrate my problem. My Macro generates the following URL and adds it as a link to the wikipage.

//http://servername.com/projectname/wiki/page_name?teddy=bear    

But the RequestHandler doesn't react, even if the condition returns true. Edit: This piece of code now shows the working version for the example.

New URL:

#example url
#http://127.0.0.1:8000/prove/files/new

class CustomRequestHandlerModule(Component):
   开发者_高级运维 implements(IRequestHandler)

    def match_request(self,req):
        #old, not working
        #return "teddy=bear"== str(req.path_info).split('?')[1]
        #new
        accept="/files/new"== str(req.path_info)
        return accept

    def process_request(self,req):
        csvfile = self.create_csv()
        req.send_response(200)
        req.send_header('Content-Type', 'text/csv')
        req.send_header('Content-length', len(csvfile))
        req.send_header('Content-Disposition','filename=lala.csv')
        req.end_headers()
        req.write(csvfile)
        raise RequestDone     

Update2 Inserting loggingstatements shows match_request never gets called.

What am I doing wrong? (Yes, the create_csv() exists already)

Update 3 Thx, for helping =)


If match_request isn't getting called, then process_request never has a chance to execute. Assuming that there's nothing wrong with your plugin that's preventing Trac from loading it correctly, what's probably happening is that another handler is matching the URL before your version of match_request gets called. Try increasing your log level to "Debug" and see if it provides enough information to tell who is processing that request.

Another option is to create a custom "namespace" for your auto-generated files. Try replacing 'wiki' in the generated URLs with something like 'files'. This should prevent any of the built-in handlers from handling the request before your plugin's match_request method gets called.


Basically you need to write your own IRequestHandler which handles a specific URL and returns your dynamically created data. Afterwards you macro should return a url which is configured for your request handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号