I want to update request context,
request.env.context
At the moment I got this dictionary
{'lang': u'en_US', 'tz': False, 'uid': 21}
I wanna update lang key, and expected output of
request.env.context
{'lang': 'de_DE', 'tz': False, 'uid': 21}
Any idea how.
context = request.env.context.copy()
context.update({'lang': u'en_CA'})
request.env.context = context
Below code works well for me, I am guessing that you are working with a pos.order model
pos_order = request.env['pos.order'].with_context(
lang='de_DE')
Related
I have below object :
obj1 = [{ id = 1, name = "abc"}, {id=2, name="pqr"}, {id=3, name="xyz"}]
I need to delete an object with id=2 where id is Primary Key too.
Below method using to delete the object
const collection = RealmDB.realm
.objects("StudentName")
.filtered(`id= $0`, '65');
RealmDB.realm.write(() => {
RealmDB.realm.delete(collection);
});
But it is not working with id object can anyone please suggest better way to do this ?
But still that object is there so may I know what is wrong here.
const id = 1;
realm.write(()=>{
realm.delete(realm.objectForPrimaryKey('Baby',id));
})
Try this.
Hello resolved an issue by following query with no error
const collection = RealmDB.realm
.objects('StudentName')
.filtered('id= $0', `65`);
RealmDB.realm.write(() => {
RealmDB.realm.delete(collection);
Thank you
im trying to make a dataframe out of a list of dictionaries. I am quite new at this whole programming thing, and google just makes me more confused. That is why i am turning to you guys hoping for some assistance.
The first two list values (YV01', '3nP3RFgGnBrOfILK4DF2Tp) i would like to have under columns called: Name and GlobalId. I would lie to drop Pset_wallcommon, AC_Pset_RenovationAndPhasing, and BaseQuantities. And use the rest of the keys(if that what they are called) as column names.
It would be great if someone could give me the right push :)
For the record: Im am parsing an Ifc file with the IfcOpenshell package
The data:
['YV01', '3nP3RFgGnBrOfILK4DF2Tp', {'Pset_WallCommon': {'Combustible': False, 'Compartmentation': False, 'ExtendToStructure': False, 'SurfaceSpreadOfFlame': '', 'ThermalTransmittance': 0.0, 'Reference': '', 'AcousticRating': '', 'FireRating': '', 'LoadBearing': False, 'IsExternal': False}, 'AC_Pset_RenovationAndPhasing': {'Renovation Status': 'New'}, 'BaseQuantities': {'Length': 13786.7314346, 'Height': 2700.0, 'Width': 276.0, 'GrossFootprintArea': 3.88131387595, 'NetFootprintArea': 3.88131387595, 'GrossSideArea': 37.9693748734, 'NetSideArea': 37.9693748734, 'GrossVolume': 10.4795474651, 'NetVolume': 10.4795474651}}, 'YV01', '1M4JyBJhXD5xt8fBFUcjUU', {'Pset_WallCommon': {'Combustible': False, 'Compartmentation': False, 'ExtendToStructure': False, 'SurfaceSpreadOfFlame': '', 'ThermalTransmittance': 0.0, 'Reference': '', 'AcousticRating': '', 'FireRating': '', 'LoadBearing': False, 'IsExternal': False}, 'AC_Pset_RenovationAndPhasing': {'Renovation Status': 'New'}, 'BaseQuantities': {'Length': 6166.67382573, 'Height': 2700.0, 'Width': 276.0, 'GrossFootprintArea': 1.6258259759, 'NetFootprintArea': 1.6258259759, 'GrossSideArea': 15.9048193295, 'NetSideArea': 15.9048193295, 'GrossVolume': 4.38973013494, 'NetVolume': 4.38973013494}}
all_walls = ifc_file.by_type('IfcWall')
wallList = []
for wall in all_walls:
propertySets = (ifcopenshell.util.element.get_psets(wall))
wallList.append(wall.Name)
wallList.append(wall.GlobalId)
wallList.append(propertySets)
print(wallList)
wall_table = pd.DataFrame.from_records(wallList)
print(wall_table)
I have tried these basic pd.DataFrame.from_dict/records/arrays(data)
but the output looks like this
enter image description here
UPDATE: Thank you so much for your help, i am learning alot from this!
So i made a dictionary out of the wallList, and flattened the dict. like this:
#list of walls
for wall in all_walls:
propertySets = (ifcopenshell.util.element.get_psets(wall))
wallList.append(wall.Name)
wallList.append(wall.GlobalId)
wallList.append(propertySets)
#dict from list
wall_dict = {i: wallList[i] for i in range(0, len(wallList))}
new_dict = {}
#flattening dict
for key, value in wall_dict.items():
if isinstance(value, dict):
for key in value.keys():
for key2 in value[key].keys():
new_dict[key + '_' + key2] = value[key][key2]
else:
new_dict[key] = value
wall_table = pd.DataFrame.from_dict(new_dict, orient='index')
print(wall_table)
It seems to work pretty good, the only problem is that the dataframe contains all walls, but only propertyset data from the first in the list. I cant seem to understand how the dict flattening loop works. I would also like the index names (Pset_WallCommon_Combustible, and so on) to be the columns in my dataframe. Is that possible?
enter image description here
EDIT : Simply flattening a list as i did goes nowhere. Actually, i think you should drop this list thing altogether and try to load the Dataframe from a dictionnary. We'd need to see what does all_walls look like to help you for that, tho.
Have you tried directly loading the all_walls dictionary into a dataframe : df = pd.Dataframe.from_dict(all_walls) ?
I think if that doesnt work, flattening the dictionnaries in a fashion similar to the following should do the trick.
new_dict = {}
for key, value in all_walls.items():
if isinstance(value, dict):
for key in value.keys():
for key2 in value[key].keys():
new_dict[key + '_' + key2] = value[key][key2]
else:
new_dict[key] = value
What i'm trying to achieve is ,When updating a field in model A ,i needs to update a field in model B using onchange method
_name = 'Model_A'
health_profile = fields.Many2one('health.profile', domain="[('partner_id', '=', partner_id)]", string="Health Profile")
#api.onchange('health_profile')
def get_health_profile_specialist(self):
ctx = self.health_profile.id
res = self.env['model_B'].browse(ctx)
return res.update({'specialist_name': self.specialist_name})
From what I understand there is no need to modify the field with an onchange. You can directly check the value in the model A field, you could directly use a related field
health_profile = fields.Many2one('health.profile', domain="[('partner_id', '=', partner_id)]", string="Health Profile")
specialist_id = fields.Many2one('<yourmodel>', related='health_profile.specialist_id')
Maybe you should explain yourself better.
I'm new to ember and I want to post a new record, So I did something like:
App.AdminController = Em.Controller.extend
submit: ->
post = App.Post.createRecord()
post.set('author', $('#author').val())
post.set('title', $('#title').val())
post.set('intro', $('#intro').val())
post.set('description', $('#description').val())
post.set('publishedAt', new Date())
post.get('store').commit()
Everything works like a charm, except the publisedAt attribute e in post request json file is null
I think the problem is due to that I may not serialise it correctly, any idea?
update the model:
App.Post = DS.Model.extend
title: DS.attr('string')
author: DS.attr('string')
intro: DS.attr('string')
description: DS.attr('string')
publishedat:DS.attr('date')
Try using JSON.stringify on the Date object:
post.set('publishedAt', JSON.stringify(new Date()))
For some reason, you can't invoke new Date() inside the .set method. This should work:
var d = new Date();
post.set('publishedAt', d);
Using nodejs, mongoskin.. I'd like to return the updated doc so Im using findAndModify, however the query {_id: "someid"} doesn't work. I think I need to use {id: ObjectID{'someid'} as the query. How do I get the ObjectId type into JS?
try this:
ObjectID = require('mongoskin').ObjectID
{_id: new ObjectID("someid")}
Here is a solution
var mongo = require("mongoskin");
var conn = mongo.db(YOUR_DETAILS);
var BSON = mongo.BSONPure;
this enables you to convert your id int, string or whatever using:
conn.collection(YOUR_COLLECTION).find({_id:new BSON.ObjectID(YOUR_ID)})
Hope that helps!
You can do something like:
yourCollection = db.collections('yourCollection');
Then
{ _id: yourCollection.id("someId") }