How to add a download hyperlink for downloading attachments from website in odoo - odoo-9

I want to add a hyperlink in the website module in odoo using which I can download the attachments which consists of information of the product which was created.Please help with with this problem .
Thank you

It is too late to answer this question. Anyway it might be helpful to some one. I have googled more, since i didn't get any write solution.
Step 1:
Create hyperlink for download button. In that button you need to pass
model name
field
id
filename (optional)
For an example your link should be like this
<a t-attf-href="/web/binary/download_document?model=product.brand.files&field=file&id={{ file.id }}&file_name={{ file.file_name }}">
Step 2:
Create controller for above link. Ex
class Binary(http.Controller):
#http.route('/web/binary/download_document', type='http', auth="public")
#serialize_exception
def download_document(self,model,field,id,file_name=None, **kw):
""" Download link for files stored as binary fields.
:param str model: name of the model to fetch the binary from
:param str field: binary field
:param str id: id of the record from which to fetch the binary
:param str filename: field holding the file's name, if any
:returns: :class:`werkzeug.wrappers.Response`
"""
Model = request.env[model].sudo().search([('id', '=', int(id))])
filecontent = base64.b64decode(Model.file or '')
headers = werkzeug.datastructures.Headers()
if not filecontent:
return request.not_found()
else:
if not file_name:
filename = '%s_%s' % (model.replace('.', '_'), id)
headers.add('Content-Disposition', 'attachment', filename=filename)
return request.make_response(filecontent,headers)
else:
headers.add('Content-Disposition', 'attachment', filename=file_name)
return request.make_response(filecontent,headers)
It will work. Above code for Odoo 10. You can do the same for below versions also. I have got refer from this link
Cheers.

Here is a working example
return {
'type': 'ir.actions.act_url',
'url': '/web/content/%s/%s' % (attachment_id.id, shortname),
'target': 'self',
'nodestroy': False,
}
In short you just have to have a link that goes to /web/content/ir_attachment_id/the_name_you_want_the_file_to_have.
This works on Odoo V10 too.

this is work from odoo 10 you must try
<a t-attf-href="/web/content?model=website.support.ticket.message&field=attachment&id={{chat.id}}&filename={{chat.attachment_filename}}&download=true">Download</a>

If this is for a form you could do this entirely in the view. First add a record entry somewhere in the xml file:
<record id="module_name.http_link" model="ir.actions.act_url">
<field name="name">Button Name</field>
<field name="type">ir.actions.act_url</field>
<field name="target">new</field>
<field name="url">https://your-http-link</field>
</record>
And then in the form:
<button type="action" name="%(http_link)d" string="Name" class="oe_highlight"/>

Related

How to display custom data in Mgt Person in SPFX

I want to display custom data which is coming from an API which will have data in 4 lines in Person Mgt,
I don't want to use default data from personquery, so how can I pass list of people's data in the Person Mgt also by default it shows data in just three lines but I want to display 4 details of an individual in 4 different lines in SPFX.
I've provided sample implementation of the code,
public render(): React.ReactElement<IMgtComponentsProps> {
return (
<Person
personQuery="me"
//personDetails={personDetails}
view={ViewType.threelines}
fetchImage={true}
avatarType={avatarType.photo}
personCardInteraction={PersonCardInteraction.hover} />
);
}
I'll be having similar type of custom data as shown below so I want to show these details as per user.
const personDetails = {
displayName: 'Bill Gates',
mail: 'nikola#contoso.com',
role:'Developer',
community:'Software Enginnering'
}
I tried passing this object inside personDetails property of Person but it's not working.
Currently a fourth line of data is only support via a custom rendering template
Here's an example of that using the raw web component as opposed to the React Wrapper.
<mgt-person class="my-person" person-query="me">
<template>
<div>
Hello, my name is: {{person.displayName}} <br>
{{person.role}} <br>
{{person.community}} <br>
{{person.mail}}
</div>
</template>
<template data-type="loading">
Loading
</template>
</mgt-person>
const person = document.querySelector('.my-person');
person.personDetails = {
displayName: 'Bill Gates',
mail: 'nikola#contoso.com',
role: 'Developer',
community: 'Software Enginnering'
};
With the existing three line view you can map each of the lines to your custom properties, assuming you have the above custom data being passed correctly you can have the component render the chosen properties on each line.
<mgt-person
class="my-person"
view="threeLines"
line2-property="role"
line2-property="community"
person-card="hover"
fetch-image>
</mgt-person>
The good news for the four-line case is that we are adding that to the library as part of our v3 release which is currently being worked on.

Grails render-plugin does not render images

I have now setup the render-plugin and I get nice PDF-files but I also need to put an image into a few columns in my table. These images are conditionally selected by a data field of the instance.
I have the image in the assets/images folder as I think is the correct place.
I use the following GSP-line in the template that will be used by the renderer to create the PDF.
<td><g:if test="${od?.priceFSC > 0.1}"><asset:image src="checkOut16x16.png" width="16" height="16"/></g:if></td>
As a HTML-view the images prints perfect but when render the PDF they are missing.
I checked the documentation and tried the code from the example:
The controller:
def createPDF() {
def file = new File("asets/CheckOut16x16.png")
def OfferHeader offerHeader = OfferHeader.get(params.id)
[offerHeader: offerHeader])
renderPdf(template: "/stocknote/Stocknote", model: [offerHeader: offerHeader,imageBytes: file.bytes], filename: "Stocknote-"+params.id+".pdf")
}
The view:
<rendering:inlinePng bytes="${imageBytes}" class="some-class" />
I didn't care of the condition here I just wanted to see if it would be printed but it's not because the view crasched:
URI
/stocknote/editStocknote/32
Class
org.grails.taglib.GrailsTagException
Message
Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/stocknote/editStocknote.gsp:32] [views/stocknote/_StocknoteDetail.gsp:3] 'bytes' is required
Caused by
[views/stocknote/editStocknote.gsp:32] [views/stocknote/_StocknoteDetail.gsp:3] 'bytes' is required
I don't know what I've done wrong but error message seems confusing, "Bytes is required" but I have bytes="${imageBytes}".
Hope someone could give me some help or explanation.
Sounds like the path to your file is incorrect, try:
Controller:
def assetResourceLocator
def createPDF() {
def file = assetResourceLocator.findAssetForURI( 'CheckOut16x16.png' )
def OfferHeader offerHeader = OfferHeader.get(params.id)
[offerHeader: offerHeader])
renderPdf(template: "/stocknote/Stocknote", model: [offerHeader: offerHeader,imageBytes: file.getByteArray()], filename: "Stocknote-"+params.id+".pdf")
}
View should be fine as is.
Made a big mistake >_<, The template used to create the PDF is also used by the view from where you order the PDF and at that time the image has not been created by the controller.
So to come through, I had to check the value of the image before rendering.
<g:if test="${imageBytes!= null}"> <rendering:inlinePng bytes="${imageBytes}" /></g:if>
That what was needed.

Server side validation in module setting page in backend joomla

I am using joomla 2.5, i am working on joomla module, i want to perform server side custom form validation at backend setting page in module. I have checked joomla forums , but they all explained according to component , i strictly need to do it in module . I am new in joomla . Please explain the method.
Try this,
First of all you can't do a wide variety of validations like components forms in module params without hacking the core.
the available options are limiting INT,RAW data string only.
you can use the last option of module params called filter. Details take a look at this.
<field name="myintvalue" type="text" default="8" label="Enter some text" description="Enter some description" filter="integer" />
<field name="myhtmlvalue" type="text" default="" label="Enter some text" description="Enter some description" filter="raw" />
Alternate Options.
You can create a custom rule for validation. For example your module name is mod_mymodule:
Add addrulepath attribute to the fieldset in the .xml file:
addrulepath="modules/mod_mymodule"
This will be the path to the custom rule folder.
Add validate attribute to the field with the name of the rule file:
validate="testint"
This will give us the file testint.php.
Create the rule file testint.php and put it to the path specified in the addrulepath attribute. So the full path will be:
administrator/modules/mod_mymodule/testint.php
Here is a simple validation rule class:
class JFormRuleTestint extends JFormRule
{
public function test(&$element, $value, $group = null, &$input = null, &$form = null)
{
return ((int)$value > 0 && (int)$value < 2);
}
}
it should extend JFormRule class and you will need only one method, called test. $value will contain the input from the field. Here we are testing it to be integer between 0 and 2.
Hope its helps..

how to update the image fields in admin side of prestashop

I have added image caption fields in admin products images tab using follwing code in following location
admin/themes/default/template/controllers/products/images.tpl
<td id="td_image_id" class="pointer dragHandle center positionImage">
<input type="text" name="image_caption" value=image_caption >
</td>
I have added image_caption field in ps_image table
imageLine({$image->id}, "{$image->getExistingImgPath()}", {$image->position}, "{if $image->cover}enabled{else}forbbiden{/if}", assoc," {$image->image_caption}");
using above data retreive from the table .now i have stuggle with update the image_caption field.how to update that field ?
There are only 5 arguments in the imageLine JS function, see below
function imageLine(id, path, position, cover, shops)
You need to edit this function by something like that:
function imageLine(id, path, position, cover, shops, image_caption)
{
line = $("#lineType").html();
line = line.replace(/image_id/g, id);
line = line.replace(/image_caption/g, image_caption);
....
}
I hope that will help you.

Tag friends in photo using graph api

I want to tag user's friends into the photo which is uploaded by user from my application....anyone please help me in that...i will be very thank full....i m using codeigniter as a framework....
i already created an photo album in user's profile and uploaded that photo into that but now i want to tag his friends fetched from his friend list...
this is the code i used for creating the album and uploading the photo =>
$fb_config = array(
'appId' => '148056051963323',
'secret' => '0cebf087b3084e5a772b6c31acb2736a'
);
$this->load->library('facebook', $fb_config);
$this->facebook->setFileUploadSupport(true);
$album_details = array(
'message'=> 'For more LoL images check out -> http://lolsharing.com/',
'name'=> 'LoL Sharing'
);
$album_exist_check = $this->common_model->check_album($_SESSION['user_fb_id']);
if($album_exist_check['album_id']==0)
{
$create_album = $this->facebook->api('/me/albums', 'post', $album_details);
$insert_ablum = $this->common_model->insert_ablum($_SESSION['user_fb_id'], $create_album['id']);
}
else
{
$create_album['id'] = $album_exist_check['album_id'];
}
$photo_details = array(
'message'=> ''.$image_name['image_caption'].' for more LoL Images check out - http://lolsharing.com/'
);
$photo_details['image'] = '#' . realpath(''.FCPATH.'assets/joke_images/'.$image_name['image_name'].'');
$upload_photo = $this->facebook->api('/'.$create_album['id'].'/photos', 'post', $photo_details);
if($upload_photo)
{
$this->common_model->user_point_counter($image_id);
$this->common_model->user_self_point_counter();
if($upload_photo)
{
//redirect(''.$_SESSION['return_url'].'');
echo "<div class='button1'>Image Shared.</div>";
echo '<div class="num_share">
Total Shares <br />
<span> '.$image_name['shares'].'</span>
</div>';
}
}
please help me..thanks in advance
Here's how to add tags. The example I'm giving is using the Graph API Explorer: https://developers.facebook.com/tools/explorer
See also the tags section of: https://developers.facebook.com/docs/reference/api/photo/
request a token with the appropriate permissions (see above link for the permission you will need)
Enter in your photo ID and click Get
Add /tags to the graph url and click Get to see what tags already exist
Change Get To Post in the dropdown
Click Add a field, Name= to, Value= a friends id or your id
Click Add a field, Name = x, value = 45
Click Add a field, Name = y, value = 45
Click Submit
Change Post back to Get in the dropdown
Click Submit to see the new tag
Of course the person you're tagging in the photo might need to approve the tag if they have their security features set as such.

Resources