<s> import urllib <EOL> import urlparse <EOL> from django . conf import settings <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes import generic <EOL> from django . db import models <EOL> from django . utils import simplejson , text <EOL> from django . utils . encoding import smart_unicode <EOL> from jellyroll . managers import ItemManager <EOL> from tagging . fields import TagField <EOL> class Item ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> content_type = models . ForeignKey ( ContentType ) <EOL> object_id = models . TextField ( ) <EOL> object = generic . GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> url = models . URLField ( blank = True , max_length = <NUM_LIT:1000> ) <EOL> timestamp = models . DateTimeField ( ) <EOL> tags = TagField ( max_length = <NUM_LIT> ) <EOL> source = models . CharField ( max_length = <NUM_LIT:100> , blank = True ) <EOL> source_id = models . TextField ( blank = True ) <EOL> object_str = models . TextField ( blank = True ) <EOL> objects = ItemManager ( ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> unique_together = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . content_type . model_class ( ) . __name__ , self . object_str ) <EOL> def __cmp__ ( self , other ) : <EOL> return cmp ( self . timestamp , other . timestamp ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> ct = "<STR_LIT>" % ( self . content_type . app_label , self . content_type . model . lower ( ) ) <EOL> self . object_str = smart_unicode ( self . object ) <EOL> super ( Item , self ) . save ( * args , ** kwargs ) <EOL> class Bookmark ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> url = models . URLField ( unique = True , max_length = <NUM_LIT:1000> ) <EOL> description = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> extended = models . TextField ( blank = True ) <EOL> thumbnail = models . ImageField ( upload_to = "<STR_LIT>" , blank = True ) <EOL> thumbnail_url = models . URLField ( blank = True , verify_exists = False , max_length = <NUM_LIT:1000> ) <EOL> def __unicode__ ( self ) : <EOL> return self . url <EOL> class Track ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> artist_name = models . CharField ( max_length = <NUM_LIT> ) <EOL> track_name = models . CharField ( max_length = <NUM_LIT> ) <EOL> url = models . URLField ( blank = True , max_length = <NUM_LIT:1000> ) <EOL> track_mbid = models . CharField ( "<STR_LIT>" , max_length = <NUM_LIT> , blank = True ) <EOL> artist_mbid = models . CharField ( "<STR_LIT>" , max_length = <NUM_LIT> , blank = True ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . artist_name , self . track_name ) <EOL> CC_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 Photo ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> photo_id = models . CharField ( unique = True , primary_key = True , max_length = <NUM_LIT:50> ) <EOL> farm_id = models . PositiveSmallIntegerField ( null = True ) <EOL> server_id = models . PositiveSmallIntegerField ( ) <EOL> secret = models . CharField ( max_length = <NUM_LIT:30> , blank = True ) <EOL> taken_by = models . CharField ( max_length = <NUM_LIT:100> , blank = True ) <EOL> cc_license = models . URLField ( blank = True , choices = CC_LICENSES ) <EOL> title = models . CharField ( max_length = <NUM_LIT> ) <EOL> description = models . TextField ( blank = True ) <EOL> comment_count = models . PositiveIntegerField ( max_length = <NUM_LIT:5> , default = <NUM_LIT:0> ) <EOL> date_uploaded = models . DateTimeField ( blank = True , null = True ) <EOL> date_updated = models . DateTimeField ( blank = True , null = True ) <EOL> _exif = models . TextField ( blank = True ) <EOL> def _set_exif ( self , d ) : <EOL> self . _exif = simplejson . dumps ( d ) <EOL> def _get_exif ( self ) : <EOL> if self . _exif : <EOL> return simplejson . loads ( self . _exif ) <EOL> else : <EOL> return { } <EOL> exif = property ( _get_exif , _set_exif , "<STR_LIT>" ) <EOL> def _get_farm ( self ) : <EOL> if self . farm_id : <EOL> return '<STR_LIT>' . join ( [ "<STR_LIT>" , str ( self . farm_id ) , "<STR_LIT:.>" ] ) <EOL> return '<STR_LIT>' <EOL> farm = property ( _get_farm ) <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> def url ( self ) : <EOL> return "<STR_LIT>" % ( self . taken_by , self . photo_id ) <EOL> url = property ( url ) <EOL> def timestamp ( self ) : <EOL> return self . date_uploaded <EOL> timestamp = property ( timestamp ) <EOL> def get_image_url ( self , size = None ) : <EOL> if size in list ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" % ( self . farm , self . server_id , self . photo_id , self . secret , size ) <EOL> else : <EOL> return "<STR_LIT>" % ( self . farm , self . server_id , self . photo_id , self . secret ) <EOL> image_url = property ( lambda self : self . get_image_url ( ) ) <EOL> square_url = property ( lambda self : self . get_image_url ( '<STR_LIT:s>' ) ) <EOL> thumbnail_url = property ( lambda self : self . get_image_url ( '<STR_LIT:t>' ) ) <EOL> small_url = property ( lambda self : self . get_image_url ( '<STR_LIT:m>' ) ) <EOL> large_url = property ( lambda self : self . get_image_url ( '<STR_LIT:b>' ) ) <EOL> original_url = property ( lambda self : self . get_image_url ( '<STR_LIT:o>' ) ) <EOL> def license_code ( self ) : <EOL> if not self . cc_license : <EOL> return None <EOL> path = urlparse . urlparse ( self . cc_license ) [ <NUM_LIT:2> ] <EOL> return path . split ( "<STR_LIT:/>" ) [ <NUM_LIT:2> ] <EOL> license_code = property ( license_code ) <EOL> def taken_by_me ( self ) : <EOL> return self . taken_by == getattr ( settings , "<STR_LIT>" , "<STR_LIT>" ) <EOL> taken_by_me = property ( taken_by_me ) <EOL> def can_republish ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . taken_by_me : <EOL> return True <EOL> elif self . license_code is None : <EOL> return False <EOL> elif getattr ( settings , "<STR_LIT>" , False ) and "<STR_LIT>" in self . license_code : <EOL> return False <EOL> else : <EOL> return True <EOL> can_republish = property ( can_republish ) <EOL> def derivative_ok ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . can_republish and "<STR_LIT>" not in self . license_code <EOL> derivative_ok = property ( derivative_ok ) <EOL> def must_share_alike ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . can_republish and "<STR_LIT>" in self . license_code <EOL> must_share_alike = property ( must_share_alike ) <EOL> class SearchEngine ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:200> ) <EOL> home = models . URLField ( ) <EOL> search_template = models . URLField ( ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class WebSearch ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> engine = models . ForeignKey ( SearchEngine , related_name = "<STR_LIT>" ) <EOL> query = models . CharField ( max_length = <NUM_LIT> ) <EOL> class Meta : <EOL> verbose_name_plural = "<STR_LIT>" <EOL> def __unicode__ ( self ) : <EOL> return self . query <EOL> def url ( self ) : <EOL> return self . engine . search_template % ( urllib . quote_plus ( self . query ) ) <EOL> url = property ( url ) <EOL> class WebSearchResult ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> search = models . ForeignKey ( WebSearch , related_name = "<STR_LIT>" ) <EOL> title = models . CharField ( max_length = <NUM_LIT> ) <EOL> url = models . URLField ( ) <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> class VideoSource ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:200> ) <EOL> home = models . URLField ( ) <EOL> embed_template = models . URLField ( ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class Video ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> source = models . ForeignKey ( VideoSource , related_name = "<STR_LIT>" ) <EOL> title = models . CharField ( max_length = <NUM_LIT> ) <EOL> url = models . URLField ( ) <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> def docid ( self ) : <EOL> scheme , netloc , path , params , query , fragment = urlparse . urlparse ( self . url ) <EOL> return query . split ( "<STR_LIT:=>" ) [ - <NUM_LIT:1> ] <EOL> docid = property ( docid ) <EOL> def embed_url ( self ) : <EOL> return self . source . embed_template % self . docid <EOL> embed_url = property ( embed_url ) <EOL> SCM_CHOICES = ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ) <EOL> class CodeRepository ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> type = models . CharField ( max_length = <NUM_LIT:10> , choices = SCM_CHOICES ) <EOL> name = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> slug = models . SlugField ( ) <EOL> username = models . CharField ( max_length = <NUM_LIT:100> , help_text = "<STR_LIT>" ) <EOL> public_changeset_template = models . URLField ( <EOL> verify_exists = False , blank = True , <EOL> help_text = "<STR_LIT>" ) <EOL> url = models . URLField ( ) <EOL> class Meta : <EOL> verbose_name_plural = "<STR_LIT>" <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class CodeCommit ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> repository = models . ForeignKey ( CodeRepository , related_name = "<STR_LIT>" ) <EOL> revision = models . CharField ( max_length = <NUM_LIT:200> ) <EOL> message = models . TextField ( ) <EOL> class Meta : <EOL> ordering = [ "<STR_LIT>" ] <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . format_revision ( ) , text . truncate_words ( self . message , <NUM_LIT:10> ) ) <EOL> def format_revision ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return str ( int ( self . revision ) ) <EOL> except ValueError : <EOL> return self . revision [ : <NUM_LIT:7> ] <EOL> @ property <EOL> def url ( self ) : <EOL> if self . repository . public_changeset_template : <EOL> return self . repository . public_changeset_template % self . revision <EOL> return "<STR_LIT>" <EOL> class Message ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> message = models . TextField ( ) <EOL> links = models . ManyToManyField ( '<STR_LIT>' , blank = True , null = True ) <EOL> def __unicode__ ( self ) : <EOL> return text . truncate_words ( self . message , <NUM_LIT:30> ) <EOL> class ContentLink ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> url = models . URLField ( ) <EOL> identifier = models . CharField ( max_length = <NUM_LIT> ) <EOL> def __unicode__ ( self ) : <EOL> return self . identifier <EOL> class Location ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> latitude = models . DecimalField ( max_digits = <NUM_LIT:10> , decimal_places = <NUM_LIT:6> ) <EOL> longitude = models . DecimalField ( max_digits = <NUM_LIT:10> , decimal_places = <NUM_LIT:6> ) <EOL> name = models . CharField ( max_length = <NUM_LIT:200> , blank = True ) <EOL> def __unicode__ ( self ) : <EOL> if self . name : <EOL> return self . name <EOL> else : <EOL> return "<STR_LIT>" % ( self . longitude , self . latitude ) <EOL> @ property <EOL> def url ( self ) : <EOL> return "<STR_LIT>" % ( self . longitude , self . latitude ) <EOL> Item . objects . follow_model ( Bookmark ) <EOL> Item . objects . follow_model ( Track ) <EOL> Item . objects . follow_model ( Photo ) <EOL> Item . objects . follow_model ( WebSearch ) <EOL> Item . objects . follow_model ( Video ) <EOL> Item . objects . follow_model ( CodeCommit ) <EOL> Item . objects . follow_model ( Message ) <EOL> Item . objects . follow_model ( Location ) </s>
