<s> from django . http import HttpResponse , HttpResponseRedirect , HttpResponseNotFound <EOL> from django . template import Context , loader <EOL> from django . core . urlresolvers import reverse <EOL> from django . template import RequestContext <EOL> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from datetime import datetime <EOL> from tagging . models import Tag , TaggedItem <EOL> from django . views . decorators . csrf import csrf_exempt <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . auth import authenticate , login <EOL> from django . core . mail import send_mail <EOL> from django . conf import settings <EOL> from django . http import Http404 <EOL> from django . db . models import Q <EOL> import json <EOL> from openwatch . recordings . models import Recording <EOL> from openwatch import recording_tags <EOL> @ login_required <EOL> def moderate ( request ) : <EOL> '''<STR_LIT>''' <EOL> response_values = { } <EOL> org_tag = request . user . get_profile ( ) . org_tag <EOL> if not request . user . is_superuser and ( not request . user . get_profile ( ) . can_moderate or org_tag == '<STR_LIT>' ) : <EOL> raise Http404 <EOL> if recording_tags . ACLU_NJ in org_tag : <EOL> location = { } <EOL> location [ '<STR_LIT>' ] = <NUM_LIT> <EOL> location [ '<STR_LIT>' ] = - <NUM_LIT> <EOL> response_values [ '<STR_LIT:location>' ] = location <EOL> response_values [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return render_to_response ( '<STR_LIT>' , response_values , context_instance = RequestContext ( request ) ) <EOL> def map ( request ) : <EOL> total = "<STR_LIT>" <EOL> return render_to_response ( '<STR_LIT>' , { '<STR_LIT>' : total } , context_instance = RequestContext ( request ) ) <EOL> def size ( request ) : <EOL> featureset = Recording . objects . filter ( ~ Q ( lat = None ) , ~ Q ( lon = None ) , ~ Q ( jtype = '<STR_LIT>' ) ) . exclude ( location__exact = '<STR_LIT>' ) . exclude ( location__exact = '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) <EOL> total = len ( featureset ) <EOL> return render_to_response ( '<STR_LIT>' , { '<STR_LIT>' : total } , context_instance = RequestContext ( request ) ) <EOL> def redir ( self ) : <EOL> return HttpResponseRedirect ( '<STR_LIT:/>' ) <EOL> def map_json ( request ) : <EOL> featureset = Recording . objects . all ( ) . order_by ( '<STR_LIT>' ) . filter ( ~ Q ( location = '<STR_LIT>' ) ) . exclude ( location__isnull = True ) . exclude ( location__exact = '<STR_LIT>' ) [ : <NUM_LIT> ] <EOL> resp = encode_queryset ( featureset ) <EOL> return HttpResponse ( resp , mimetype = "<STR_LIT:application/json>" ) <EOL> @ login_required <EOL> def map_json_moderate ( request ) : <EOL> org_tag = request . user . get_profile ( ) . org_tag <EOL> if org_tag != '<STR_LIT>' : <EOL> featureset = Recording . objects . filter ( org_approved = False , org_flagged = False , tags__contains = org_tag ) <EOL> else : <EOL> featureset = Recording . objects . all ( ) <EOL> featureset = featureset . order_by ( '<STR_LIT>' ) . filter ( ~ Q ( location = '<STR_LIT>' ) ) . exclude ( location__isnull = True ) . exclude ( location__exact = '<STR_LIT>' ) <EOL> resp = encode_queryset ( featureset ) <EOL> return HttpResponse ( resp , mimetype = "<STR_LIT:application/json>" ) <EOL> def map_location_json ( request , ne_lat = <NUM_LIT:0> , ne_lon = <NUM_LIT:0> , sw_lat = <NUM_LIT:0> , sw_lon = <NUM_LIT:0> ) : <EOL> ne_lat = float ( ne_lat ) <EOL> ne_lon = float ( ne_lon ) <EOL> sw_lat = float ( sw_lat ) <EOL> sw_lon = float ( sw_lon ) <EOL> featureset = Recording . objects . filter ( lat__lt = ne_lat , lat__gt = sw_lat , lon__lt = ne_lon , lon__gt = sw_lon ) . order_by ( '<STR_LIT>' ) . exclude ( location__isnull = True ) . exclude ( location__exact = '<STR_LIT>' ) . exclude ( location__exact = '<STR_LIT>' ) . exclude ( location__exact = '<STR_LIT>' ) [ : <NUM_LIT> ] <EOL> if len ( featureset ) < <NUM_LIT:1> : <EOL> return HttpResponse ( "<STR_LIT>" , mimetype = "<STR_LIT:application/json>" ) <EOL> resp = encode_queryset ( featureset ) <EOL> return HttpResponse ( resp , mimetype = "<STR_LIT:application/json>" ) <EOL> def encode_queryset ( featureset ) : <EOL> resp = '<STR_LIT>' <EOL> for obj in featureset : <EOL> resp = resp + json . dumps ( obj . to_dict ( ) ) + '<STR_LIT:U+002C>' <EOL> resp = resp [ : - <NUM_LIT:1> ] + '<STR_LIT>' <EOL> return resp </s>
