<s> import json <EOL> import re <EOL> from django import http <EOL> from django . db . models import Count <EOL> from django . db . transaction import non_atomic_requests <EOL> from django . shortcuts import redirect , render <EOL> from django . views . decorators . csrf import csrf_exempt <EOL> from olympia import amo <EOL> from olympia . amo import utils as amo_utils <EOL> from olympia . addons . decorators import owner_or_unlisted_reviewer <EOL> from olympia . amo . decorators import post_required <EOL> from olympia . addons . models import Addon <EOL> from olympia . search . utils import floor_version <EOL> from olympia . versions . compare import version_dict as vdict <EOL> from . models import CompatReport <EOL> from . forms import AppVerForm <EOL> @ csrf_exempt <EOL> @ post_required <EOL> @ non_atomic_requests <EOL> def incoming ( request ) : <EOL> def snake_case ( s ) : <EOL> return re . sub ( '<STR_LIT>' , '<STR_LIT>' , s ) . lower ( ) <EOL> try : <EOL> data = [ ( snake_case ( k ) , v ) <EOL> for k , v in json . loads ( request . body ) . items ( ) ] <EOL> except Exception : <EOL> return http . HttpResponseBadRequest ( ) <EOL> report = CompatReport ( client_ip = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> fields = CompatReport . _meta . get_all_field_names ( ) <EOL> for key , value in data : <EOL> if key in fields : <EOL> setattr ( report , key , value ) <EOL> else : <EOL> return http . HttpResponseBadRequest ( ) <EOL> report . save ( ) <EOL> return http . HttpResponse ( status = <NUM_LIT> ) <EOL> @ non_atomic_requests <EOL> def reporter ( request ) : <EOL> query = request . GET . get ( '<STR_LIT>' ) <EOL> if query : <EOL> qs = None <EOL> if query . isdigit ( ) : <EOL> qs = Addon . with_unlisted . filter ( id = query ) <EOL> if not qs : <EOL> qs = Addon . with_unlisted . filter ( slug = query ) <EOL> if not qs : <EOL> qs = Addon . with_unlisted . filter ( guid = query ) <EOL> if not qs and len ( query ) > <NUM_LIT:4> : <EOL> qs = CompatReport . objects . filter ( guid__startswith = query ) <EOL> if qs : <EOL> guid = qs [ <NUM_LIT:0> ] . guid <EOL> addon = Addon . with_unlisted . get ( guid = guid ) <EOL> if addon . is_listed or owner_or_unlisted_reviewer ( request , addon ) : <EOL> return redirect ( '<STR_LIT>' , guid ) <EOL> addons = ( Addon . with_unlisted . filter ( authors = request . user ) <EOL> if request . user . is_authenticated ( ) else [ ] ) <EOL> return render ( request , '<STR_LIT>' , <EOL> dict ( query = query , addons = addons ) ) <EOL> @ non_atomic_requests <EOL> def reporter_detail ( request , guid ) : <EOL> try : <EOL> addon = Addon . with_unlisted . get ( guid = guid ) <EOL> except Addon . DoesNotExist : <EOL> addon = None <EOL> name = addon . name if addon else guid <EOL> qs = CompatReport . objects . filter ( guid = guid ) <EOL> if ( addon and not addon . is_listed and <EOL> not owner_or_unlisted_reviewer ( request , addon ) ) : <EOL> name = guid <EOL> qs = CompatReport . objects . none ( ) <EOL> form = AppVerForm ( request . GET ) <EOL> if request . GET and form . is_valid ( ) and form . cleaned_data [ '<STR_LIT>' ] : <EOL> app , ver = form . cleaned_data [ '<STR_LIT>' ] . split ( '<STR_LIT:->' ) <EOL> app = amo . APP_IDS [ int ( app ) ] <EOL> ver = vdict ( floor_version ( ver ) ) [ '<STR_LIT>' ] <EOL> qs = qs . filter ( app_guid = app . guid , <EOL> app_version__startswith = str ( ver ) + '<STR_LIT:.>' ) <EOL> works_ = dict ( qs . values_list ( '<STR_LIT>' ) . annotate ( Count ( '<STR_LIT:id>' ) ) ) <EOL> works = { '<STR_LIT:success>' : works_ . get ( True , <NUM_LIT:0> ) , '<STR_LIT>' : works_ . get ( False , <NUM_LIT:0> ) } <EOL> works_properly = request . GET . get ( '<STR_LIT>' ) <EOL> if works_properly : <EOL> qs = qs . filter ( works_properly = works_properly ) <EOL> reports = amo_utils . paginate ( request , qs . order_by ( '<STR_LIT>' ) , <NUM_LIT:100> ) <EOL> return render ( request , '<STR_LIT>' , <EOL> dict ( reports = reports , works = works , <EOL> works_properly = works_properly , <EOL> name = name , guid = guid , form = form ) ) </s>
