def deserialize_institution(data, persistent=False): """ Transforms data (as JSON string or a dict) to an institution """ if not data: return None if not persistent: pass # TODO if necessary else: from repository.models import Institution from vocabulary.models import CountryCode, InstitutionType if isinstance(data, basestring): data = DictKeyAttribute(simplejson.loads(data)) elif isinstance(data, dict): data = DictKeyAttribute(data) try: institution = Institution.objects.get(pk=data.pk) except Institution.DoesNotExist: institution = Institution() institution.id = data.pk institution.name = data.name institution.address = data.address institution.country = deserialize_vocabulary(data.country, True, CountryCode) institution.creator = deserialize_user(data.creator, True) institution.i_type = deserialize_vocabulary(data.i_type, True, InstitutionType) institution.save() return institution
def deserialize_institution(data, persistent=False): """ Transforms data (as JSON string or a dict) to an institution """ if not data: return None if not persistent: pass # TODO if necessary else: from repository.models import Institution from vocabulary.models import CountryCode, InstitutionType if isinstance(data, basestring): data = DictKeyAttribute(simplejson.loads(data)) elif isinstance(data, dict): data = DictKeyAttribute(data) try: institution = Institution.objects.get(pk=data.pk) except Institution.DoesNotExist: institution = Institution() institution.id = data.pk institution.name = data.name institution.address = data.address institution.country = deserialize_vocabulary( data.country, True, CountryCode) institution.creator = deserialize_user(data.creator, True) institution.i_type = deserialize_vocabulary( data.i_type, True, InstitutionType) institution.save() return institution