def generate_lookupvalue(lookup_ids, lookupvalues_data): ''' 1: copy age-group appt-type last-instore on lookupvalue 2: insert intent-car test-drive-car intent-color intent-level channel on lookupvalue ''' from application.models.base import db lookupvalue_age_groups = _age_groups(lookup_id=11) lookupvalue_appt_type = _age_groups(lookup_id=17) lookupvalue_last_instore = _age_groups(lookup_id=18) try: for copy_lookupvalue in [ lookupvalue_age_groups, lookupvalue_appt_type, lookupvalue_last_instore ]: for lookup_name, code, value, order in copy_lookupvalue: lookupvalue = LookupValue.create( code=code, value=value, lookup_id=lookup_ids[lookup_name], parent_id='-1', order=order, section=None, version='1') if lookupvalue is not None: db.session.add(lookupvalue) db.session.commit() except Exception as e: raise e try: for lookup_name_key in lookupvalues_data: order_count = 10 for code, value, section in lookupvalues_data[lookup_name_key]: lookupvalue = LookupValue.create( code=code, value=value, lookup_id=lookup_ids[lookup_name_key], parent_id='-1', order=order_count, section=section, version='1') if lookupvalue is not None: db.session.add(lookupvalue) order_count += 10 db.session.commit() except Exception as e: raise e return True
def add_lookupvalue(lookup_id, version, changevalues): from application.models.base import db from application.nutils.excel import convert_value_to_code, safe_convert_unicode count = 0 try: for changevalue in changevalues: if not changevalue['value'] and not changevalue['orders']: continue lookupvalue = LookupValue.create( code=convert_value_to_code( safe_convert_unicode(changevalue['value'])), value=safe_convert_unicode(changevalue['value']), lookup_id=lookup_id, parent_id='-1', order=safe_convert_unicode(changevalue['orders']), section=safe_convert_unicode(changevalue['section']), version=version, ) db.session.add(lookupvalue) count += 1 db.session.commit() except Exception as e: raise e if count == 0: return count try: Lookup.update_version(lookup_id, version) LookupValue.update_version(lookup_id, version) db.session.commit() except Exception as e: raise e return count