Пример #1
0
def _get_submissions(manager,questionnaire_code, request,paginate=True):
    request_bag = request.GET
    start_time = request_bag.get("start_time") or ""
    end_time = request_bag.get("end_time") or ""
    start_time_epoch = convert_to_epoch(helper.get_formatted_time_string(start_time.strip() + START_OF_DAY))
    end_time_epoch = convert_to_epoch(helper.get_formatted_time_string(end_time.strip() + END_OF_DAY))
    if paginate:
        current_page = int(request_bag.get('page_number') or 1)
        count, results = _load_submissions_for_page(manager,current_page, questionnaire_code,
                                                start_time_epoch,end_time_epoch)
    else:
        count, results = _load_all_submissions(manager,questionnaire_code,start_time_epoch,end_time_epoch)

    error_message = "No submissions present for this project" if not count else None
    return count,results,error_message
Пример #2
0
def _map(dbm, type_path, group_level, form_code=None, start_time=None, end_time=None):
# currently it assumes one to one mapping between form code and entity type and hence only filter on form code
    view_name = "by_form_code_time"
    epoch_start = convert_to_epoch(start_time)
    epoch_end = convert_to_epoch(end_time)
    start_key = [form_code, epoch_start] if epoch_start is not None else [form_code]
    end_key = [form_code, epoch_end] if epoch_end is not None else [form_code, {}]
    rows = dbm.load_all_rows_in_view(view_name, startkey=start_key, endkey=end_key)
    values = []
    for row in rows:
        form_code, timestamp, entity_id, field = row.key
        values.append(([entity_id, field], row.value))

    transformed_values = defaultdict(list)
    for key, value in values:
        transformed_values[tuple(key)].append(value)

    return transformed_values
Пример #3
0
def _get_submissions(manager, questionnaire_code, request, paginate=True):
    request_bag = request.GET
    start_time = request_bag.get("start_time") or ""
    end_time = request_bag.get("end_time") or ""
    start_time_epoch = convert_to_epoch(
        helper.get_formatted_time_string(start_time.strip() + START_OF_DAY))
    end_time_epoch = convert_to_epoch(
        helper.get_formatted_time_string(end_time.strip() + END_OF_DAY))
    if paginate:
        current_page = int(request_bag.get('page_number') or 1)
        count, results = _load_submissions_for_page(manager, current_page,
                                                    questionnaire_code,
                                                    start_time_epoch,
                                                    end_time_epoch)
    else:
        count, results = _load_all_submissions(manager, questionnaire_code,
                                               start_time_epoch,
                                               end_time_epoch)

    error_message = "No submissions present for this project" if not count else None
    return count, results, error_message
Пример #4
0
def _end_time_filter(row, end_time):
    if end_time is None:
        return True
    epoch = convert_to_epoch(end_time)
    return row.key[BY_VALUES_EVENT_TIME_INDEX] <= epoch