<s> from __future__ import absolute_import <EOL> from django . contrib import messages <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from sentry . models import ( <EOL> AuditLogEntry , AuditLogEntryEvent , ProjectKey , ProjectKeyStatus <EOL> ) <EOL> from sentry . web . frontend . base import ProjectView <EOL> class DisableProjectKeyView ( ProjectView ) : <EOL> required_scope = '<STR_LIT>' <EOL> def post ( self , request , organization , team , project , key_id ) : <EOL> try : <EOL> key = ProjectKey . objects . get ( id = key_id ) <EOL> except ProjectKey . DoesNotExist : <EOL> return self . redirect ( reverse ( '<STR_LIT>' , args = [ project . organization . slug , project . slug ] ) ) <EOL> key . update ( status = ProjectKeyStatus . INACTIVE ) <EOL> AuditLogEntry . objects . create ( <EOL> organization = organization , <EOL> actor = request . user , <EOL> ip_address = request . META [ '<STR_LIT>' ] , <EOL> target_object = key . id , <EOL> event = AuditLogEntryEvent . PROJECTKEY_DISABLE , <EOL> data = key . get_audit_log_data ( ) , <EOL> ) <EOL> messages . add_message ( <EOL> request , messages . SUCCESS , <EOL> _ ( '<STR_LIT>' ) % ( key . public_key , ) ) <EOL> return self . redirect ( reverse ( '<STR_LIT>' , args = [ project . organization . slug , project . slug ] ) ) </s>
