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

port from gramps34

svn: r22763
This commit is contained in:
Vassilii Khachaturov 2013-07-29 08:53:08 +00:00
parent a9cad8c0d2
commit 056d82895e
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.gui.plug.export import WriterOptionBox
from gramps.gen.const import PROGRAM_NAME from gramps.gen.const import PROGRAM_NAME
from gramps.version import VERSION 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.urltype import UrlType
from gramps.gen.lib.eventtype import EventType from gramps.gen.lib.eventtype import EventType
from gramps.gen.display.name import displayer as _nd from gramps.gen.display.name import displayer as _nd
@ -171,6 +171,7 @@ class VCardWriter(object):
self.write_name(prname) self.write_name(prname)
self.write_sortstring(prname) self.write_sortstring(prname)
self.write_nicknames(person, prname) self.write_nicknames(person, prname)
self.write_gender(person)
self.write_birthdate(person) self.write_birthdate(person)
self.write_addresses(person) self.write_addresses(person)
self.write_urls(person) self.write_urls(person)
@ -252,6 +253,18 @@ class VCardWriter(object):
if len(nicknames) > 0: if len(nicknames) > 0:
self.writeln("NICKNAME:%s" % (','.join(self.esc(nicknames)))) 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): def write_birthdate(self, person):
"""Write the BDAY property of a VCard.""" """Write the BDAY property of a VCard."""
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()

View File

@ -278,6 +278,10 @@ class VCardParser(object):
self.add_url(fields, line_parts[1]) self.add_url(fields, line_parts[1])
elif property_name == "EMAIL": elif property_name == "EMAIL":
self.add_email(fields, line_parts[1]) 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": elif property_name == "PRODID":
# Included cause VCards made by Gramps have this prop. # Included cause VCards made by Gramps have this prop.
pass pass
@ -509,3 +513,17 @@ class VCardParser(object):
url.set_type(UrlType(UrlType.EMAIL)) url.set_type(UrlType(UrlType.EMAIL))
url.set_path(self.unesc(email)) url.set_path(self.unesc(email))
self.person.add_url(url) 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)