Example #1
0
 def get_flights(user, method, body):
     user_owned_flights = Flight.objects
     department_flights = Flight.objects
     if method == 'POST':
         filters = body['filters']
         for _filter in filters:
             if _filter['title'] == 'before':
                 user_owned_flights = user_owned_flights.filter(ends_at__lt=parse_datetime(_filter['datetime']))
                 department_flights = department_flights.filter(ends_at__lt=parse_datetime(_filter['datetime']))
             if _filter['title'] == 'after':
                 user_owned_flights = user_owned_flights.filter(starts_at__gt=parse_datetime(_filter['datetime']))
                 department_flights = department_flights.filter(starts_at__gt=parse_datetime(_filter['datetime']))
     user_departments = DepartmentController.get_user_department_query(user)
     for user_department in user_departments:
         user_owned_flights = user_owned_flights.filter(~Q(area__intersects=user_department.area))
         department_flights = department_flights.filter(area__intersects=user_department.area)
     if len(user_departments) == 0:
         department_flights = []
     else:
         department_flights = department_flights.all()
     user_owned_flights = user_owned_flights.filter(created_by=user.id).all()
     dictionaries = []
     for flights, can_edit_clearance in [(department_flights, True), (user_owned_flights, False)]:
         for flight in flights:
             flight_dict = flight.as_dict()
             flight_dict['num_drones'] = Asset.objects.filter(flight=flight).count()
             flight_dict['can_edit_clearance'] = can_edit_clearance
             dictionaries += [flight_dict]
     return dictionaries
Example #2
0
 def get_flight_info(flight_id, user) -> (int, dict):
     flight = Flight.objects.filter(id=flight_id).first()
     if not flight:
         return 400, {"message": "No mission exists with that id."}
     flight_dict = flight.as_dict()
     user_departments = DepartmentController.get_user_department_query(user)
     flight_dict['can_edit_clearance'] = False
     for user_department in user_departments:
         if flight.area.intersects(user_department.area):
             flight_dict['can_edit_clearance'] = True
     return 200, flight_dict
Example #3
0
def message_jurisdiction(request):
    user = request.user
    body = request.data
    department_name = body['department_name']
    gov_official = DepartmentController.get_user_department_query(user)
    if not gov_official:
        response_json = {
            'message': 'Must be government official to use this endpoint.'
        }
        return HttpResponse(json.dumps(response_json),
                            content_type='application/json',
                            status=400)
    DepartmentController.message_pilots(department_name, body['message'])
    response_json = {'message': 'Messages have successfully begun sending.'}
    return HttpResponse(json.dumps(response_json),
                        content_type='application/json')