What does context.get ('active_ids', []) mean? Why are we using this?

The following code is from export_stockinfo_xlsin Odoo 10. I want to know what it means context.get('active_ids', [])and what the return value is. Why do we use []in this expression?

@api.multi
def export_xls(self):
    context = self._context
    datas = {'ids': context.get('active_ids', [])} # what mean this and what return

    datas['model'] = 'product.product'
    datas['form'] = self.read()[0]

    for field in datas['form'].keys():
        if isinstance(datas['form'][field], tuple):
            datas['form'][field] = datas['form'][field][0]
    if context.get('xls_export'):
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'export_stockinfo_xls.stock_report_xls.xlsx',
            'datas': datas,
            'name': 'Current Stock'
        }
+4
source share
2 answers

If you are in a tree view context.get('active_ids', []), a list of identifiers of checked items is returned. If you are in a form, it returns the identifier of the element that you see on the screen. If the item identifier is missing, it returns an empty list ([]). Hope this helps you.

+2
source

dict.get . , dict.

dict.get :

dictionary = {"message": "Hello, World!"}
print(dictionary.get("message", ""))
print(dictionary.get("message_1111", "No Value"))   #Note: "message_1111" not in dictionary. 

:

Hello, World!
No Value

MoreInfo

.

context.get('active_ids', [])

'active_ids' , .

0

Source: https://habr.com/ru/post/1695109/


All Articles