Example #1
0
def getRebuildData(request):
    """
    Returns form metadata for rebuilding via AJAX
    """
    if request.is_ajax():
        if request.method == 'GET':
            try:
                form_id = int(request.GET['form_id'])
            except ValueError:
                return HttpResponse(status=400)
            form = Form.objects.get(pk=form_id)
            fh = FormHandler(form=form, request=request)
            metadata = json.dumps(fh.rebuildData())
            return HttpResponse(metadata)
    return HttpResponse(status=400)
Example #2
0
def getData(request):
    """
    Returns response data via Ajax
    """
    if request.is_ajax():
        if request.method == 'GET':
            try:
                form_id = int(request.GET['form_id'])
            except ValueError:
                return HttpResponse(status=400)
            form = Form.objects.get(pk=form_id)
            fh = FormHandler(form=form, request=request)
            resp_data = json.dumps(fh.getResponseData(form))
            return HttpResponse(resp_data)
    return HttpResponse(status=400)
Example #3
0
def viewForm(request, form_id):
    """
    Form viewing and submission
    """
    try:
        form_id = int(form_id)
        form = Form.objects.get(pk=form_id)
    except (ValueError, Form.DoesNotExist):
        raise Http404

    perm, error_text = hasPerm(request.user, form)
    if not perm:
        return render_to_response('customforms/error.html', request,
                                  {'error_text': error_text})
    fh = FormHandler(form=form, request=request, user=request.user)

    return fh.get_wizard_view()
Example #4
0
def getExcelData(request, form_id):
    """
    Returns the response data as an excel spreadsheet
    """

    try:
        form_id = int(form_id)
    except ValueError:
        return HttpResponse(status=400)

    form = Form.objects.get(pk=form_id)
    fh = FormHandler(form=form, request=request)
    wbk = fh.getResponseExcel()
    response = HttpResponse(wbk.getvalue(),
                            content_type="application/vnd.ms-excel")
    response[
        'Content-Disposition'] = 'attachment; filename=%s.xls' % form.title
    return response
Example #5
0
def viewForm(request, form_id):
    """
    Form viewing and submission
    """
    try:
        form_id = int(form_id)
    except ValueError:
        raise Http404

    form = Form.objects.get(pk=form_id)

    perm, error_text = hasPerm(request.user, form)
    if not perm:
        return render_to_response('customforms/error.html',
                                  {'error_text': error_text},
                                  context_instance=RequestContext(request))
    fh = FormHandler(form=form, request=request, user=request.user)

    return fh.get_wizard_view()
 def quiz(self, request, tl, one, two, module, extra, prog):
 
     custom_form_id = Tag.getProgramTag('quiz_form_id', prog, None)
     if custom_form_id:
         cf = Form.objects.get(id=int(custom_form_id))
     else:
         raise ESPError('Cannot find an appropriate form for the quiz.  Please ask your administrator to create a form and set the quiz_form_id Tag.')
     
     form_wizard = FormHandler(cf, request, request.user).get_wizard()
     form_wizard.curr_request = request
 
     if request.method == 'POST':
         form = form_wizard.get_form(0, request.POST, request.FILES)
         if form.is_valid():
             form_wizard.done([form])
             self.controller.markCompleted(request.user)
             return self.goToCore(tl)
     else:
         form = form_wizard.get_form(0)
         
     return render_to_response(self.baseDir()+'quiz.html', request, {'prog':prog, 'form': form})