<s> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . admin . util import quote <EOL> from django . utils . translation import ugettext , ugettext_lazy as _ <EOL> from django . utils . encoding import smart_text <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> ADDITION = <NUM_LIT:1> <EOL> CHANGE = <NUM_LIT:2> <EOL> DELETION = <NUM_LIT:3> <EOL> class LogEntryManager ( models . Manager ) : <EOL> def log_action ( self , user_id , content_type_id , object_id , object_repr , action_flag , change_message = '<STR_LIT>' ) : <EOL> e = self . model ( None , None , user_id , content_type_id , smart_text ( object_id ) , object_repr [ : <NUM_LIT:200> ] , action_flag , change_message ) <EOL> e . save ( ) <EOL> @ python_2_unicode_compatible <EOL> class LogEntry ( models . Model ) : <EOL> action_time = models . DateTimeField ( _ ( '<STR_LIT>' ) , auto_now = True ) <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL ) <EOL> content_type = models . ForeignKey ( ContentType , blank = True , null = True ) <EOL> object_id = models . TextField ( _ ( '<STR_LIT>' ) , blank = True , null = True ) <EOL> object_repr = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:200> ) <EOL> action_flag = models . PositiveSmallIntegerField ( _ ( '<STR_LIT>' ) ) <EOL> change_message = models . TextField ( _ ( '<STR_LIT>' ) , blank = True ) <EOL> objects = LogEntryManager ( ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> db_table = '<STR_LIT>' <EOL> ordering = ( '<STR_LIT>' , ) <EOL> def __repr__ ( self ) : <EOL> return smart_text ( self . action_time ) <EOL> def __str__ ( self ) : <EOL> if self . action_flag == ADDITION : <EOL> return ugettext ( '<STR_LIT>' ) % { '<STR_LIT:object>' : self . object_repr } <EOL> elif self . action_flag == CHANGE : <EOL> return ugettext ( '<STR_LIT>' ) % { <EOL> '<STR_LIT:object>' : self . object_repr , <EOL> '<STR_LIT>' : self . change_message , <EOL> } <EOL> elif self . action_flag == DELETION : <EOL> return ugettext ( '<STR_LIT>' ) % { '<STR_LIT:object>' : self . object_repr } <EOL> return ugettext ( '<STR_LIT>' ) <EOL> def is_addition ( self ) : <EOL> return self . action_flag == ADDITION <EOL> def is_change ( self ) : <EOL> return self . action_flag == CHANGE <EOL> def is_deletion ( self ) : <EOL> return self . action_flag == DELETION <EOL> def get_edited_object ( self ) : <EOL> "<STR_LIT>" <EOL> return self . content_type . get_object_for_this_type ( pk = self . object_id ) <EOL> def get_admin_url ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . content_type and self . object_id : <EOL> return "<STR_LIT>" % ( self . content_type . app_label , self . content_type . model , quote ( self . object_id ) ) <EOL> return None </s>
