<s> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import models <EOL> from django . template . defaultfilters import truncatechars <EOL> from django . utils . text import Truncator <EOL> from accounts . models import MyUser <EOL> from videos . models import Video <EOL> class CommentManager ( models . Manager ) : <EOL> def all ( self ) : <EOL> return super ( CommentManager , self ) . filter ( active = True ) . filter ( parent = None ) <EOL> def recent ( self ) : <EOL> try : <EOL> limit_to = settings . RECENT_COMMENT_NUMBER <EOL> except : <EOL> limit_to = <NUM_LIT:6> <EOL> return self . get_queryset ( ) . filter ( active = True ) . filter ( parent = None ) [ : limit_to ] <EOL> def create_comment ( self , user = None , text = None , path = None , video = None , parent = None ) : <EOL> if not path : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not user : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> comment = self . model ( <EOL> user = user , <EOL> path = path , <EOL> text = text <EOL> ) <EOL> if video is not None : <EOL> comment . video = video <EOL> if parent is not None : <EOL> comment . parent = parent <EOL> comment . save ( using = self . _db ) <EOL> return comment <EOL> class Comment ( models . Model ) : <EOL> user = models . ForeignKey ( MyUser ) <EOL> parent = models . ForeignKey ( "<STR_LIT>" , null = True , blank = True ) <EOL> path = models . CharField ( max_length = <NUM_LIT> ) <EOL> video = models . ForeignKey ( Video , null = True , blank = True ) <EOL> text = models . TextField ( ) <EOL> updated = models . DateTimeField ( auto_now = True , auto_now_add = False ) <EOL> timestamp = models . DateTimeField ( auto_now = False , auto_now_add = True ) <EOL> active = models . BooleanField ( default = True ) <EOL> objects = CommentManager ( ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> def __unicode__ ( self ) : <EOL> return self . text <EOL> def get_absolute_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , kwargs = { "<STR_LIT:id>" : self . id } ) <EOL> @ property <EOL> def get_origin ( self ) : <EOL> return self . path <EOL> @ property <EOL> def get_preview ( self ) : <EOL> return Truncator ( self . text ) . chars ( <NUM_LIT> ) <EOL> @ property <EOL> def get_comment ( self ) : <EOL> return self . text <EOL> @ property <EOL> def is_child ( self ) : <EOL> if self . parent is not None : <EOL> return True <EOL> else : <EOL> return False <EOL> def get_children ( self ) : <EOL> if self . is_child : <EOL> return None <EOL> else : <EOL> return Comment . objects . filter ( parent = self ) <EOL> def get_affected_users ( self ) : <EOL> """<STR_LIT>""" <EOL> comment_children = self . get_children ( ) <EOL> if comment_children is not None : <EOL> users = [ ] <EOL> for comment in comment_children : <EOL> if comment . user in users : <EOL> pass <EOL> else : <EOL> users . append ( comment . user ) <EOL> return users <EOL> return None </s>
