How to override odoo im_chat.js file? - python

I want to customize code in im_chat.js -> im_chat.ConversationManager with my own javascript file, not changing any code from im_chat.js file.
Can anyone tell me good practice on how to do this?
Here are the functions i want to customize:
List item
window_title_change
apply_session
activate_session
delete_session
received_message

Try this method:
openerp.your_module = function(instance) {
im_chat.ConversationManager.include({
window_title_change : function(){
//Your code
}
});
};

Related

How to replace get_declared_classes() from CakePHP to Python?

I have been moving website made in Cakephp into Django. In one place I found get_declared_classes(). I thinks this function returns list of previously used classes before running current class.
First time when I encounter this, I just store list of classes manually in one file and I was using that and this solution worked only for a particular web page but Now I have multiple pages calling this class and everytime list of classnames are very different so I can not store class name list.
This code is actually connecting and fetching data from here and I want to replace this class in python(We are replacing whole website). The only problem I have is how to replace get_declared_classes.
class HrbcConnect{
private $scope = '';
private $token = null;
private $token_expire = 0;
private $request_opt = array();
public $id;
public $id_arr = array();
public $write_error;
public function read($resource,$condition='',$field=array(),$order=null){
$declared_classes = get_declared_classes();
foreach(App::objects('Model') as $v){
if(in_array($v,$declared_classes)){
$instance = new $v;
if(property_exists($instance,'hrbc_cols') && array_key_exists(ucfirst($resource),$instance->hrbc_cols)){
foreach($instance->hrbc_cols[ucfirst($resource)] as $vv){
if(is_array($vv)){
$field[] = $vv[0];
}else{
$field[] = $vv;
}
}
}elseif(property_exists($instance,'hrbc_cols_arr')){
foreach($instance->hrbc_cols_arr as $kk=>$vv){
if(array_key_exists(ucfirst($resource),$vv)){
foreach($vv[ucfirst($resource)] as $vvv){
if(is_array($vvv) && !in_array($vvv[0],$field)){
$field[] = $vvv[0];
}elseif(!is_array($vvv) && !in_array($vvv,$field)){
$field[] = $vvv;
}
}
}
}
}
}
}
}
}
When I print the $v in the above code to find what are classes being used, I found list of classes that defined in my models.
If question is not clear please let me know, I can provide more information.
Is there any other library that can replace this function in Python? Or Is there any other solution I can try ?

Uploading multiple files with Quart/Flask adds file-objects to form as bytes and nothing to files [duplicate]

Summary
I am trying to set my FormData properly using javascript.
I need to be able to upload jpg/png, but I might need to upload some other file types pdf/csv in the future using fetch.
Expected
I expect it to append the data to the form
Error
Working
This snippet is working fine:
const formData = new FormData(document.querySelector('form'));
formData.append("extraField", "This is some extra data, testing");
return fetch('http://localhost:8080/api/upload/multi', {
method: 'POST',
body: formData,
});
Not working
const formData = new FormData();
const input = document.querySelector('input[type="file"]');
formData.append('files', input.files);
Question
Does fetch support multiple file upload natively?
If you want multiples file, you can use this
var input = document.querySelector('input[type="file"]')
var data = new FormData()
for (const file of input.files) {
data.append('files',file,file.name)
}
fetch('http://localhost:8080/api/upload/multi', {
method: 'POST',
body: data
})
The issue with your code is in the lineformData.append('files', input.files);
Instead of that, you should upload each file running a loop with unique keys, like this
const fileList = document.querySelector('input[type="file"]').files;
for(var i=0;i<fileList.length;i++) {
formData.append('file'+i, fileList.item(i));
}
I have created a simple error fiddle here with your code. You can check its' submitted post data here, where you can see that no file has been uploaded.
At the bottom of the page you can find
.
I have corrected the fiddle here with the fix. You can check its'post data from the server, where it shows the details of the two files that I uploaded.
I mentioned this on a similar question: I had the same problem, but with a PHP backend. The unique formData keys work, but I found that the classic HTML notation worked just fine and simply results in an array on the server.
formData.append('file[]', data[i]);
I like that a lot better, since I can use the same methods to process this as with a classic <input type="file" multiple />.

Angular python-shell fails on first line

Set Up
I am having an odd problem.
I have a website and I am hoping to run a python script when someone presses a button.
So, I have followed this tutorial: https://www.npmjs.com/package/python-shell
Question:
My console prints this: ReferenceError: require is not defined
on this line: var PythonShell = require('python-shell');
This is the first line in my .js function. I added this line after the npm install step.
How do I overcome this error?
Potentially Helpful Notes
My script looks like this:
angular.module('MYApp')
.controller('MyTypeController', function ($scope, $http, $stateParams, $state) {
$scope.runPythonRoutine = function () {
console.log("Error 1");
var PythonShell = require('python-shell');
var myshell = new PythonShell.run('hello.py', function (err, results) {
console.log("Error 2");
// script finished
});
};
...
My package.json contains:
...
"node-uuid": "1.4.7",
"python-shell": "^0.5.0",
...
require() does not exist in the browser/client-side JavaScript. You need require.js to use require() in the browser. You must also add this to package.json:
"require.js": "version"
and specify require.js in the <script> tag of the html code at the bottom, like so:
<script src="/location/of/require.js/"></script>

Openerp information messages

Is it possible to create information message with options like proceed or cancel in OpenERP ? If it is possible how to create one ?
You can extend a js web module to do that.
Create script.js under /module_name/static/src/js/ which contains:
openerp.module_name = function(instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
/* For example */
instance.web.FormView.include({
});
};
You can create a wizard with cancel and proceed button within

Check some part of string in variable in template Django

Hi i got the site domain in the template name with the
{{request.META.HTTP_HOST}}
from which i got the value some thing like this
pydev.aviesta.com
and
pydev.aviesta.com.mx
i need to show different data for both domains but as this is the dev server i cant use the full doamin name for compare can i check only .mx or .com so there will be no problem when going to live site
You may need Custom filter for this.
#register.filter(name='split')
def split(value, arg):
return value.split('.')[-1]
Use it as {{request.META.HTTP_HOST|split}}
i got the solution with js
<script>
var str = location.host;
if( str.search(".mx") > 0 ){
var dom = 'mx';
}else{
var dom = 'com';
} </script>

Categories