6957: VCF export/import should support [x-]gender

reapply from gramps40

svn: r22764
This commit is contained in:
Vassilii Khachaturov 2013-07-29 08:55:49 +00:00
parent 174a1dac95
commit f36b5e66ae
2 changed files with 32 additions and 1 deletions

View File

@ -52,7 +52,7 @@ _ = glocale.translation.gettext
from gramps.gui.plug.export import WriterOptionBox
from gramps.gen.const import PROGRAM_NAME
from gramps.version import VERSION
from gramps.gen.lib import Date
from gramps.gen.lib import Date, Person
from gramps.gen.lib.urltype import UrlType
from gramps.gen.lib.eventtype import EventType
from gramps.gen.display.name import displayer as _nd
@ -171,6 +171,7 @@ class VCardWriter(object):
self.write_name(prname)
self.write_sortstring(prname)
self.write_nicknames(person, prname)
self.write_gender(person)
self.write_birthdate(person)
self.write_addresses(person)
self.write_urls(person)
@ -252,6 +253,18 @@ class VCardWriter(object):
if len(nicknames) > 0:
self.writeln("NICKNAME:%s" % (','.join(self.esc(nicknames))))
def write_gender(self, person):
"""Write the X-GENDER property of a VCard (X- dropped in 4.0, we're at 3.0)."""
gender = person.get_gender()
gender_value = ''
if gender == Person.MALE:
gender_value = 'Male'
elif gender == Person.FEMALE:
gender_value = 'Female'
log.info("gender: %s -> %s" % (gender, gender_value))
if gender_value:
self.writeln("X-GENDER:%s" % (gender_value))
def write_birthdate(self, person):
"""Write the BDAY property of a VCard."""
birth_ref = person.get_birth_ref()

View File

@ -278,6 +278,10 @@ class VCardParser(object):
self.add_url(fields, line_parts[1])
elif property_name == "EMAIL":
self.add_email(fields, line_parts[1])
elif property_name == "X-GENDER" or property_name == "GENDER":
# VCard 3.0 only has X-GENDER, GENDER is 4.0 syntax,
# but we want to be robust here.
self.add_gender(fields, line_parts[1])
elif property_name == "PRODID":
# Included cause VCards made by Gramps have this prop.
pass
@ -509,3 +513,17 @@ class VCardParser(object):
url.set_type(UrlType(UrlType.EMAIL))
url.set_path(self.unesc(email))
self.person.add_url(url)
def add_gender(self, fields, data):
"""Read the GENDER property of a VCard."""
gender_value = data.strip()
if gender_value:
gender_value = gender_value.upper()
gender_value = gender_value[0]
if gender_value == 'M':
gender = gen.lib.Person.MALE
elif gender_value == 'F':
gender = gen.lib.Person.FEMALE
else:
return
self.person.set_gender(gender)