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
Related
In my vueJs project, i have a table that displays some products data from the database. When i click on a product tr, it should open a modal that displays a form to enter further details for the product clicked like so:
<table class="table table-responsive table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Product Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-for="prod in products" :key="prod.id">
<td>{{ prod.id }}</td>
<td>{{ prod.name }}</td>
<td><button class="btn btn-success btn-sm" #click.prevent="addStocks(prod)">Add Stock</button></td>
</tr>
</tbody>
</table>
Now in my script, i have a method to open the modal and pass the value of the item clicked to the modal like so;
addStocks(prod){
this.$modal.show('add-stocks')
this.newStock.unitPrice = prod.sellin_price
this.newStock.id = prod.id
this.newStock.name = prod.name
},
and my data object
data() {
return {
newStock: {
id: null,
name: '',
size: '',
srln: '',
colour: '',
mfg: '',
expiry: '',
selling_price: ''
},
}
}
and the modal component
<modal name="add-stocks" height="auto" :draggable="true" :width="600">
<div class="modal-header">
<h4>Add new stock</h4>
</div>
<div class="modal-body form-horizontal">
<div class="form-group">
<label for="unitPrice" class="control-label col-md-2">Unit Price</label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">₦</span>
<input class="form-control" v-model="newStock.unitPrice" readonly aria-describedby="basic-addon1">
</div>
</div>
<div style="clear:both"></div>
</div>
<div class="form-group">
//form fields here
</div>
<div class="modal-footer modal_btns">
<button class="btn btn-primary" #click.prevent="uploadStock">Save</button>
<button class="btn btn-danger" #click.prevent="cancelUpload">Cancel</button>
</div>
</modal>
Now, the issue is when i fill the fields in the modal and click on the cancel button (without saving), i expect the fields to be cleared so when i click on another product tr, i get a fresh form, but this is not the case, the details filled into the previously closed modal form displays. In the cancelUpload methods, i have cleared the fields before closing the modal;
cancelUpload(){
this.$modal.hide('add-stocks')
this.newStock.unitPrice = prod.sellin_price
this.newStock.id = prod.id
this.newStock.name = prod.name
}
When i click on the save button and after api call is made, i call this method to hide the modal but the same issue occurs as the details display when next i open another modal.
How do i fix this?
First of all check whether your method is called everytime the modal is being closed i.e either by clicking on cancel button,cross sign or esc key.
Next this could be the issue of vue reactivity.
An object property should be updated using set method in vue js to keep it reactive.
Hence try as below.
cancelUpload(){
this.$modal.hide('clear-stocks')
this.$set(this.newStock,unitPrice,'');
this.$set(this.newStock,id,'');
this.$set(this.newStock,name,'');
}
You can clear other properties also in the above method.
Or else in the addStocks method also you can set the rest of properties to empty.
More on Vue.set here.
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([])
})
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).
Hey guys i'm having some problems with how to upload and save images using angularjs and flowjs.
I'm new to angularjs and had my problems trying to make an image upload but i got it working with ng-flow, still i'm having some problems trying to save the image to some designed path.
One exemple and similar problem is this one How and where save uploaded files with ng-flow? , but i still couldn't made it work.
Here's the code for the upload and preview, working fine so far so good:
<div class="ng-scope add-file" flow-init="{target:'../WebService/WebService.asmx/setImage'}"
flow-name="image.flow" flow-files-submitted="$flow.upload()"
flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1}[$file.getExtension()]">
<div class="row" style="margin-top: 0px!important;">
<div class="col-sm-10">
<p><label for="image">ADD PHOTO</label></p>
<table style="border: 0px;">
<tr>
<td ng-repeat="file in $flow.files" class="ng-scope thumbnail" style="margin: 3px 3px 3px 3px;">
<div class="text-right">
<a class="glyphicon glyphicon-remove" ng-click="file.cancel()"
style="color:#ff4b4b; text-decoration: none!important;"></a>
</div>
<div class="frame" ng-show="$flow.files.length" style="min-width: 210px!important;">
<span class="helper"></span>
<img flow-img="file" src="" class="image-thumbnail">
</div>
<div class="progress progress-striped" ng-class="{active: file.isUploading()}">
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0"
aria-valuemax="100" ng-style="{width: (file.progress() * 100) + '%'}">
</div>
<span class="sr-only ng-binding">1% Complete</span>
</div>
</td>
</tr>
</table>
</div>
<div class="col-sm-2 text-right drop" flow-drop="" ng-class="dropClass">
<span class="file-upload btn btn-primary" flow-btn="">
Choose file
<input type="file" multiple="multiple" style="visibility: hidden; position: absolute;">
</span>
</div>
</div>
But here's the problem, i don't know how or what to do to create this image in some path...
I'm passing to ng-flow-init my webservice method as it will send via url parameters like this:
flow-init="{target:'../WebService/WebService.asmx/setImage'}"
and the ws receive it like the following example:
../setImage?flowChunkNumber=1&flowChunkSize=1048576&flowCurrentChunkSize=198637&flowTotalSize=198637&flowIdentifier=198637-1jpg&flowFilename=1.jpg&flowRelativePath=1.jpg&flowTotalChunks=1
'flowChunkNumber=1
'flowChunkSize=1048576
'flowCurrentChunkSize=111168
'flowTotalSize = 111168
'flowIdentifier=111168-Figura1png
'flowFilename=Figura1.png
'flowRelativePath=Figura1.png
'flowTotalChunks = 1
What should i do with these informations or what do i need to send the data (binary, base64, etc) and save/create the image on my server?
Edit 1: I already know that i need the file data and figured that i do need an upload.php to transform and send the file.
Still can't even think about how to create an upload.php for vb.net
After a long time searching i decided to move forward and do with an entirely different way, i removed pretty much all my custom css and style to make it more clean to read.
Before anything i changed somethings like i'm not using ng-flow anymore, it's purely angularjs and javascript, and i'm encoding the file to Base64 and decoding it on my server side.
HTML:
<div class="row">
<div class="col-sm-10">
<table>
<tr>
<td ng-repeat="image in images">
<div>
<img id="imagePreview{{$index}}" src="#" alt="" />
</div>
</td>
</tr>
</table>
</div>
<div class="col-sm-2 text-right">
<input type="file" id="img" />
<button ng-click="addImage()" type="button">ADD</button>
</div>
</div>
AngularJS Controller:
$scope.images = [];
//Don't let the same file to be added again
$scope.removeImage = function (index) {
$scope.images.splice(index, 1);
}
//Add new file to $scope.images
$scope.addImage = function () {
var
reader = new FileReader(),
$img = $("#img")[0],
index = $scope.images.length;
reader.onload = function (e) {
if ($scope.images.indexOf(e.target.result) > -1) return;
$scope.images.push(e.target.result);
if (!$scope.$$phase) $scope.$apply();
$("#imagePreview" + index).attr('src', e.target.result);
$scope.uploadImage(index);
}
reader.readAsDataURL($img.files[0]);
};
And here it is how to get the files converted to Base64:
$scope.uploadImage = function (index) {
var res = $scope.images[index];
//{...} Your code here, method call etc.
}
I'm trying to implement a Google Custom Search Engine into my website. So far, I've been able of changing my snippets layout, and show the variables Google shows in its examples:
http://googleajaxsearchapi.blogspot.com.es/2010/04/rendering-custom-data-in-custom-search.html
Well, in the examples, everything looks great, BECAUSE THEY KNOW THE VALUES THEY MAY PRINT. I mean, if you see this snippet:
<div id="mysite_thumbnail">
<div data-if="Vars.thumbnail" class="gs-image-box gs-web-image-box">
<a class="gs-image" data-attr="{href:url, target:target}">
<img class="gs-image" data-attr="{src:thumbnail.src, width:48, height: 48}"/>
</a>
</div>
</div>
it's pretty clear that "Vars" is holding some data GSE is printing. My problem is that I don't know what "Vars" holds, and when developing my view I can't know if the value is there, and what is its name.
So, the question is: How can I print "Vars"? I suppose is a js variable you may obtain from the jsapi, but juss guessing, console.log() was not working for me, :(
Well, I finally found out how to post the data:
From Google Search Engine Api documentation:
https://developers.google.com/custom-search/docs/js/rendering?hl=es&csw=1#richsnip
You only have to add the following code in your snippet:
<span data-body="JSON.stringify(Vars)"></span>
So, you'll have something like:
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
// Load the Search API
google.load('search', '1');
// Set a callback to load the Custom Search Control when you page loads
google.setOnLoadCallback(
function(){
new google.search.CustomSearchControl('XXXXXXXXXXXXXXX').draw('cse');
google.search.Csedr.addOverride("mysite_");
},
true);
console.log(google);
</script>
<div style="display:none">
<div id="mysite_thumbnail">
//This will show all Vars content
<span data-body="JSON.stringify(Vars)"></span>
<div data-if="Vars.thumbnail" class="gs-image-box gs-web-image-box">
<a class="gs-image" data-attr="{href:url, target:target}">
<img class="gs-image" data-attr="{src:thumbnail.src, width:48, height: 48}"/>
</a>
</div>
<div data-ifel="Vars.thumbnail == 0" class="gs-image-box gs-web-image-box">
<a class="gs-image" data-attr="{href:url, target:target}">
<img class="gs-image" data-attr="{src:'XXXXX.png', width:115, height: 90}"/>
</a>
</div>
</div>
<div id="mysite_webResult">
<div class="gs-webResult gs-result"
data-vars="{longUrl:function() {
var i = unescapedUrl.indexOf(visibleUrl);
return i < 1 ? visibleUrl : unescapedUrl.substring(i);}}">
<table>
<tr>
<td valign="top">
<div data-if="Vars.richSnippet" data-attr="0"
data-body="render('thumbnail',richSnippet,{url:unescapedUrl,target:target})"></div>
</td>
<td valign="top">
<div class="gs-title">
<a class="gs-title" data-attr="{href:unescapedUrl,target:target}"
data-body="html(title)"></a>
</div>
<div class="gs-snippet" data-body="html(content)"></div>
</td>
</tr>
</table>
</div>
</div>
</div>