feat: download contact list as vCards
This commit is contained in:
parent
b53203e14c
commit
9d19701e56
2 changed files with 26 additions and 0 deletions
|
|
@ -218,6 +218,24 @@ def download_vcard(contact: str):
|
|||
frappe.response["type"] = "binary"
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_vcards(contacts: str):
|
||||
"""Download vCard for the contact"""
|
||||
from frappe.utils.data import now
|
||||
|
||||
vcards = []
|
||||
for contact_id in frappe.parse_json(contacts):
|
||||
contact = frappe.get_doc("Contact", contact_id)
|
||||
vcard = contact.get_vcard()
|
||||
vcards.append(vcard.serialize())
|
||||
|
||||
timestamp = now()[:19] # remove milliseconds
|
||||
|
||||
frappe.response["filename"] = f"{timestamp} Contacts.vcf"
|
||||
frappe.response["filecontent"] = "\n".join(vcards).encode("utf-8")
|
||||
frappe.response["type"] = "binary"
|
||||
|
||||
|
||||
def get_default_contact(doctype, name):
|
||||
"""Return default contact for the given doctype, name."""
|
||||
out = frappe.db.sql(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
frappe.listview_settings["Contact"] = {
|
||||
add_fields: ["image"],
|
||||
onload: function (listview) {
|
||||
listview.page.add_action_item(__("Download vCards"), function () {
|
||||
const contacts = listview.get_checked_items();
|
||||
open_url_post("/api/method/frappe.contacts.doctype.contact.contact.download_vcards", {
|
||||
contacts: contacts.map((c) => c.name),
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue