<s> from django . utils . translation import ugettext_noop as _ <EOL> from haystack import indexes <EOL> from packages . models import Package <EOL> from search . indexes import PackageCelerySearchIndex <EOL> LICENSES = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : _ ( "<STR_LIT>" ) , <EOL> } <EOL> class PackageIndex ( PackageCelerySearchIndex , indexes . Indexable ) : <EOL> text = indexes . CharField ( document = True , use_template = True ) <EOL> name = indexes . CharField ( model_attr = "<STR_LIT:name>" , boost = <NUM_LIT> ) <EOL> summary = indexes . CharField ( null = True ) <EOL> description = indexes . CharField ( null = True ) <EOL> author = indexes . CharField ( null = True ) <EOL> maintainer = indexes . CharField ( null = True ) <EOL> downloads = indexes . IntegerField ( model_attr = "<STR_LIT>" , indexed = False ) <EOL> url = indexes . CharField ( model_attr = "<STR_LIT>" , indexed = False ) <EOL> operating_systems = indexes . MultiValueField ( null = True , faceted = True , facet_class = indexes . FacetMultiValueField ) <EOL> licenses = indexes . MultiValueField ( null = True , faceted = True , facet_class = indexes . FacetMultiValueField ) <EOL> implementations = indexes . MultiValueField ( null = True , faceted = True , facet_class = indexes . FacetMultiValueField ) <EOL> python_versions = indexes . MultiValueField ( null = True , faceted = True , facet_class = indexes . FacetMultiValueField ) <EOL> versions = indexes . MultiValueField ( null = True ) <EOL> release_count = indexes . IntegerField ( default = <NUM_LIT:0> ) <EOL> def get_model ( self ) : <EOL> return Package <EOL> def prepare ( self , obj ) : <EOL> data = super ( PackageIndex , self ) . prepare ( obj ) <EOL> if '<STR_LIT:_>' in data [ '<STR_LIT:name>' ] : <EOL> data [ '<STR_LIT:name>' ] += '<STR_LIT:U+0020>' + data [ '<STR_LIT:name>' ] . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if obj . latest : <EOL> data [ "<STR_LIT>" ] = obj . latest . summary <EOL> data [ "<STR_LIT>" ] = obj . latest . author if obj . latest . author else None <EOL> data [ "<STR_LIT>" ] = obj . latest . maintainer if obj . latest . maintainer else None <EOL> data [ "<STR_LIT:description>" ] = obj . latest . description if obj . latest . description else None <EOL> operating_systems = [ ] <EOL> licenses = [ ] <EOL> implementations = [ ] <EOL> python_versions = [ ] <EOL> for classifier in obj . latest . classifiers . all ( ) : <EOL> if classifier . trove . startswith ( "<STR_LIT>" ) : <EOL> licenses . append ( classifier . trove . rsplit ( "<STR_LIT>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) ) <EOL> elif classifier . trove . startswith ( "<STR_LIT>" ) : <EOL> operating_systems . append ( classifier . trove . rsplit ( "<STR_LIT>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) ) <EOL> elif classifier . trove . startswith ( "<STR_LIT>" ) : <EOL> implementations . append ( classifier . trove . rsplit ( "<STR_LIT>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) ) <EOL> elif classifier . trove . startswith ( "<STR_LIT>" ) : <EOL> if classifier . trove == "<STR_LIT>" : <EOL> python_versions . append ( "<STR_LIT>" ) <EOL> elif classifier . trove . startswith ( "<STR_LIT>" ) : <EOL> python_versions . append ( "<STR_LIT>" ) <EOL> elif classifier . trove . startswith ( "<STR_LIT>" ) : <EOL> python_versions . append ( "<STR_LIT>" ) <EOL> else : <EOL> python_versions . append ( classifier . trove . rsplit ( "<STR_LIT>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) ) <EOL> if not licenses : <EOL> licenses = [ _ ( "<STR_LIT>" ) ] <EOL> licenses = [ x for x in licenses if x not in [ "<STR_LIT>" ] ] <EOL> licenses = [ LICENSES . get ( x , x ) for x in licenses ] <EOL> data [ "<STR_LIT>" ] = licenses <EOL> if not operating_systems : <EOL> operating_systems = [ _ ( "<STR_LIT>" ) ] <EOL> data [ "<STR_LIT>" ] = operating_systems <EOL> if not implementations : <EOL> implementations = [ _ ( "<STR_LIT>" ) ] <EOL> data [ "<STR_LIT>" ] = implementations <EOL> if not python_versions : <EOL> python_versions = [ _ ( "<STR_LIT>" ) ] <EOL> data [ "<STR_LIT>" ] = python_versions <EOL> releases = obj . releases . all ( ) . order_by ( "<STR_LIT>" ) <EOL> data [ "<STR_LIT>" ] = [ release . version for release in releases if release . version ] <EOL> data [ "<STR_LIT>" ] = releases . count ( ) <EOL> capped_downloads = min ( data [ "<STR_LIT>" ] , <NUM_LIT> ) <EOL> boost = capped_downloads / <NUM_LIT> <EOL> data [ "<STR_LIT>" ] = <NUM_LIT:1.0> + boost <EOL> return data </s>
