<s> from django . db import models <EOL> import datetime <EOL> import random <EOL> import hashlib <EOL> class LastFmUser ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> username = models . CharField ( max_length = <NUM_LIT:255> , unique = True ) <EOL> requested_update = models . DateTimeField ( blank = True , null = True ) <EOL> last_check = models . DateTimeField ( blank = True , null = True ) <EOL> external_until = models . DateTimeField ( blank = True , null = True ) <EOL> fetching = models . BooleanField ( default = False ) <EOL> def __unicode__ ( self ) : <EOL> return self . username <EOL> def get_absolute_url ( self ) : <EOL> return "<STR_LIT>" % self . username <EOL> def external_allowed ( self ) : <EOL> return True <EOL> @ classmethod <EOL> def by_username ( cls , username ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> return cls . objects . get ( username = username ) <EOL> except cls . DoesNotExist : <EOL> instance = cls ( username = username ) <EOL> instance . save ( ) <EOL> return instance <EOL> @ classmethod <EOL> def queue ( cls ) : <EOL> "<STR_LIT>" <EOL> return cls . objects . filter ( requested_update__isnull = False ) . order_by ( "<STR_LIT>" ) <EOL> class Poster ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> user = models . ForeignKey ( LastFmUser , related_name = "<STR_LIT>" ) <EOL> start = models . DateField ( ) <EOL> end = models . DateField ( ) <EOL> params = models . TextField ( blank = True ) <EOL> requested = models . DateTimeField ( blank = True , null = True ) <EOL> started = models . DateTimeField ( blank = True , null = True ) <EOL> completed = models . DateTimeField ( blank = True , null = True ) <EOL> failed = models . DateTimeField ( blank = True , null = True ) <EOL> expires = models . DateTimeField ( blank = True , null = True ) <EOL> email = models . TextField ( blank = True ) <EOL> error = models . TextField ( blank = True ) <EOL> node = models . ForeignKey ( "<STR_LIT>" , blank = True , null = True ) <EOL> pdf_url = models . TextField ( blank = True ) <EOL> svg_url = models . TextField ( blank = True ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . user , self . start , self . end ) <EOL> def queue_position ( self ) : <EOL> queue = list ( Poster . queue ( ) ) <EOL> try : <EOL> return queue . index ( self ) + <NUM_LIT:1> <EOL> except ( IndexError , ValueError ) : <EOL> return len ( queue ) + <NUM_LIT:1> <EOL> def status_string ( self ) : <EOL> if self . failed : <EOL> return "<STR_LIT>" <EOL> if self . requested : <EOL> if self . completed : <EOL> if self . pdf_url == "<STR_LIT>" : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> elif self . started : <EOL> return "<STR_LIT>" <EOL> return "<STR_LIT>" % self . queue_position ( ) <EOL> return "<STR_LIT>" <EOL> def expired ( self ) : <EOL> return self . completed and self . pdf_url == "<STR_LIT>" <EOL> def detail_string ( self ) : <EOL> detail = int ( self . params . split ( "<STR_LIT:|>" ) [ <NUM_LIT:1> ] ) <EOL> return { <EOL> <NUM_LIT:1> : "<STR_LIT>" , <EOL> <NUM_LIT:2> : "<STR_LIT>" , <EOL> <NUM_LIT:3> : "<STR_LIT>" , <EOL> <NUM_LIT:5> : "<STR_LIT>" , <EOL> <NUM_LIT:10> : "<STR_LIT>" , <EOL> <NUM_LIT:20> : "<STR_LIT>" , <EOL> <NUM_LIT:30> : "<STR_LIT>" , <EOL> } . get ( detail , detail ) <EOL> def colorscheme_string ( self ) : <EOL> return self . params . split ( "<STR_LIT:|>" ) [ <NUM_LIT:0> ] . title ( ) <EOL> def set_error ( self , error ) : <EOL> self . error = error <EOL> self . failed = datetime . datetime . utcnow ( ) <EOL> self . save ( ) <EOL> @ classmethod <EOL> def queue ( cls ) : <EOL> return cls . objects . filter ( requested__isnull = False , started__isnull = True , failed__isnull = True ) . order_by ( "<STR_LIT>" ) <EOL> class Node ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> nodename = models . CharField ( '<STR_LIT>' , max_length = <NUM_LIT:100> , unique = True ) <EOL> salt = models . CharField ( '<STR_LIT>' , max_length = <NUM_LIT:20> ) <EOL> hash = models . CharField ( '<STR_LIT>' , max_length = <NUM_LIT:100> ) <EOL> disabled = models . BooleanField ( default = False ) <EOL> lastseen = models . DateTimeField ( '<STR_LIT>' , null = True , blank = True , default = None ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % self . nodename <EOL> def set_password ( self , password ) : <EOL> self . salt = "<STR_LIT>" . join ( [ random . choice ( "<STR_LIT>" ) for i in range ( <NUM_LIT:8> ) ] ) <EOL> self . hash = hashlib . sha1 ( self . salt + password ) . hexdigest ( ) <EOL> def password_matches ( self , password ) : <EOL> return self . hash == hashlib . sha1 ( self . salt + password ) . hexdigest ( ) <EOL> @ classmethod <EOL> def recent ( cls ) : <EOL> return cls . objects . filter ( lastseen__gte = datetime . datetime . utcnow ( ) - datetime . timedelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) </s>
