Skip to Content
Menu
This question has been flagged
1 Reply
31408 Views

How to format a field as URL link (href)?

My code is

        <record id="voipdata_tree_view" model="ir.ui.view">
           <field name="name">File Details</field>
            <field name="model">filedata</field>
            <field name="priority" eval="1"/>
             <field name="type">tree</field>
                  <field name="arch" type="xml">
                          <tree string="File Names" create="false" edit="false">
                             <field name="file_name" widget="url" placeholder="www.openerp.com"/>
                             <field name="time_created" string="Time Created"/>
                              <field name="size" string="Size"/>
                             </tree>
                   </field>
    </record>

My fields are

 class filedata(osv.osv):
         _name = 'filedata'
       _log_access = False
       _columns = {
                            'file_name'     :   fields.char('Name'),
                            'time_created'  :   fields.datetime('Date Time'),
                            'size'          :   fields.char('Size')
                        }

I insert values to this fields from function "get_filenames" during button click from another form which is given below

 <form string="voip" version="7.0">
      <style>.openerp .oe_application .oe_breadcrumb_title  {display:none }</style>
      <style>.openerp .oe_view_manager table.oe_view_manager_header .oe_view_manager_buttons{display:none } </style>
      <header>
               <button name="get_filenames" type="object" string="List Files" onclick="display_change()" class="oe_highlight"/>
      </header>
 </form>

But its not working by giving widget="url" . please help!!

Avatar
Discard
Best Answer

Hi,

You can try this

'file_name' : fields.char('Name'),

use this

'file_name' : fields.binary(string='Name'), thanks

Avatar
Discard
Author

@jack I changed my code but its not working . I will add code in my question. please check

@anuradha: give more details regarding your field..

Author

@jack ok .i update the question

@anuradha; You want attached any file using this field ??

Author

@jack i didnt get you :(. I want to attach a link to download mp3 file

I have update answer

Author

@jack i changed code now it shows links eg:- "Download (21.00 bytes)" in my tree view .But I want to show my file names in each field and play my mp3 in browser on clicking that link. I also want an option to download file to users computer. Can you please help me to achieve this

Author

@jack Using binary field help me to download file. Thank alot jack :). Do you help me on playing this mp3 file on clicking play buttton

@anuradha: I didnt get ? (Do you help me on playing this mp3 file on clicking play buttton)

Author

@jack My files are mp3 files. Now i implimented "download" option for them, and i want a "Play" button/link which will play the file !! got me?

@anuradha: I think you have do python code for that create method and execute this method on button click

Author

What should i do in create method? decode binary and return to form?

@anuradha: have finish download mp3 file and play it ..??

How's u download file in url ?

Author

@ jack By giving ftp url

I have same problem, i have create one button export wizard "download zip" , when i click on button it download zip file of exported data , but i am not able downlaod file

I have same problem, i have create one button export wizard "download zip" , when i click on button it download zip file of exported data , but i am not able downlaod file

Author

@jack sorry i will update tomorrow.my work time over

ok but its xml side wht from python side

Author

@jack if you are using binary field no need to use python code .Just add that field in xml and you can download by clicking link.

Author

@jack My py function returns a action url after that my button disables.Open erp adds an attribute disable="disable" to my button . I dnt want to disable button.Please help? My code is <button name="play_file" type="object" string="Play or download" />

def play_file(self, cr, uid, ids, context=None): res = self.read(cr, uid, ids, ['file_name'], context=context) file_name = res[0]['file_name'] return{ 'type': 'ir.actions.act_url', 'url':'ftp://test.claudion.com:123/'+file_name,

'target': 'new',}