def check_looupvalue(lookup_id, changevalues): from application.nutils.excel import safe_convert_unicode lookup_by_store_and_name = Lookup.get_description_by_store_id(lookup_id) description = lookup_by_store_and_name.description sections = LookupValue.find_all_by_lookup_id_by_order(lookup_id)[0] for changevalue in changevalues: value = changevalue['value'] if not value and not changevalue['orders'] and not changevalue[ 'section']: continue if not value: return u"此行%s必须有值" % description else: value = safe_convert_unicode(value) if LookupValue.find_value_in_lookupvalue_by_lookup_id_by_order_by_value( lookup_id, value): return u"%s已经存在" % value if not isinstance(changevalue['orders'], int): return u"次序必须是数值" if sections.section: if not changevalue['section']: return u"类别必须有值" else: if changevalue['section']: return u"类别必须为空"
def lookupvalues(): from application.forms.ops import LookupvalueForm from application.models.lookup import LookupValue selections = remove_empty_storename(get_stores_selection()) search_lookupvalue = LookupvalueForm(request.args) search_lookupvalue.store_filter.choices = selections lookup_id = request.args.get('lookup_filter', None) descriptions = get_stores_descriptions_and_lookupvalues(lookup_id) if search_lookupvalue.store_filter.data and search_lookupvalue.store_filter.data not in ('None', 'all'): store_id = search_lookupvalue.store_filter.data store_name = Store.find_storename_by_store_id(store_id).name from application.models.lookup import Lookup id_and_description = Lookup.get_descriptions_by_store_id(store_id) search_lookupvalue.lookup_filter.choices = [(lookup.id, lookup.description) for lookup in id_and_description] else: store_id = '' store_name = '' search_lookupvalue.lookup_filter.choices = {} if lookup_id and lookup_id is not None: lookupvalueslist = LookupValue.find_all_by_lookup_id_by_order(lookup_id) else: lookupvalueslist = [] return render_template('ops/lookupvalue.html', selected_menu=LOOKUPVALUE_MGMT_SUMMARY, form=search_lookupvalue, lookupvalues=lookupvalueslist, descriptions=descriptions, storename=store_name, lookup_id=lookup_id, store_id=store_id)