<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import json <EOL> from django . db import models <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . utils . functional import cached_property <EOL> try : <EOL> from django . contrib . contenttypes . fields import GenericForeignKey <EOL> except ImportError : <EOL> from django . contrib . contenttypes . generic import GenericForeignKey <EOL> def has_int_pk ( model ) : <EOL> """<STR_LIT>""" <EOL> pk = model . _meta . pk <EOL> return ( <EOL> ( <EOL> isinstance ( pk , ( models . IntegerField , models . AutoField ) ) and <EOL> not isinstance ( pk , models . BigIntegerField ) <EOL> ) or ( <EOL> isinstance ( pk , models . ForeignKey ) and has_int_pk ( pk . rel . to ) <EOL> ) <EOL> ) <EOL> META_CACHE_KEY = "<STR_LIT>" <EOL> class SearchEntry ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> engine_slug = models . CharField ( <EOL> max_length = <NUM_LIT:200> , <EOL> db_index = True , <EOL> default = "<STR_LIT:default>" , <EOL> ) <EOL> content_type = models . ForeignKey ( <EOL> ContentType , <EOL> ) <EOL> object_id = models . TextField ( ) <EOL> object_id_int = models . IntegerField ( <EOL> blank = True , <EOL> null = True , <EOL> db_index = True , <EOL> ) <EOL> object = GenericForeignKey ( ) <EOL> title = models . CharField ( <EOL> max_length = <NUM_LIT:1000> , <EOL> ) <EOL> description = models . TextField ( <EOL> blank = True , <EOL> ) <EOL> content = models . TextField ( <EOL> blank = True , <EOL> ) <EOL> url = models . CharField ( <EOL> max_length = <NUM_LIT:1000> , <EOL> blank = True , <EOL> ) <EOL> meta_encoded = models . TextField ( ) <EOL> def _deserialize_meta ( self ) : <EOL> from watson . search import SearchEngine <EOL> engine = SearchEngine . _created_engines [ self . engine_slug ] <EOL> model = ContentType . objects . get_for_id ( self . content_type_id ) . model_class ( ) <EOL> adapter = engine . get_adapter ( model ) <EOL> return adapter . deserialize_meta ( self . meta_encoded ) <EOL> @ cached_property <EOL> def meta ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , META_CACHE_KEY ) : <EOL> return getattr ( self , META_CACHE_KEY ) <EOL> meta_value = self . _deserialize_meta ( ) <EOL> setattr ( self , META_CACHE_KEY , meta_value ) <EOL> return meta_value <EOL> def get_absolute_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . url <EOL> def __unicode__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . title <EOL> class Meta : <EOL> verbose_name_plural = "<STR_LIT>" <EOL> app_label = '<STR_LIT>' </s>
