I’m trying to write a custom data import. Currently, I have a button that pops up a dialog:
I’m now stuck in implementation. This is my JS code:
listview.page.add_inner_button('Import Members', function () {
frappe.prompt({
label: 'Attach a CSV file',
fieldname: 'import_file',
fieldtype: 'Attach'
}, (values) => {
frappe.call({
method: 'custom_features.custom_features.doctype.campaign_member.campaign_member.import_members',
args: {
'url': values.import_file
}
});
});
});
My import_members
function is like this:
@frappe.whitelist()
def import_members(url):
# My code
Now, I first need to read the file before starting on the importing. How do I do that? I’ve tried:
-
frappe.db.get("File", {"file_url": url}).get_contents()
- this raises an error saying thatNoneType
isn’t callable, which means that theget_contents
method isNone
. -
requests.get(url)
- to make this work, I prependedwindow.location
tourl
before passing it here. But this raises a 403 error, although the URL works in the browser.
I don’t understand why both of the above methods don’t work. Especially the first one - it should either raise an error, or be a function, but it’s None
.
Could you help me with getting the file contents? Possibly as a Pandas DF, but any format would work.
Thanks.