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 show_submits(request, template_name="receiver/show_submits.html"):
    '''View submissions for this domain.'''
    context = {}
    slogs = Submission.objects.filter(domain=request.user.selected_domain).order_by('-submit_time')
    
    context['submissions'] = paginate(request, slogs)
    return render_to_response(request, template_name, context)
Example #3
0
def show_dupes(request, submission_id, template_name="receiver/show_dupes.html"):
    '''View duplicates of this submission.'''
    context = {}
    submit = get_object_or_404(Submission, id=submission_id)
    if submit.checksum is None or len(submit.checksum) == 0:
        # this error will go away as soon as we update all submissions 
        # to have corresponding checksums
        context['errors'] = "No checksum found. Cannot identify duplicates."
    else:
        slogs = Submission.objects.filter(checksum=submit.checksum).order_by('-submit_time')
        context['submissions'] = paginate(request, slogs)
    return render_to_response(request, template_name, context)
Example #4
0
def case_flat(request, case_id, template_name="case_flat.html"):
    '''A flat view of the topmost data for all cases'''
    context = {}
    case = Case.objects.get(id=case_id)
    
    context['cols'] = case.get_column_names()
    
    data = case.get_topmost_data()
    keys = data.keys()
    keys.sort()
    flattened = []
    for key in keys:
        flattened.append(data[key])
    
    
    context['data'] = paginate(request, flattened)    
    context['case'] = case
    
    return render_to_response(request, template_name, context)
Example #5
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 #6
0
                    if _process(submission, request.POST['action']): 
                        count = count + 1
        else: 
            for i in request.POST.getlist('instance'):
                if 'checked_'+ i in request.POST:
                    submit_id = int(i)
                    submission = Submission.objects.get(id=submit_id)
                    if _process(submission, request.POST['action']): 
                        count = count + 1
        context['status'] = "%s attempted. %s forms processed." % \
                            (request.POST['action'], count)
    inner_qs = SubmissionHandlingOccurrence.objects.all().values('submission_id').query
    orphans = Submission.objects.filter(domain=extuser.domain).exclude(id__in=inner_qs)
    # We could also put a check in here to not display duplicate data
    # using 'if not orphan.is_duplicate()'
    context['submissions'] = paginate(request, orphans )
    return render_to_response(request, template_name, context)

@extuser_required()
@transaction.commit_on_success
def delete_submission(request, submission_id=None, template='receiver/confirm_delete.html'):
    context = {}
    extuser = request.extuser
    submission = get_object_or_404(Submission, pk=submission_id)
    if request.method == "POST":
        if request.POST["confirm_delete"]: # user has confirmed deletion.
            submission.delete()
            logging.debug("Submission %s deleted ", submission_id)
            return HttpResponseRedirect(reverse('show_submits'))
    context['object'] = submission
    context['type'] = 'Submission'
Example #7
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)