2014-04-15 49 views
2

我創建了一個自定義控制器以下載自動生成的文件,我目前面臨的問題是如何在視圖中鏈接到此控制器而無需使用表單標記(如鏈接/按鈕,我想這已經是一種形式視圖內)的地方,波紋管是我的控制器:鏈接到模塊openerp中的自定義控制器

class MyController(http.Controller): 
    _cp_path = '/sc' 

    @http.httprequest 
    def some_html(self, req, s_action=None, **kw): 
    return req.make_response(open('path_of_file').read(), 
      [('Content-Type', 'application/octet-stream; charset=binary'), 
      ('Content-Disposition', content_disposition('1.docx', req))], 
     ) 

貝婁是XML視圖,在這裏我要放置鏈接的url下載給出docx(請注意它不是一個靜態文件,它是自動生成的):

<record model="ir.ui.view" id="view_sefarer_applicant_form"> 
    .... 
    <field name="arch" type="xml"> 
     <form string="Jobs - Recruitment Form" version="7.0"> 
     ..... 
     <sheet> 
      <div class="oe_right oe_button_box"> 
      ... 
      <button 
       name="action_download_form" 
       type="object" 
       string="P014 Drug/Alcohol Delcaration" 
       attrs="{'invisible':[('state','!=','done')]}" 
       <!-- this is where the link to the download url 
        {sc/some_html} should be called --> 
       /> 
      ... 
     </sheet> 
     </form> 

    </field> 
</record> 

任何幫助或建議,將不勝感激。

+0

哥們沒u得到了上述question.I也希望同樣的解決方案。請幫幫我 – nitesh

回答

0

爲了獲得OpenERP的承認你的控制器,你必須有一個static目錄在你的模塊目錄:

/.../openerp/addons/MyModule/ 
    |-- __init__.py 
    |-- __openerp__.py 
    |-- controllers.py 
    |-- static/ 
相關問題