def map_events(request): """ Display events on the map """ if not is_admin(request.user): return HttpResponseForbidden() tabs = AdminTabViews() tabs.set_active_tab('map') return render_tab_view(request, tabs, {'haze': Haze.objects.all()})
def map_events(request): """ Display events on the map """ # if not isOperator(request.user): # return HttpResponseBadRequest() tabs = PublicTabViews() tabs.set_active_tab('map') return render_tab_view(request, tabs, {'haze': Haze.objects.all()})
def get_crisis_view(request): """ Set crisis manager as active tab """ if not is_admin(request.user): return HttpResponseForbidden() tabs = AdminTabViews() tabs.set_active_tab('crisis') return render_tab_view(request, tabs, { })
def crisis_calculator(request): """ Show suggested crisis """ if not is_admin(request.user): return HttpResponseForbidden() tabs = AdminTabViews() tabs.set_active_tab('calculator') crises = CrisisCalculator().check_crisis() print(crises) return render_tab_view(request, tabs, data={'crises': crises})
def list_events(request): """ Return a list of events """ if not is_admin(request.user): return HttpResponseForbidden() tabs = AdminTabViews() tabs.set_active_tab('list') return render_tab_view(request, tabs, { 'trafficevents': TrafficEvent.objects.filter(event__isactive=True), 'terroristevents': TerroristEvent.objects.filter(event__isactive=True) })
def get_transaction_log(request): """ Get the transaction log from the database """ if not is_admin(request.user): return HttpResponseForbidden() tabs = AdminTabViews() tabs.set_active_tab('log') event_type_dict = {} return render_tab_view(request, tabs, { 'eventTransactionLog': EventTransactionLog.objects.all(), 'crisisLogDatabase': CrisisTransactionLog.objects.all(), })
def list_events(request): """ List all the events """ if not is_operator(request.user): return HttpResponseForbidden() tabs = OperatorTabViews() tabs.set_active_tab('list') return render_tab_view( request, tabs, { 'trafficevents': TrafficEvent.objects.filter(event__isactive=True), 'terroristevents': TerroristEvent.objects.filter(event__isactive=True) })
def new_event(request): """ Create a new event """ if not is_operator(request.user): return HttpResponseForbidden() if request.method == 'GET': tabs = OperatorTabViews() tabs.set_active_tab('newevent') data = {'eventtypes': enumerate(['Traffic Event', 'Terrorist Event'])} return render_tab_view(request, tabs, data) elif request.method == 'POST': event_details = {} reporter = {} event_type = request.POST.get('eventtype') reporter['identification'] = request.POST.get('identification') try: event_details['first_responder'] = Reporter.objects.get( identification=reporter['identification']) except Reporter.DoesNotExist: reporter['name'] = request.POST.get('name') reporter['contact_number'] = request.POST.get('contact') event_details['first_responder'] = Reporter.objects.create( **reporter) event_details['first_responder'].save() operator = Operator.objects.get(user_ptr_id=request.user.id) event_details['description'] = request.POST.get('description') event_details['num_casualties'] = int( request.POST.get('numCasualties')) event_details['num_injured'] = int(request.POST.get('numInjured')) event_details['location'] = lat_lng_to_point( request.POST.get('location')) event = Event.objects.create(**event_details) event.save() event.operator.add(operator) event_log = EventTransactionLog.objects.create( event=event, transaction_type='CR', operator=operator) # add the operator in later event_log.save() if event_type: specific_event_details = {'event': event} if event_type == 'traffic': specific_event_details['num_vehicles'] = int( request.POST.get('numVehicles')) new_event = TrafficEvent.objects.create( **specific_event_details) elif event_type == 'terrorist': specific_event_details['num_hostiles'] = int( request.POST.get('numHostiles')) specific_event_details['attack_type'] = request.POST.get( 'attacktype') new_event = TerroristEvent.objects.create( **specific_event_details) else: return HttpResponseBadRequest('nnok') new_event.save() AgencyDispatcher(event_log).dispatch() return redirect('/cms_operator/list') return HttpResponseBadRequest('nok')
def report_manager(request): tabs = AdminTabViews() tabs.set_active_tab('reportmanager') return render_tab_view(request, tabs)