<s> from __future__ import absolute_import <EOL> from sentry . api . serializers import Serializer , register <EOL> from sentry . models import SavedSearch , SavedSearchUserDefault <EOL> @ register ( SavedSearch ) <EOL> class SavedSearchSerializer ( Serializer ) : <EOL> def get_attrs ( self , item_list , user ) : <EOL> if user . is_authenticated ( ) : <EOL> user_defaults = tuple ( SavedSearchUserDefault . objects . filter ( <EOL> savedsearch__in = item_list , <EOL> user = user , <EOL> ) . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> else : <EOL> user_defaults = ( ) <EOL> attrs = { } <EOL> for item in item_list : <EOL> attrs [ item ] = { <EOL> '<STR_LIT>' : item . id in user_defaults , <EOL> } <EOL> return attrs <EOL> def serialize ( self , obj , attrs , user ) : <EOL> return { <EOL> '<STR_LIT:id>' : str ( obj . id ) , <EOL> '<STR_LIT:name>' : obj . name , <EOL> '<STR_LIT>' : obj . query , <EOL> '<STR_LIT>' : obj . is_default , <EOL> '<STR_LIT>' : attrs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : obj . date_added , <EOL> } </s>
