<s> from django . conf import settings <EOL> from django . contrib . comments . managers import CommentManager <EOL> from django . contrib . contenttypes import generic <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . sites . models import Site <EOL> from django . core import urlresolvers <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils import timezone <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> COMMENT_MAX_LENGTH = getattr ( settings , '<STR_LIT>' , <NUM_LIT> ) <EOL> class BaseCommentAbstractModel ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> content_type = models . ForeignKey ( ContentType , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> related_name = "<STR_LIT>" ) <EOL> object_pk = models . TextField ( _ ( '<STR_LIT>' ) ) <EOL> content_object = generic . GenericForeignKey ( ct_field = "<STR_LIT>" , fk_field = "<STR_LIT>" ) <EOL> site = models . ForeignKey ( Site ) <EOL> class Meta : <EOL> abstract = True <EOL> def get_content_object_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return urlresolvers . reverse ( <EOL> "<STR_LIT>" , <EOL> args = ( self . content_type_id , self . object_pk ) <EOL> ) <EOL> @ python_2_unicode_compatible <EOL> class Comment ( BaseCommentAbstractModel ) : <EOL> """<STR_LIT>""" <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL , verbose_name = _ ( '<STR_LIT:user>' ) , <EOL> blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> user_name = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True ) <EOL> user_email = models . EmailField ( _ ( "<STR_LIT>" ) , blank = True ) <EOL> user_url = models . URLField ( _ ( "<STR_LIT>" ) , blank = True ) <EOL> comment = models . TextField ( _ ( '<STR_LIT>' ) , max_length = COMMENT_MAX_LENGTH ) <EOL> submit_date = models . DateTimeField ( _ ( '<STR_LIT>' ) , default = None ) <EOL> ip_address = models . IPAddressField ( _ ( '<STR_LIT>' ) , blank = True , null = True ) <EOL> is_public = models . BooleanField ( _ ( '<STR_LIT>' ) , default = True , <EOL> help_text = _ ( '<STR_LIT>' '<STR_LIT>' ) ) <EOL> is_removed = models . BooleanField ( _ ( '<STR_LIT>' ) , default = False , <EOL> help_text = _ ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) ) <EOL> objects = CommentManager ( ) <EOL> class Meta : <EOL> db_table = "<STR_LIT>" <EOL> ordering = ( '<STR_LIT>' , ) <EOL> permissions = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . name , self . comment [ : <NUM_LIT:50> ] ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . submit_date is None : <EOL> self . submit_date = timezone . now ( ) <EOL> super ( Comment , self ) . save ( * args , ** kwargs ) <EOL> def _get_userinfo ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> userinfo = { <EOL> "<STR_LIT:name>" : self . user_name , <EOL> "<STR_LIT:email>" : self . user_email , <EOL> "<STR_LIT:url>" : self . user_url <EOL> } <EOL> if self . user_id : <EOL> u = self . user <EOL> if u . email : <EOL> userinfo [ "<STR_LIT:email>" ] = u . email <EOL> if u . get_full_name ( ) : <EOL> userinfo [ "<STR_LIT:name>" ] = self . user . get_full_name ( ) <EOL> elif not self . user_name : <EOL> userinfo [ "<STR_LIT:name>" ] = u . get_username ( ) <EOL> self . _userinfo = userinfo <EOL> return self . _userinfo <EOL> userinfo = property ( _get_userinfo , doc = _get_userinfo . __doc__ ) <EOL> def _get_name ( self ) : <EOL> return self . userinfo [ "<STR_LIT:name>" ] <EOL> def _set_name ( self , val ) : <EOL> if self . user_id : <EOL> raise AttributeError ( _ ( "<STR_LIT>" "<STR_LIT>" ) ) <EOL> self . user_name = val <EOL> name = property ( _get_name , _set_name , doc = "<STR_LIT>" ) <EOL> def _get_email ( self ) : <EOL> return self . userinfo [ "<STR_LIT:email>" ] <EOL> def _set_email ( self , val ) : <EOL> if self . user_id : <EOL> raise AttributeError ( _ ( "<STR_LIT>" "<STR_LIT>" ) ) <EOL> self . user_email = val <EOL> email = property ( _get_email , _set_email , doc = "<STR_LIT>" ) <EOL> def _get_url ( self ) : <EOL> return self . userinfo [ "<STR_LIT:url>" ] <EOL> def _set_url ( self , val ) : <EOL> self . user_url = val <EOL> url = property ( _get_url , _set_url , doc = "<STR_LIT>" ) <EOL> def get_absolute_url ( self , anchor_pattern = "<STR_LIT>" ) : <EOL> return self . get_content_object_url ( ) + ( anchor_pattern % self . __dict__ ) <EOL> def get_as_text ( self ) : <EOL> """<STR_LIT>""" <EOL> d = { <EOL> '<STR_LIT:user>' : self . user or self . name , <EOL> '<STR_LIT:date>' : self . submit_date , <EOL> '<STR_LIT>' : self . comment , <EOL> '<STR_LIT>' : self . site . domain , <EOL> '<STR_LIT:url>' : self . get_absolute_url ( ) <EOL> } <EOL> return _ ( '<STR_LIT>' ) % d <EOL> @ python_2_unicode_compatible <EOL> class CommentFlag ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL , verbose_name = _ ( '<STR_LIT:user>' ) , related_name = "<STR_LIT>" ) <EOL> comment = models . ForeignKey ( Comment , verbose_name = _ ( '<STR_LIT>' ) , related_name = "<STR_LIT>" ) <EOL> flag = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:30> , db_index = True ) <EOL> flag_date = models . DateTimeField ( _ ( '<STR_LIT:date>' ) , default = None ) <EOL> SUGGEST_REMOVAL = "<STR_LIT>" <EOL> MODERATOR_DELETION = "<STR_LIT>" <EOL> MODERATOR_APPROVAL = "<STR_LIT>" <EOL> class Meta : <EOL> db_table = '<STR_LIT>' <EOL> unique_together = [ ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . flag , self . comment_id , self . user . get_username ( ) ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . flag_date is None : <EOL> self . flag_date = timezone . now ( ) <EOL> super ( CommentFlag , self ) . save ( * args , ** kwargs ) </s>
