class Person(object): """ Person model """ education = [] work_experience = [] firstname = "" lastname = "" birthdate = "" birthplace = "" contacts = [] def __init__(self, data): self.__initialization(data) def __initialization(self, data): if data is None: raise Exception("Data is invalid") self.firstname = data.get('firstname', None) self.lastname = data.get(u'lastname', None) self.birthdate = data.get('birthdate', None) birthplace = data.get('birthplace', None) if birthplace is not None: self.birthplace = Place(birthplace) employers = data.get('work_experience', []) if isinstance(employers, list): for employer in employers: self.work_experience.append( Employer(employer) ) degrees = data.get('education', []) if isinstance(degrees, list): for degree in degrees: self.education.append(Degree(degree)) contacts = data.get('contacts', []) if isinstance(contacts, list): for contact in contacts: self.contacts.append(Contact.get_instance(contact)) def to_json(self): return { "firstname": self.firstname, "lastname": self.lastname, "birth":{ "date": self.birthdate, "place": self.birthplace.to_json() }, 'education': [degree.to_json() for degree in self.education], 'work_experience': [employer.to_json() for employer in self.work_experience], 'contacts': [contact.to_json() for contact in self.contacts] }
class Employer(object): """ Employer model that represents a real work experience """ from_date = "" to_date = "" place = None summary = "", name = "" title = "" sector = "", keywords = [] def __init__(self, data): self.name = data.get('name', None) self.title = data.get('title', None) self.sector = data.get('sector', None) self.from_date = data.get('from_date', None) self.to_date = data.get('to_date', None) self.summary = data.get('summary', None) keywords = data.get('keywords', []) if not isinstance(keywords, list): keywords = [] self.keywords = keywords place = data.get('place', None) if place is not None: self.place = Place(place) def to_json(self): return { 'name': self.name, 'title': self.title, 'sector': self.sector, 'from_date': self.from_date, 'to_date': self.to_date, 'summary': self.summary, 'keywords': self.keywords, 'place': self.place.to_json() if not self.place is None else None }