def create(request): try: json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["DESC"], expectedAttr["DATETIME"] ] commonHttp.check_keys(json_obj, req_attrs) new_ism = IncidentSummary( description=json_obj[expectedAttr["DESC"]], datetime=json_obj[expectedAttr["DATETIME"]] ) commonHttp.save_model_obj(new_ism) response = JsonResponse({ "id" : new_ism.id, "success" : True }) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def update(request, obj_id): try: # Get existing obj existing_loc = IncidentLocation.objects.get(id=obj_id) except IncidentLocation.DoesNotExist as e: return HttpResponseBadRequest(str(e)) try: # Update existing obj json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["RADIUS"], expectedAttr["COORD_LAT"], expectedAttr["COORD_LONG"], ] commonHttp.check_keys(json_obj, req_attrs) existing_loc.radius = json_obj.get(expectedAttr["RADIUS"]) existing_loc.coord_lat = json_obj.get(expectedAttr["COORD_LAT"]) existing_loc.coord_long = json_obj.get(expectedAttr["COORD_LONG"]) commonHttp.save_model_obj(existing_loc) response = JsonResponse({ "success": True, }) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def update(request, obj_id): try: # Get existing obj existing_ism= IncidentSummary.objects.get(id=obj_id) except IncidentSummary.DoesNotExist as e: return HttpResponseBadRequest(str(e)) try: # Update existing obj json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["DESC"], expectedAttr["DATETIME"] ] commonHttp.check_keys(json_obj, req_attrs) existing_ism.description = json_obj.get(expectedAttr["DESC"]) existing_ism.datetime = json_obj.get(expectedAttr["DATETIME"]) commonHttp.save_model_obj(existing_ism) response = JsonResponse({ "success" : True, }) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def update(request, obj_id): try: # Get existing obj existing_agency = Agency.objects.get(id=obj_id) except Agency.DoesNotExist as e: return HttpResponseBadRequest(str(e)) try: # Update existing obj json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["NAME"], expectedAttr["DESCRIPTION"], expectedAttr["SMS_CONTACT_NO"], ] commonHttp.check_keys(json_obj, req_attrs) existing_agency.name = json_obj.get(expectedAttr["NAME"]) existing_agency.desc = json_obj.get(expectedAttr["DESCRIPTION"]) existing_agency.sms_contact_no = json_obj.get( expectedAttr["SMS_CONTACT_NO"]) commonHttp.save_model_obj(existing_agency) response = JsonResponse({ "success": True, }) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def update(request, obj_id): try: # Get existing obj existing_icr = IncidentCallReport.objects.get(id=obj_id) except IncidentCallReport.DoesNotExist as e: return HttpResponseBadRequest(str(e)) try: # Update existing obj json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["CALLER_NAME"], expectedAttr["CONTACT_NO"], expectedAttr["DESC"], expectedAttr["DATETIME"] ] commonHttp.check_keys(json_obj, req_attrs) existing_icr.caller_name = json_obj.get(expectedAttr["CALLER_NAME"]) existing_icr.contact_no = json_obj.get(expectedAttr["CONTACT_NO"]) existing_icr.description = json_obj.get(expectedAttr["DESC"]) existing_icr.dateTime = json_obj.get(expectedAttr["DATETIME"]) commonHttp.save_model_obj(existing_icr) response = JsonResponse({ "success": True, }) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def update(request, obj_id): try: # Get existing obj existing_incident = Incident.objects.get(id=obj_id) except Incident.DoesNotExist as e: return HttpResponseBadRequest(str(e)) try: # Update existing obj json_obj = commonHttp.get_json(request.body) loc_req_attrs = [ loc_expectedAttr["RADIUS"], loc_expectedAttr["COORD_LAT"], loc_expectedAttr["COORD_LONG"], ] activation_time = json_obj.get(expectedAttr["ACT_TIME"]) deactivation_time = json_obj.get(expectedAttr["DEACT_TIME"]) description = json_obj.get(expectedAttr["DESC"]) incident_type = json_obj.get(expectedAttr["TYPE"]) loc_obj = json_obj.get(expectedAttr["LOC"]) if activation_time: existing_incident.activation_time = activation_time if deactivation_time: existing_incident.deactivation_time = deactivation_time if description: existing_incident.description = description if incident_type: existing_incident.incident_type = incident_type if loc_obj: commonHttp.check_keys(loc_obj, loc_req_attrs) existing_incident.location.radius = loc_obj[ loc_expectedAttr["RADIUS"]] existing_incident.location.coord_lat = loc_obj[ loc_expectedAttr["COORD_LAT"]] existing_incident.location.coord_long = loc_obj[ loc_expectedAttr["COORD_LONG"]] commonHttp.save_model_obj(existing_incident.location) commonHttp.save_model_obj(existing_incident) response = JsonResponse({ "success": True, }) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def create(request): json_obj = commonHttp.get_json(request.body) try: cms = CMSStatus.objects.get(id=1) all_incident_logs = IncidentLog.objects.all() contentStr = '' currentPointer = -1 for incident_logs in reversed(all_incident_logs): incident = Incident.objects.get(id=incident_logs.incident_id) if currentPointer != incident_logs.incident_id: contentStr = contentStr + '\nIncident ID and Type: ' + str( incident_logs.incident_id ) + ' ' + incident.incident_type + '\nDescription: ' + incident_logs.description + '\nDateTime: ' + str( incident_logs.datetime) + '\n' currentPointer = incident_logs.incident_id else: contentStr = contentStr + 'Description: ' + incident_logs.description + '\nDateTime: ' + str( incident_logs.datetime) + '\n' time_difference = datetime_util.sgt_now() - cms.last_sent if time_difference > timedelta(minutes=30) and cms.active: email = EmailMessage('Incident Report Generated ' + str(datetime_util.sgt_now()), contentStr, to=['*****@*****.**']) email.send() cms.last_sent = datetime_util.sgt_now() commonHttp.save_model_obj(cms) new_ism = IncidentSummary(description=contentStr, datetime=datetime_util.sgt_now()) commonHttp.save_model_obj(new_ism) response = JsonResponse({ cmsexpectedAttr["ACTIVE"]: cms.active, "cms_last_sent": cms.last_sent, "success": True, }) return response except Exception as e: response = JsonResponse({ cmsexpectedAttr["ACTIVE"]: cms.active, "cms_last_sent": cms.last_sent, "success": False, "exception": e, }) return response
def create(request): try: json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["TO"], expectedAttr["TITLE"], expectedAttr["MESSAGE"] ] commonHttp.check_keys(json_obj, req_attrs) new_sms = SMS(to=json_obj[expectedAttr["TO"]], title=json_obj[expectedAttr["TITLE"]], message=json_obj[expectedAttr["MESSAGE"]]) commonHttp.save_model_obj(new_sms) url = "http://smsgateway.me/api/v3/messages/send" data = { 'email': '*****@*****.**', 'password': env.SMS_ACC_PASSWORD, 'device': '32326', 'number': json_obj[expectedAttr["TO"]], 'message': json_obj[expectedAttr["TITLE"]] + "," + json_obj[expectedAttr["MESSAGE"]] } r = requests.post(url, data) print "test" print r.json()['success'] if r.json()['success'] == True: status = True else: status = False response = JsonResponse({"id": new_sms.id, "success": status}) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def create_location(loc_obj): loc_req_attrs = [ loc_expectedAttr["RADIUS"], loc_expectedAttr["COORD_LAT"], loc_expectedAttr["COORD_LONG"], ] commonHttp.check_keys(loc_obj, loc_req_attrs) new_location = IncidentLocation( radius=loc_obj[loc_expectedAttr["RADIUS"]], coord_lat=loc_obj[loc_expectedAttr["COORD_LAT"]], coord_long=loc_obj[loc_expectedAttr["COORD_LONG"]]) commonHttp.save_model_obj(new_location) return new_location
def make_callreport(request, incident_id): json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["CALLER_NAME"], expectedAttr["CONTACT_NO"], expectedAttr["DESC"], expectedAttr["DATETIME"], ] commonHttp.check_keys(json_obj, req_attrs) new_icr = IncidentCallReport( caller_name=json_obj[expectedAttr["CALLER_NAME"]], contact_no=json_obj[expectedAttr["CONTACT_NO"]], description=json_obj[expectedAttr["DESC"]], dateTime=json_obj[expectedAttr["DATETIME"]], incident_id=incident_id) commonHttp.save_model_obj(new_icr) return new_icr
def create(request, incident_id): """Create log for given incident""" try: json_obj = commonHttp.get_json(request.body) req_attrs = [expectedAttr["DESCRIPTION"]] commonHttp.check_keys(json_obj, req_attrs) new_log = IncidentLog( incident_id=incident_id, datetime=datetime.datetime.now(), description=json_obj[expectedAttr["DESCRIPTION"]]) commonHttp.save_model_obj(new_log) response = JsonResponse({"id": new_log.id, "success": True}) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def create(request): try: json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["RADIUS"], expectedAttr["COORD_LAT"], expectedAttr["COORD_LONG"] ] commonHttp.check_keys(json_obj, req_attrs) new_loc = IncidentLocation( radius=json_obj[expectedAttr["RADIUS"]], coord_lat=json_obj[expectedAttr["COORD_LAT"]], coord_long=json_obj[expectedAttr["COORD_LONG"]]) commonHttp.save_model_obj(new_loc) response = JsonResponse({"id": new_loc.id, "success": True}) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def create(request): """Create Incident with IncidentLocation""" try: json_obj = commonHttp.get_json(request.body) # Check request json req_attrs = [ expectedAttr["DESC"], expectedAttr["TYPE"], expectedAttr["LOC"], ] commonHttp.check_keys(json_obj, req_attrs) new_location = None if json_obj.get(expectedAttr["LOC"]): new_location = create_location(json_obj.get(expectedAttr["LOC"])) activation_time = json_obj.get(expectedAttr["ACT_TIME"]) deactivation_time = json_obj.get(expectedAttr["DEACT_TIME"]) new_incident = Incident(activation_time=activation_time, deactivation_time=deactivation_time, description=json_obj[expectedAttr["DESC"]], incident_type=json_obj[expectedAttr["TYPE"]], location=new_location) commonHttp.save_model_obj(new_incident) response = JsonResponse({"id": new_incident.id, "success": True}) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)
def create(request): try: json_obj = commonHttp.get_json(request.body) req_attrs = [ expectedAttr["NAME"], expectedAttr["DESCRIPTION"], expectedAttr["SMS_CONTACT_NO"] ] commonHttp.check_keys(json_obj, req_attrs) new_agency = Agency( name=json_obj[expectedAttr["NAME"]], description=json_obj[expectedAttr["DESCRIPTION"]], sms_contact_no=json_obj[expectedAttr["SMS_CONTACT_NO"]]) commonHttp.save_model_obj(new_agency) response = JsonResponse({"id": new_agency.id, "success": True}) return response except commonHttp.HttpBadRequestException as e: return HttpResponseBadRequest(e.reason_phrase)