Example #1
0
def query_region(region,fields_values):

    request_dict = parse_fields_values(fields_values)

    #search data for request dictionary
    results = [x for x in config.sandy_collection.find(request_dict).limit(50000)]

    #convert date and object ID to string
    for r in results:
        for x,y in r.items():
            if type(y) in (datetime.datetime,ObjectId):
               r[x] = str(y)

    if request_wants_json():
        return jsonify(items=results)

    return jsonify(items=results)
Example #2
0
def query_structure(fields_values = False):
    if fields_values:
        request_dict = parse_fields_values(fields_values)

        #search data for request dictionary
        results = [x for x in config.sandy_collection.find(request_dict).limit(50000)]
    else:
        results = [x for x in config.sandy_collection.limit(50000)]
    
    outbound = []

    #convert date and object ID to string
    for r in results:
        for x,y in r.items():
            if type(y) in (datetime.datetime,ObjectId):
               r[x] = str(y)

        
        structure = {
                'id':r.pop('gid',None),
                'timestamp':r.pop('timestamp',None),
                'date':r.pop('date',None),
                'contact':{
                    'first-name':r.pop('first-name',None),
                    'last-name':r.pop('last-name',None),
                    'phone':r.pop('phone',None),
                    'email':r.pop('email',None),
                    'contact-lang':r.pop('contact-lang',None),
                    'contact-origin':r.pop('contact-origin',None)
                },
                'sandy':{
                    'resident-during-sandy':r.pop('resident-during-sandy',None)
                },
                'location':{
                    'street':r.pop('street',None),
                    'city':r.pop('city',None),
                    'state':r.pop('state',None),
                    'zip':r.pop('zip',None)
                },
                'home':{
                    'occupant-count':r.pop('occupant-count',None),
                    'rent-or-own-1':r.pop('rent-or-own-1',None),
                    'rent-or-own-2':r.pop('rent-or-own-2',None),
                    'resident':r.pop('resident',None),
                    'residence-other':r.pop('residence-other',None),
                    'have-children':r.pop('have-children',None),
                    'have-seniors':r.pop('have-seniors',None),
                    'have-disabled':r.pop('have-disabled',None),
                    'damage':{
                        'house-has-damage':r.pop('house-has-damage',None),
                        'need-help-repair':r.pop('need-help-repair',None),
                        'house-has-mold':r.pop('house-has-mold',None)
                    },
                'notes':{
                    'note-contact':r.pop('note-contact',None),
                    'note-info':r.pop('note-info',None),
                    'note-fema-sba':r.pop('note-fema-sba',None),
                    'note-insurance':r.pop('note-insurance',None),
                    'note-housing':r.pop('note-housing',None),
                    'note-other':r.pop('note-other',None)
                    }
                }
            }

        structure['other'] = {}
        for x,y in r.items():
            structure['other'][x] = y
       
        # Remove None values 
        structure.update((k, v) for k, v in structure.iteritems() if v is not None)

        outbound.append(structure)


    if request_wants_json():
        return jsonify(items=outbound)

    return jsonify(count=str(len(results)),items=outbound)