<s> from __future__ import absolute_import <EOL> from rest_framework . response import Response <EOL> from sentry . api . base import Endpoint <EOL> from sentry . api . bases . group import GroupPermission <EOL> from sentry . api . exceptions import ResourceDoesNotExist <EOL> from sentry . api . serializers import serialize <EOL> from sentry . constants import EVENT_ORDERING_KEY <EOL> from sentry . models import Event , Release , UserReport <EOL> class EventDetailsEndpoint ( Endpoint ) : <EOL> permission_classes = ( GroupPermission , ) <EOL> def _get_release_info ( self , request , event ) : <EOL> version = event . get_tag ( '<STR_LIT>' ) <EOL> if not version : <EOL> return None <EOL> try : <EOL> release = Release . objects . get ( <EOL> project = event . project , <EOL> version = version , <EOL> ) <EOL> except Release . DoesNotExist : <EOL> return { '<STR_LIT:version>' : version } <EOL> return serialize ( release , request . user ) <EOL> def get ( self , request , event_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> event = Event . objects . get ( <EOL> id = event_id <EOL> ) <EOL> except Event . DoesNotExist : <EOL> raise ResourceDoesNotExist <EOL> self . check_object_permissions ( request , event . group ) <EOL> Event . objects . bind_nodes ( [ event ] , '<STR_LIT:data>' ) <EOL> base_qs = Event . objects . filter ( <EOL> group_id = event . group_id , <EOL> ) . exclude ( id = event . id ) <EOL> next_events = sorted ( <EOL> base_qs . filter ( <EOL> datetime__gte = event . datetime , <EOL> ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:5> ] , <EOL> key = EVENT_ORDERING_KEY , <EOL> ) <EOL> prev_events = sorted ( <EOL> base_qs . filter ( <EOL> datetime__lte = event . datetime , <EOL> ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:5> ] , <EOL> key = EVENT_ORDERING_KEY , <EOL> reverse = True , <EOL> ) <EOL> next_event = None <EOL> for e in next_events : <EOL> if e . datetime == event . datetime and e . id > event . id : <EOL> next_event = e <EOL> break <EOL> if e . datetime > event . datetime : <EOL> next_event = e <EOL> break <EOL> prev_event = None <EOL> for e in prev_events : <EOL> if e . datetime == event . datetime and e . id < event . id : <EOL> prev_event = e <EOL> break <EOL> if e . datetime < event . datetime : <EOL> prev_event = e <EOL> break <EOL> try : <EOL> user_report = UserReport . objects . get ( <EOL> event_id = event . event_id , <EOL> project = event . project , <EOL> ) <EOL> except UserReport . DoesNotExist : <EOL> user_report = None <EOL> data = serialize ( event , request . user ) <EOL> data [ '<STR_LIT>' ] = serialize ( user_report , request . user ) <EOL> data [ '<STR_LIT>' ] = self . _get_release_info ( request , event ) <EOL> if next_event : <EOL> data [ '<STR_LIT>' ] = str ( next_event . id ) <EOL> else : <EOL> data [ '<STR_LIT>' ] = None <EOL> if prev_event : <EOL> data [ '<STR_LIT>' ] = str ( prev_event . id ) <EOL> else : <EOL> data [ '<STR_LIT>' ] = None <EOL> return Response ( data ) </s>
