def after_update(self, context, pkg_dict): #if not custom.custom_field_table.exists(): # custom.init_db() # During the harvest the get_lang() is not defined if get_lang(): lang = get_lang()[0] for extra in pkg_dict.get('extras'): for field in self.custom_fields: if extra.get('key') == field[0]: log.info(':::::::::::::::Localizing custom field: %r', field[0]) f = custom.get_field(extra.get('key'), pkg_dict.get('id'), lang) if f: if extra.get('value') == '': f.purge() elif f.text != extra.get('value'): # Update the localized field value for the current language f.text = extra.get('value') f.save() log.info('Custom field updated successfully') elif extra.get('value') != '': # Create the localized field record self.createLocField(extra, lang, pkg_dict.get('id'))
def getLocalizedFieldValue(field=None, pkg_dict=None): if field and pkg_dict: lang = get_lang()[0] localized_value = custom.get_field(field, pkg_dict.get('id'), lang) if localized_value: return localized_value.text else: return None else: return None
def after_import_stage(self, package_dict): for cls in PBZHarvester.__bases__: c = cls() if hasattr(c, '_package_dict'): c._package_dict = self._package_dict c.after_import_stage(package_dict) package_id = package_dict.get('id') log.debug( "::::::::::::: Persisting localized Author package field :::::::::::::" ) try: ## PERSISTING the 'author' standard field localized ## ------------------------------------------------ session = Session rows = session.query(PackageMultilang).filter( PackageMultilang.package_id == package_id, PackageMultilang.field == 'author').all() if not rows: log.info( '::::::::: Adding new localized organization author in the package_multilang table :::::::::' ) log.debug( '::::: Persisting organization author metadata locale :::::' ) for org in self.localized_org: session.add_all([ PackageMultilang(package_id=package_id, field='author', field_type='localized', lang=org.get('locale'), text=org.get('text')), ]) session.commit() log.info('::::::::: OBJECT PERSISTED SUCCESSFULLY :::::::::') else: log.info( '::::::::: Updating localized organization author in the package_multilang table :::::::::' ) for row in rows: if row.field == 'author': for org in self.localized_org: if org.get('locale') == row.lang: row.text = org.get('text') row.save() log.info('::::::::: OBJECT UPDATED SUCCESSFULLY :::::::::') ## PERSISTING the 'holder' custom field localized ## ---------------------------------------------- for org in self.localized_org: record = custom.get_field('holder', package_id, org.get('locale')) if record: log.info( '::::::::: Updating the localized holder custom field in the custom_field table :::::::::' ) record.text = org.get('text') record.save() log.info( '::::::::: CUSTOM OBJECT UPDATED SUCCESSFULLY :::::::::' ) else: log.info( '::::::::: Adding new localized holder custom field in the custom_field table :::::::::' ) # This for the holder custom field new_holder_loc_field = custom.CustomFieldMultilang( package_id, 'holder', org.get('locale'), org.get('text')) custom.CustomFieldMultilang.save(new_holder_loc_field) log.info( '::::::::: CUSTOM OBJECT PERSISTED SUCCESSFULLY :::::::::' ) pass except Exception, e: # on rollback, the same closure of state # as that of commit proceeds. session.rollback() log.error('Exception occurred while persisting DB objects: %s', e) raise
def after_import_stage(self, package_dict): for cls in PBZHarvester.__bases__: c = cls() if hasattr(c, "_package_dict"): c._package_dict = self._package_dict c.after_import_stage(package_dict) package_id = package_dict.get("id") log.debug("::::::::::::: Persisting localized Author package field :::::::::::::") try: ## PERSISTING the 'author' standard field localized ## ------------------------------------------------ session = Session rows = ( session.query(PackageMultilang) .filter(PackageMultilang.package_id == package_id, PackageMultilang.field == "author") .all() ) if not rows: log.info("::::::::: Adding new localized organization author in the package_multilang table :::::::::") log.debug("::::: Persisting organization author metadata locale :::::") for org in self.localized_org: session.add_all( [ PackageMultilang( package_id=package_id, field="author", field_type="localized", lang=org.get("locale"), text=org.get("text"), ) ] ) session.commit() log.info("::::::::: OBJECT PERSISTED SUCCESSFULLY :::::::::") else: log.info("::::::::: Updating localized organization author in the package_multilang table :::::::::") for row in rows: if row.field == "author": for org in self.localized_org: if org.get("locale") == row.lang: row.text = org.get("text") row.save() log.info("::::::::: OBJECT UPDATED SUCCESSFULLY :::::::::") ## PERSISTING the 'holder' custom field localized ## ---------------------------------------------- for org in self.localized_org: record = custom.get_field("holder", package_id, org.get("locale")) if record: log.info("::::::::: Updating the localized holder custom field in the custom_field table :::::::::") record.text = org.get("text") record.save() log.info("::::::::: CUSTOM OBJECT UPDATED SUCCESSFULLY :::::::::") else: log.info("::::::::: Adding new localized holder custom field in the custom_field table :::::::::") # This for the holder custom field new_holder_loc_field = custom.CustomFieldMultilang( package_id, "holder", org.get("locale"), org.get("text") ) custom.CustomFieldMultilang.save(new_holder_loc_field) log.info("::::::::: CUSTOM OBJECT PERSISTED SUCCESSFULLY :::::::::") pass except Exception, e: # on rollback, the same closure of state # as that of commit proceeds. session.rollback() log.error("Exception occurred while persisting DB objects: %s", e) raise