From 053e7a447721a1332dc2147fc5f5cd14e814592b Mon Sep 17 00:00:00 2001 From: Shivam Gutgutia Date: Sun, 19 Nov 2023 18:44:32 +0530 Subject: [PATCH] Fixed the situation where there might be two or more same name columns --- controllers/vcf.py | 6 +++++- utils/vcfGenerator.py | 14 ++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/controllers/vcf.py b/controllers/vcf.py index f792d8b..eab7505 100644 --- a/controllers/vcf.py +++ b/controllers/vcf.py @@ -65,7 +65,11 @@ def vcf(): vcard = vobject.readOne(vcfString) jcard = jsonify({ - "Name": vcard.fn.value if hasattr(vcard, 'fn') else "", + "Prefix":vcard.n.value.prefix, + "First Name":vcard.n.value.given, + "Middle Name":vcard.n.value.additional, + "Last Name":vcard.n.value.family, + "Suffix":vcard.n.value.suffix, "Phone Number(s)": "/".join([tel.value for tel in vcard.tel_list]) if hasattr(vcard, 'tel') else "", "E-Mail": "/".join([email.value for email in vcard.email_list]) if hasattr(vcard, 'email') else "" }) diff --git a/utils/vcfGenerator.py b/utils/vcfGenerator.py index 4790d1d..24f7791 100644 --- a/utils/vcfGenerator.py +++ b/utils/vcfGenerator.py @@ -6,18 +6,20 @@ def generateVcard(row, headers, vCards): vcard = vobject.vCard() - fn = row.get(headers.get("First Name","NA"),"")+row.get(headers.get("Last Name","NA"),"") + fnParameters = [row.get(headers.get(string,""),"") for string in ["First Name","Middle Name","Last Name"]] + fnParameters=request.form.get("Prefix",[])+fnParameters+request.form.get("Suffix",[]) + fn = " ".join(filter(None,fnParameters)) if fn: vcard.add("fn").value = fn else: vcard.add("fn").value = "N/A" vcard.add("n").value = vobject.vcard.Name( - family=row.get(headers.get("Last Name","Not Found"),""), - given=row.get(headers.get("First Name","Not Found"),""), - additional=row.get(headers.get("Middle Name","Not Found"),""), - suffix=request.form.get("suffix",""), - prefix=request.form.get("prefix","") + family=row.get(headers.get("Last Name",""),""), + given=row.get(headers.get("First Name",""),""), + additional=row.get(headers.get("Middle Name",""),""), + suffix=request.form.get("Suffix",""), + prefix=request.form.get("Prefix","") ) fields=headers.get("Phone Number","")