Example #1
0
def metadata(request, domain=None):
    '''Submission Summary List for All Forms'''
    if not domain:
        domain = request.user.selected_domain
    # extract params from the URL
    
    items, sort_column, sort_descending, filters =\
         get_table_display_properties(request)
    filters["attachment__submission__domain"] = domain
    columns = [["formdefmodel", "Form"],
               ["deviceid", "Device"],
               ["chw_id", "User Id"],
               ["username", "User Name"],
               ["timestart", "Started"],
               ["timeend", "Ended"]]

    all_meta = get_query_set(Metadata, sort_column, sort_descending, filters)
    paginated_meta = paginate(request, all_meta, items)
    return render_to_string("custom/all/metadata.html", 
                            {"MEDIA_URL": settings.MEDIA_URL, # we pretty sneakly have to explicitly pass this
                             "columns": columns, 
                             "all_metadata": paginated_meta,
                             "sort_column": sort_column,
                             "sort_descending": sort_descending,
                             "filters": filters })
Example #2
0
def form_data_group(req, group_id):
    group = get_object_or_404(FormDataGroup, id=group_id)
    items, sort_column, sort_descending, filters =\
         get_table_display_properties(req,default_sort_column = None,
                                      default_sort_descending = False)
    cursor = group.get_data(sort_column, sort_descending)
    columns = get_column_names(cursor)
    if sort_column:
        sort_index = columns.index(sort_column)
    else:
        sort_index = -1
    data = paginate(req, cursor.fetchall())
    extra_params = "&".join(['%s=%s' % (key, value)\
                             for key, value in req.GET.items()\
                             if key != "page"])
    return render_to_response(req, "xformmanager/form_data_group.html",
                              {"group": group, "columns": columns, 
                               "data": data, "sort_column": sort_column,
                               "sort_descending": sort_descending,
                               "sort_index": sort_index, 
                               "extra_params": extra_params, 
                               "editing": False })
Example #3
0
def data(request, formdef_id, template_name="data.html", context={}, use_blacklist=True):
    '''View the xform data for a particular schema.  Accepts as
       url parameters the following (with defaults specified):
       items: 25 (the number of items to paginate at a time
       page: 1 (the page you are on)
       sort_column: id (?) (the column to sort by)
       sort_descending: True (?) (the sort order of the column)
       ''' 
    # clear the context
    # (because caching on the browsers sometimes prevents this from being
    # reset properly)
    context = {}
    xform = get_object_or_404(FormDefModel, id=formdef_id)
    
    default_sort_column = "id"
    # extract params from the URL
    items, sort_column, sort_descending, filters =\
         get_table_display_properties(request,default_sort_column = default_sort_column)

    columns = xform.get_column_names()
    if not sort_column in columns:
        context["errors"] = "Sorry, we currently can't sort by the column '%s' and have sorted by the default column, '%s', instead."  %\
                        (sort_column, default_sort_column)
        sort_column = default_sort_column

    column_filters = []
    
    # pare down list of filters by only those items which are in the allowed list of 
    # columns
    clean_filters = {}
    for key, value in filters.items():
        if key in columns:
             clean_filters[key] = value
    if clean_filters:
        column_filters = [[key, "=", value] for key, value in clean_filters.items()]
        # context['filters'] will be displayed
        context['filters'] = "&".join(['%s=%s' % (key, value)
                                            for key, value
                                            in clean_filters.items()])
        
        # hacky way of making sure that the first already-filtered field
        # does not show up as a filter link - todo: clean up later
        context['filtered_by'] = clean_filters.keys()[0]
    
    if use_blacklist:
        blacklist_users = BlacklistedUser.for_domain(request.user.selected_domain)
        rows = xform.get_rows(sort_column=sort_column, sort_descending=sort_descending, 
                              blacklist=blacklist_users, column_filters=column_filters)
    else:
        rows = xform.get_rows(sort_column=sort_column, sort_descending=sort_descending, 
                              column_filters=column_filters)
    context["sort_index"] = columns.index(sort_column)
    context['columns'] = columns 
    context['form_name'] = xform.form_name
    context['xform'] = xform
    context['sort_descending'] = sort_descending
    context['data'] = paginate(request, rows, rows_per_page=items)

    # python! rebuild the query string, removing the "page" argument so it can
    # be passed on when paginating.
    context['param_string_no_page'] = "&".join(['%s=%s' % (key, value)\
                                                for key, value in request.GET.items()\
                                                if key != "page"])
    context['sort_params'] = "&".join(['%s=%s' % (key, value)
                                        for key, value in request.GET.items()\
                                        if key.startswith("sort")])
    return render_to_response(request, template_name, context)