Exemple #1
0
def get_picture_objects_for_group(group_id):
    """
    Gets all the pictures belonging to a group, groups them in an array under the snaps they belong to
    """
    url_base = get_url_base()
    picture_links = []
    args_dict = {}
    snaps_dict = {}
    snaps = []
    args_dict["type"] = "picture"
    args_dict["group_id"] = group_id
    pictures_dict = get_documents_from_criteria(args_dict)
    for picture_id in pictures_dict:
        picture_link = url_base + url_for("picture.get_picture", picture_id=picture_id)
        snap_id = pictures_dict[picture_id]["snap_id"]
        if snap_id in snaps_dict:
            snaps_dict[snap_id]["picture_objects"].append(pictures_dict[picture_id])
        else:
            snaps_dict[snap_id] = {
                "created": pictures_dict[picture_id]["created"],
                "id": snap_id,
                "picture_objects": [pictures_dict[picture_id]],
            }
    snaps_array = snaps_dict.values()
    snaps_array.sort(key=lambda x: x["created"])
    return snaps_array
Exemple #2
0
def search_generic(document_type='', args_dict={}):
    '''
    Finds all documents of the specified type matching the parameters passed in with the wargs dict
    It's just a wrapper around get_documents_from_criteria
    THIS CAN THROW EXCEPTIONS, it needs to run within a try except block
    '''
    if request is not None and 'args' in dir(request): # only gather parms if we have a request context
        the_dict = gather_and_enforce_request_args(['ANY_SEARCHABLE'])
        for key in the_dict:
            args_dict[key] = the_dict[key]
    args_dict['type'] = document_type
    documents_dict = get_documents_from_criteria(args_dict)
    return documents_dict
Exemple #3
0
    def test_get_documents_from_criteria_recognizes_gallery_url_not_noll_kwarg(self):
        id_1 = str(uuid.uuid4())
        the_doc = {'doctor': 'strangelove', 'gallery_url': 'something'}
        current_app.db[id_1] = the_doc
        id_2 = str(uuid.uuid4())
        the_doc = {'doctor': 'strangelove'}
        current_app.db[id_2] = the_doc

        args_dict = {'doctor': 'strangelove', 'gallery_url_not_null': True}

        documents = tu.get_documents_from_criteria(args_dict)

        assert len(documents.keys()) == 1
        assert id_1 in documents
Exemple #4
0
def get_picture_links_for_group(group_id):
    '''
    Gets all the pictures belonging to a given group id
    '''
    # TODO sort these ascending on time
    url_base = get_url_base()
    picture_links = []
    args_dict = {}
    args_dict['type'] = 'picture'
    args_dict['group_id'] = group_id
    pictures_dict = get_documents_from_criteria(args_dict)
    for picture_id in pictures_dict:
        picture_link = url_base + url_for('picture.get_picture', picture_id=picture_id)
        picture_links.append(picture_link)
    return picture_links
Exemple #5
0
def get_picture_links_for_group(group_id):
    """
    Gets all the pictures belonging to a given group id
    """
    # TODO sort these ascending on time
    url_base = get_url_base()
    picture_links = []
    args_dict = {}
    args_dict["type"] = "picture"
    args_dict["group_id"] = group_id
    pictures_dict = get_documents_from_criteria(args_dict)
    for picture_id in pictures_dict:
        picture_link = url_base + url_for("picture.get_picture", picture_id=picture_id)
        picture_links.append(picture_link)
    return picture_links
Exemple #6
0
    def test_get_documents_from_criteria_recognizes_gallery_url_not_noll_kwarg(
            self):
        id_1 = str(uuid.uuid4())
        the_doc = {'doctor': 'strangelove', 'gallery_url': 'something'}
        current_app.db[id_1] = the_doc
        id_2 = str(uuid.uuid4())
        the_doc = {'doctor': 'strangelove'}
        current_app.db[id_2] = the_doc

        args_dict = {'doctor': 'strangelove', 'gallery_url_not_null': True}

        documents = tu.get_documents_from_criteria(args_dict)

        assert len(documents.keys()) == 1
        assert id_1 in documents
Exemple #7
0
    def test_get_documents_from_criteria_fetches_by_arbitrary_criterion(self):
        id_1 = str(uuid.uuid4())
        the_doc = {'doctor': 'strangelove'}
        current_app.db[id_1] = the_doc
        id_2 = str(uuid.uuid4())
        the_doc = {'doctor': 'demento'}
        current_app.db[id_2] = the_doc
        id_3 = str(uuid.uuid4())
        the_doc = {'doctor': 'detroit'}
        current_app.db[id_3] = the_doc
        args_dict = {'doctor': 'demento'}

        documents = tu.get_documents_from_criteria(args_dict)

        assert len(documents.keys()) == 1
        assert id_2 in documents
Exemple #8
0
    def test_get_documents_from_criteria_fetches_by_arbitrary_criterion(self):
        id_1 = str(uuid.uuid4())
        the_doc = {'doctor': 'strangelove'}
        current_app.db[id_1] = the_doc
        id_2 = str(uuid.uuid4())
        the_doc = {'doctor': 'demento'}
        current_app.db[id_2] = the_doc
        id_3 = str(uuid.uuid4())
        the_doc = {'doctor': 'detroit'}
        current_app.db[id_3] = the_doc
        args_dict = {'doctor': 'demento'}

        documents = tu.get_documents_from_criteria(args_dict)

        assert len(documents.keys()) == 1
        assert id_2 in documents
Exemple #9
0
def get_picture_objects_for_group(group_id):
    '''
    Gets all the pictures belonging to a group, groups them in an array under the snaps they belong to
    '''
    url_base = get_url_base()
    picture_links = []
    args_dict = {}
    snaps_dict = {}
    snaps = []
    args_dict['type'] = 'picture'
    args_dict['group_id'] = group_id
    pictures_dict = get_documents_from_criteria(args_dict)
    for picture_id in pictures_dict:
        picture_link = url_base + url_for('picture.get_picture', picture_id=picture_id)
        snap_id =  pictures_dict[picture_id]['snap_id']
        if snap_id in snaps_dict:
            snaps_dict[snap_id]['picture_objects'].append(pictures_dict[picture_id])
        else:
            snaps_dict[snap_id] = {'created': pictures_dict[picture_id]['created'],
                                   'id': snap_id,
                                   'picture_objects': [pictures_dict[picture_id]]}
    snaps_array = snaps_dict.values()
    snaps_array.sort(key=lambda x: x['created'])
    return snaps_array
Exemple #10
0
def find_pictures(args_dict, **kwargs):
    args_dict['type'] = 'picture'
    pictures_dict = get_documents_from_criteria(args_dict, **kwargs)
    return pictures_dict
Exemple #11
0
def find_calibration_sessions(args_dict):
    args_dict['type'] = 'calibration_session'
    calibration_sessions_dict = get_documents_from_criteria(args_dict)
    return calibration_sessions_dict
Exemple #12
0
def find_distortion_pairs(args_dict):
    args_dict['type'] = 'distortion_pair'
    distortion_pairs_dict = get_documents_from_criteria(args_dict)
    return distortion_pairs_dict
Exemple #13
0
def find_calibration_sessions(args_dict):
    args_dict['type'] = 'calibration_session'
    calibration_sessions_dict = get_documents_from_criteria(args_dict)
    return calibration_sessions_dict
Exemple #14
0
def find_distortion_pairs(args_dict):
    args_dict['type'] = 'distortion_pair'
    distortion_pairs_dict = get_documents_from_criteria(args_dict)
    return distortion_pairs_dict
Exemple #15
0
def find_pictures(args_dict, **kwargs):
    args_dict['type'] = 'picture'
    pictures_dict = get_documents_from_criteria(args_dict, **kwargs)
    return pictures_dict