def update_filters_by_user_name(self, username,context=None, be_module_filter=False,be_page_filter=False): from gflux.apps.station.sql_utils import get_user_stations_by_name from gflux.apps.station.sql_utils import get_user_fuel_type_by_name from gflux.apps.station.sql_utils import get_user_none_fuel_type_by_name from gflux.apps.station.sql_utils import get_system_fuel_type from gflux.apps.station.sql_utils import locate_china_location_id_from_request from gflux.apps.station.sql_utils import get_china_location_name_by_id,getUserLocationInfo if username==None: return #print 'update filter '+self.label+' dash...' _full_filters=copy.deepcopy(self._full_filters) _filters=copy.deepcopy(self._filters) #standalone render for field in _full_filters : if field.field.name == 'site' : field.field.field.choices=get_user_stations_by_name(username) elif field.field.name == 'fuel_type': field.field.field.choices=[(0,_(u'任意'))]+get_user_fuel_type_by_name(username) elif field.field.name=='none_fuel_type': field.field.field.choices=[(0,_(u'任意'))]+get_user_none_fuel_type_by_name(username) elif field.field.name=='system_fuel_type': field.field.field.choices=[(0,_(u'任意'))]+get_system_fuel_type() elif field.field.name=='china_location': request=context['request'] ids=getUserLocationInfo(request) re_ids = [] for id in ids: re_ids.append((id,get_china_location_name_by_id(id))) field.field.field.choices=re_ids #none-standalone render for field in _filters : if field.field.name == 'site' : field.field.field.choices=get_user_stations_by_name(username) elif field.field.name == 'fuel_type': field.field.field.choices=[(0,_(u'任意'))]+get_user_fuel_type_by_name(username) elif field.field.name=='none_fuel_type': field.field.field.choices=[(0,_(u'任意'))]+get_user_none_fuel_type_by_name(username) elif field.field.name=='system_fuel_type': field.field.field.choices=[(0,_(u'任意'))]+get_system_fuel_type() elif field.field.name=='china_location': request=context['request'] ids=getUserLocationInfo(request) re_ids = [] for id in ids: re_ids.append((id,get_china_location_name_by_id(id))) field.field.field.choices=re_ids #更新filter if be_module_filter: self._full_filters=_full_filters self._filters=_filters if be_page_filter: context['dash_full_filters']=_full_filters context['dash_filters']=_filters
def update_form_filters_by_user_name(self, username,form,request): if username==None: return #print 'update form filter '+self.uid+' report...' for fieldname in form.fields.iterkeys(): field=form.fields[fieldname] if fieldname=='site': from gflux.apps.station.sql_utils import get_user_stations_by_name field.choices=get_user_stations_by_name(username) elif fieldname=='fuel_type': from gflux.apps.station.sql_utils import get_user_fuel_type_by_name field.choices=[(0,_(u'任意'))]+get_user_fuel_type_by_name(username) elif fieldname=='none_fuel_type': from gflux.apps.station.sql_utils import get_user_none_fuel_type_by_name field.choices=[(0,_(u'任意'))]+get_user_none_fuel_type_by_name(username) elif fieldname=='system_fuel_type': from gflux.apps.station.sql_utils import get_system_fuel_type field.choices=[(0,_(u'任意'))]+get_system_fuel_type() elif fieldname=='china_location': from gflux.apps.station.sql_utils import \ locate_china_location_id_from_request,get_china_location_name_by_id id=locate_china_location_id_from_request(request) field.choices=[(id,get_china_location_name_by_id(id))] elif fieldname == 'tag_choice' : from gflux.apps.station.sql_utils import get_tag_list field.choices=[(0,'请选择')] + get_tag_list(request)
def update_form_filters_by_user_name(self, username, form, request): if username == None: return #print 'update form filter '+self.uid+' report...' for fieldname in form.fields.iterkeys(): field = form.fields[fieldname] if fieldname == 'site': from gflux.apps.station.sql_utils import get_user_stations_by_name field.choices = get_user_stations_by_name(username) elif fieldname == 'fuel_type': from gflux.apps.station.sql_utils import get_user_fuel_type_by_name field.choices = [(0, _(u'任意')) ] + get_user_fuel_type_by_name(username) elif fieldname == 'none_fuel_type': from gflux.apps.station.sql_utils import get_user_none_fuel_type_by_name field.choices = [(0, _(u'任意')) ] + get_user_none_fuel_type_by_name(username) elif fieldname == 'system_fuel_type': from gflux.apps.station.sql_utils import get_system_fuel_type field.choices = [(0, _(u'任意'))] + get_system_fuel_type() elif fieldname == 'china_location': from gflux.apps.station.sql_utils import \ locate_china_location_id_from_request,get_china_location_name_by_id id = locate_china_location_id_from_request(request) field.choices = [(id, get_china_location_name_by_id(id))] elif fieldname == 'tag_choice': from gflux.apps.station.sql_utils import get_tag_list field.choices = [(0, '请选择')] + get_tag_list(request)