I want render data on home (index) page, below is my example:
controller:
import openerp.http as http
from openerp.http import request
class TestController(http.Controller):
#http.route('/index',auth='public',website=True)
def list(self,**kw):
Test9 = http.request.env['test.9']
arr = Test9.search([])
print arr
return http.request.website.render('website.layout',
{'test9':Test9.search([])
})
xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="test9" name="Test9" page="True">
<t t-call="website.layout">
<div class="oe_structure">
<div class="container">
<center><h3>Details</h3></center>
<t t-foreach="test9" t-as="company">
<h4><span t-esc="company.name"/></h4>
<table class="table-striped table">
<tr>
<td>Name:</td>
<td><span t-esc="company.name"/></td>
</tr>
<tr>
<td>City:</td>
<td><span t-esc="company.city"/></td>
</tr>
<tr>
<td>Place:</td>
<td>
<td><span t-esc="company.place"/></td>
</td>
</tr>
</table>
</t>
</div>
</div>
</t>
</template>
</data>
</openerp>
After run http://localhost:8069/index in console get two record
Where is problem in my code?
................................................................................................................................................
Try This.
import openerp.http as http
from openerp.http import request
class List(openerp.addons.web.controllers.main.Home):
#http.route('/', type='http', auth='none', website=True)
def index(self):
Test9 = request.env['test.9']
arr = Test9.search([])
print arr
return request.render('YOUR_MODULE.test9',
{'test9':Test9.search([])
})
Related
I am trying to fetch data from a table into separate fields of a CSV file.
The table in the website looks like this:
And (part of) the source of the webpage looks like this:
<div id="right">
<div id="rightwrap">
<h1>Krimpen aan den IJssel</h1>
<div class="tools">
print
terug
</div>
<h2 class="lijst">Krimpen aan den IJssel</h2>
<div class="dotted"> </div>
<div class="zoekres">
<h4>Aantal kindplaatsen</h4>
<div class="paratable">
<table cellpadding="0" cellspacing="0">
<tr>
<th> </th>
<th>2006</th>
<th>2008</th>
<th>2009</th>
<th>2010</th>
<th>2011</th>
</tr>
<tr>
<th>KDV</th>
<td>144</td>
<td>144</td>
<td>174</td>
<td>243</td>
<td>-</td>
</tr>
<tr>
<th>BSO</th>
<td>135</td>
<td>265</td>
<td>315</td>
<td>365</td>
<td>-</td>
</tr>
<tr>
<th>Totaal</th>
<td>279</td>
<td>409</td>
<td>489</td>
<td>608</td>
<td>-</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="brtotal"> </div>
</div>
I managed to retrieve the name of the place "Krimpen aan den IJssel" using this code:
def parse(self, response):
item = OrderedDict()
for col in self.cols:
item[col] = 'None'
item['Gemeente'] = response.css('h2.lijst::text').get('')
yield item
But I am unable to retrieve the values displayed in the table of this website. The standard approach for table using:
response.xpath('//*[#class="table paratable"]
doesn't seem to work or I am not experienced enough to set the parameters right.
Can anyone provide me with some lines of code that will bring the
values from this table into the following columns of my CSV-file
KDV_2006 KDV_2008 KDV_2009 KDV_2010 KDV_2011 BSO_2006 BSO_2008
BSO_2009 BSO_2010 BSO_2011
One possible way:
result = {}
years = response.xpath('//div[#class="paratable"]/table/tr[1]/th[position() > 1]/text()').getall()
for row in response.xpath('//div[#class="paratable"]/table/tr[position() > 1][position() < last()]'):
field_name = row.xpath('./th/text()').get()
values = row.xpath('./td/text()').getall()
for year, value in zip(years, values):
result[f'{field_name}_{year}'] = value
After reading docs & forums for hours... still have no answer.
Have the following JS/HTML:
Vue.component("my-component", {
props: ["id"],
render: function(h) {
return h("tr", this.$slots.default);
}
});
var vapp = new Vue();
<script src="https://unpkg.com/vue#2.4.2/dist/vue.js"></script>
<table>
<tr is="my-component" :name="yo">
<td>
<span v-text="name"></span>
</td>
</tr>
</table>
Use tr + "is" attribute to specify component within the table otherwise browser will hoist it out as invalid content. Done
Use render + h("tr"...) because vuejs doesn't render tr element, but instead table > td and again browser hoist it out.Done
Now I have table > tr > td rendered well but how can I add children bound to the props/data, so I will see "yo" on the screen.
Thanks a lot!
If the elements in the slot need access to data inside the component, then you need to use a scoped slot.
Since you are using a render function, the scoped slot is available as a function through this.$scopedSlots.default() and you pass it an object with the data you want to be made available to the scoped slot.
You also need to define the scoped slot in the template. Here is an example.
Vue.component("my-component", {
props: ["id", "name"],
render: function(h) {
return h("tr", this.$scopedSlots.default({name: this.name}));
}
});
var vapp = new Vue({ el:"#app"});
<script src="https://unpkg.com/vue#2.4.2/dist/vue.js"></script>
<div id="app">
<table>
<tr is="my-component" :name="'yo'">
<template scope="{name}">
<td>
<span v-text="name"></span>
</td>
</template>
</tr>
</table>
</div>
If you are using .vue files you can have the table row component defined like this:
<template>
<tr>{{ name }}</tr>
</template>
<script>
export default {
name: 'table-row',
props: ['name'],
};
</script>
Then use it like this:
<table>
<tr is="TableRow" name="Some name here"></tr>
</table>
<table>
<thead>
<!-- ...some th -->
</thead>
<tbody>
<tr>
<td>..</rd>
</tr>
<template> <row-component my-param="blabla"></row-component> <!-- component return full row <tr>...</tr> -->
<some-other-recomponent my-par="blabla"></some-other-recomponent> <!-- component return full row <tr>...</tr> -->
</template>
</tbody>
</table>
If your're interested in returning multiple rows from your component, you can do like this.
In your main component.
<table width="90%">
<thead>
<tr>
<th width="1%">#</th>
<th>header description</th>
</tr>
</thead>
<template>
<your-child-component
:prop="prop-data"
v-for="(lancamento, index) in lancamentos"
:key="lancamento.id">
</your-child-component
</template>
</table>
And inside your child component
<template>
<tbody> <!-- dont forget this tag -->
<tr>
<td rowspan="2" v-html="prop.id"></td>
<td><td>
</tr>
<tr>
<td colspan="2" class="text-center"></td>
</tr>
</tbody>
</template>
test.html
<gid>
<grid-col prop1=""></grid-col>
<grid-col-checkbox prop1=""></grid-col-checkbox>
<grid-col-radio prop1=""></grid-col-radio>
<grid-col-custom prop1=""></grid-col-custom>
</grid>
test.js
export class Test {}
==============
grid.html
<table>
<tbody>
<td>test</td>
=======
<template classs="foo-class" repeat="">
</template>
======
</tbody>
</table>
grid.js
export class Grid {}
I want to insert the below things in table body. so that they will repeat for entire data
<grid-col prop1=""></grid-col>
<grid-col-checkbox prop1=""></grid-col-checkbox>
<grid-col-radio prop1=""></grid-col-radio>
<grid-col-custom prop1=""></grid-col-custom>
Can any one help how we can do this?
You can create a template for your table row:
my-table-row-template.html
<template>
<td>
<grid-col prop1=""></grid-col>
</td>
<td>
<grid-col-checkbox prop1=""></grid-col-checkbox>
</td>
<td>
<grid-col-radio prop1=""></grid-col-radio>
</td>
<td>
<grid-col-custom prop1=""></grid-col-custom>
</td>
</template>
NOTE: you can omit the <td></td> elements if they are already in your grid-col-x components
then to use just
<require from="my-table-row-template.html"></require>
<tr repeat.for="item of items">
<my-table-row-template item.bind="item"></my-table-row-template>
</tr>
REFERENCE: http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.1.3/doc/article/cheat-sheet/4
I'm trying to get the download and filename of a file from the website.
model
class Files(models.Model):
_name = 'website_downloads.files'
name = fields.Char()
file = fields.Binary('File')
controler
class website_downloads(http.Controller):
#http.route('/downloads/', auth='public', website=True)
def index(self, **kw):
files = http.request.env['website_downloads.files']
return http.request.render('website_downloads.index', {
'files': files.search([]),
})
template
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="index" name="Website Downloads Index">
<t t-call="website.layout">
<div id="wrap" style="margin-top:50px;margin-bottom:50px">
<div class="container text-center">
<table class="table table-striped">
<t t-foreach="files" t-as="f">
<tr>
<td><t t-esc="f.name"/></td>
**<td>Download</td>**
</tr>
</t>
</table>
</div>
</div>
</t>
</template>
</data>
</openerp>
How can I get the download link, and when saving the file in the db save de original filename
Odoo comes with a built-in /web/binary/saveas controller, that can be used for exactly this purpose:
<t t-foreach="files" t-as="f">
<tr>
<td><t t-esc="f.name"/></td>
<td><a t-attf-href="/web/binary/saveas?model=website_downloads.files&field=file&filename_field=name&id={{ f.id }}">Download</a></td>
</tr>
</t>
The controller takes four arguments:
model - the name of the model with the Binary field
field - the name of the Binary field
id - id of the record containing particular file.
filename_field - name of a Char field containing file's name (optional).
I'm new in odoo so sorry if this is a noob question.
How can I assing unlogged website user read permission to the model?
which is the website user group?
And why odoo 8.0 documentation so poor?
I've made a module website_downloads:
models:
class Files(models.Model):
_name = 'website_downloads.files'
name = fields.Char()
file = fields.Binary('File')
filename = fields.Char()
controler:
class website_downloads(http.Controller):
#http.route('/downloads/', auth='public', website=True)
def index(self, **kw):
files = http.request.env['website_downloads.files']
return http.request.render('website_downloads.index', {
'files': files.search([]),
})
website template:
<template id="index" name="Website Downloads Index">
<t t-call="website.layout">
<div id="wrap" style="margin-top:50px;margin-bottom:50px">
<div class="container text-center">
<table class="table table-striped">
<t t-foreach="files" t-as="f">
<tr>
<td align="left"><t t-esc="f.name"/></td>
<td><t t-esc="f.filename"/></td>
<td><a t-attf-href="/web/binary/saveas?model=website_downloads.files&field=file&filename_field=filename&id={{ f.id }}"> <i class="fa fa-download"></i> Download</a></td>
</tr>
</t>
</table>
</div>
</div>
</t>
</template>
security
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_website_downloads_user,website_downloads.files,model_website_downloads_files,base.group_user,1,0,0,0
access_website_downloads_manager,website_downloads.files,model_website_downloads_files,base.group_sale_manager,1,1,1,1
"base.group_public"
I solved adding this to the security file
access_website_downloads_public,website_downloads.files,model_website_downloads_files,base.group_public,1,0,0,0