<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import warnings <EOL> from collections import OrderedDict <EOL> from django . db import models <EOL> from django . utils import timezone <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from sentry . db . models import ( <EOL> BaseManager , BoundedBigIntegerField , BoundedIntegerField , <EOL> Model , NodeField , sane_repr <EOL> ) <EOL> from sentry . interfaces . base import get_interface <EOL> from sentry . utils . cache import memoize <EOL> from sentry . utils . safe import safe_execute <EOL> from sentry . utils . strings import truncatechars , strip <EOL> class Event ( Model ) : <EOL> """<STR_LIT>""" <EOL> __core__ = False <EOL> group_id = BoundedBigIntegerField ( blank = True , null = True ) <EOL> event_id = models . CharField ( max_length = <NUM_LIT:32> , null = True , db_column = "<STR_LIT>" ) <EOL> project_id = BoundedBigIntegerField ( blank = True , null = True ) <EOL> message = models . TextField ( ) <EOL> platform = models . CharField ( max_length = <NUM_LIT:64> , null = True ) <EOL> datetime = models . DateTimeField ( default = timezone . now , db_index = True ) <EOL> time_spent = BoundedIntegerField ( null = True ) <EOL> data = NodeField ( <EOL> blank = True , <EOL> null = True , <EOL> ref_func = lambda x : x . project_id or x . project . id , <EOL> ref_version = <NUM_LIT:2> , <EOL> ) <EOL> objects = BaseManager ( ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> db_table = '<STR_LIT>' <EOL> verbose_name = _ ( '<STR_LIT:message>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> unique_together = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> index_together = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> __repr__ = sane_repr ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _set_group ( self , group ) : <EOL> self . group_id = group . id <EOL> self . _group_cache = group <EOL> def _get_group ( self ) : <EOL> from sentry . models import Group <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _group_cache = Group . objects . get ( id = self . group_id ) <EOL> return self . _group_cache <EOL> group = property ( _get_group , _set_group ) <EOL> def _set_project ( self , project ) : <EOL> self . project_id = project . id <EOL> self . _project_cache = project <EOL> def _get_project ( self ) : <EOL> from sentry . models import Project <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _project_cache = Project . objects . get ( id = self . project_id ) <EOL> return self . _project_cache <EOL> project = property ( _get_project , _set_project ) <EOL> def error ( self ) : <EOL> message = strip ( self . message ) <EOL> if not message : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> message = truncatechars ( message . splitlines ( ) [ <NUM_LIT:0> ] , <NUM_LIT:100> ) <EOL> return message <EOL> error . short_description = _ ( '<STR_LIT:error>' ) <EOL> def has_two_part_message ( self ) : <EOL> message = strip ( self . message ) <EOL> return '<STR_LIT:\n>' in message or len ( message ) > <NUM_LIT:100> <EOL> @ property <EOL> def message_short ( self ) : <EOL> message = strip ( self . message ) <EOL> if not message : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> message = truncatechars ( message . splitlines ( ) [ <NUM_LIT:0> ] , <NUM_LIT:100> ) <EOL> return message <EOL> @ property <EOL> def team ( self ) : <EOL> return self . project . team <EOL> @ property <EOL> def organization ( self ) : <EOL> return self . project . organization <EOL> @ property <EOL> def version ( self ) : <EOL> return self . data . get ( '<STR_LIT:version>' , '<STR_LIT:5>' ) <EOL> @ memoize <EOL> def ip_address ( self ) : <EOL> user_data = self . data . get ( '<STR_LIT>' , self . data . get ( '<STR_LIT:user>' ) ) <EOL> if user_data : <EOL> value = user_data . get ( '<STR_LIT>' ) <EOL> if value : <EOL> return value <EOL> http_data = self . data . get ( '<STR_LIT>' , self . data . get ( '<STR_LIT:http>' ) ) <EOL> if http_data and '<STR_LIT>' in http_data : <EOL> value = http_data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> if value : <EOL> return value <EOL> return None <EOL> def get_interfaces ( self ) : <EOL> result = [ ] <EOL> for key , data in self . data . iteritems ( ) : <EOL> try : <EOL> cls = get_interface ( key ) <EOL> except ValueError : <EOL> continue <EOL> value = safe_execute ( cls . to_python , data ) <EOL> if not value : <EOL> continue <EOL> result . append ( ( key , value ) ) <EOL> return OrderedDict ( ( k , v ) for k , v in sorted ( result , key = lambda x : x [ <NUM_LIT:1> ] . get_score ( ) , reverse = True ) ) <EOL> @ memoize <EOL> def interfaces ( self ) : <EOL> return self . get_interfaces ( ) <EOL> def get_tags ( self , with_internal = True ) : <EOL> try : <EOL> return sorted ( <EOL> ( t , v ) for t , v in self . data . get ( '<STR_LIT>' ) or ( ) <EOL> if with_internal or not t . startswith ( '<STR_LIT>' ) <EOL> ) <EOL> except ValueError : <EOL> return [ ] <EOL> tags = property ( get_tags ) <EOL> def get_tag ( self , key ) : <EOL> for t , v in ( self . data . get ( '<STR_LIT>' ) or ( ) ) : <EOL> if t == key : <EOL> return v <EOL> return None <EOL> def as_dict ( self ) : <EOL> data = OrderedDict ( ) <EOL> data [ '<STR_LIT:id>' ] = self . event_id <EOL> data [ '<STR_LIT>' ] = self . project_id <EOL> data [ '<STR_LIT>' ] = self . get_tag ( '<STR_LIT>' ) <EOL> data [ '<STR_LIT>' ] = self . platform <EOL> data [ '<STR_LIT>' ] = self . group . culprit <EOL> data [ '<STR_LIT:message>' ] = self . message <EOL> data [ '<STR_LIT>' ] = self . datetime <EOL> data [ '<STR_LIT>' ] = self . time_spent <EOL> data [ '<STR_LIT>' ] = self . get_tags ( ) <EOL> for k , v in sorted ( self . data . iteritems ( ) ) : <EOL> data [ k ] = v <EOL> return data <EOL> @ property <EOL> def size ( self ) : <EOL> data_len = len ( self . message ) <EOL> for value in self . data . itervalues ( ) : <EOL> data_len += len ( repr ( value ) ) <EOL> return data_len <EOL> def get_level_display ( self ) : <EOL> warnings . warn ( '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return self . group . get_level_display ( ) <EOL> @ property <EOL> def level ( self ) : <EOL> warnings . warn ( '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return self . group . level <EOL> @ property <EOL> def logger ( self ) : <EOL> warnings . warn ( '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return self . get_tag ( '<STR_LIT>' ) <EOL> @ property <EOL> def site ( self ) : <EOL> warnings . warn ( '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return self . get_tag ( '<STR_LIT>' ) <EOL> @ property <EOL> def server_name ( self ) : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> return self . get_tag ( '<STR_LIT>' ) <EOL> @ property <EOL> def culprit ( self ) : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> return self . group . culprit <EOL> @ property <EOL> def checksum ( self ) : <EOL> warnings . warn ( '<STR_LIT>' , DeprecationWarning ) <EOL> return '<STR_LIT>' </s>
