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_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_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 from gflux.apps.station.sql_utils import getUserTags if username==None: return #print 'update filter '+self.label+' page...' _filters=copy.deepcopy(self._filters) if len(_filters)>0 and _filters[0].field.name == 'tag_choice' : temp_list = [_filters[1],_filters[0],_filters[2],_filters[3],_filters[4],_filters[5]] _filters = temp_list 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=='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 elif field.field.name == 'tag': tags = getUserTags(username) field.field.field.choices=tags #更新filter if be_module_filter: self._filters=_filters if be_page_filter: context['page_filters']=_filters