Beispiel #1
0
def questionnaire(request, slug):
    '''GET always gives you the questionnaire as json file. POST is accepted
    when the survey is not initialized for sending in the questionnaire draft
    via the editor. The json gets written as latex and then rendered for the
    editor preview.'''
    survey = get_survey_or_404(request, slug, change=True)

    # Get CSRF token, so that cookie will be included
    csrf.get_token(request)

    if request.method == 'POST':
        if survey.initialized:
            raise Http404
        else:
            survey.questionnaire = request.read()
            survey.save()

            survey_id = str(survey.id)
            if tasks.write_questionnaire.apply_async(args=(survey_id, )):
                tasks.render_questionnaire.apply_async(args=(survey_id, ))
            return HttpResponse(status=202)

    elif request.method == 'GET':
        return HttpResponse(survey.questionnaire,
                            content_type="application/json")
Beispiel #2
0
def edit(request, survey_id):
    survey = get_survey_or_404(request, survey_id, change=True)

    # Get CSRF token, so that cookie will be included
    csrf.get_token(request)

    # XXX: Nicer error message?
    if survey.initialized:
        raise Http404

    if request.method == "POST":
        # We want to update the survey from the form
        form = forms.SurveyForm(request.POST, instance=survey)

        if form.is_valid():
            form.save()
            tasks.queue_timed_write_and_render(survey)
    else:
        form = forms.SurveyForm(instance=survey)

    context_dict = {
        'main_form' : form,
        'survey' : survey,
    }

    return render(request, 'edit_questionnaire.html', context_dict)
Beispiel #3
0
def survey_review_sheet(request, slug, sheet):
    djsurvey = get_survey_or_404(request, slug, review=True)

    # Get CSRF token, so that cookie will be included
    csrf.get_token(request)

    sheet = int(sheet)

    # XXX: Throw sane error in this case!
    #if djsurvey.active_task:
    #    raise Http404

    if not djsurvey.initialized:
        raise Http404

    # Now this is getting hairy, we need to unpickle the data :-(
    #with models.LockedSurvey(djsurvey.id, 5):

    survey = SDAPSSurvey.load(djsurvey.path)

    try:
        survey.goto_nth_sheet(sheet)
    except:
        raise Http404

    if request.method == 'POST':
        post_data = json.loads(request.read())
        data = post_data['data']

        survey.questionnaire.sdaps_ctl.set_data(data)

        survey.save()

    # Assume image is NUMBER.tif
    res = {
        'images': [{
            'image':
            int(image.filename[:-4]),
            'image_page':
            image.tiff_page,
            'page':
            image.page_number if image.survey_id == survey.survey_id else -1,
            'rotated':
            image.rotated,
            'pxtomm':
            tuple(image.matrix.px_to_mm()),
            'mmtopx':
            tuple(image.matrix.mm_to_px()),
        } for image in survey.sheet.images if not image.ignored],
        'data':
        survey.questionnaire.sdaps_ctl.get_data()
    }

    return HttpResponse(json.dumps(res), content_type="application/json")
Beispiel #4
0
def survey_upload(request, slug):
    survey = get_survey_or_404(request, slug, upload=True)

    csrf.get_token(request)

    if not survey.initialized:
        raise Http404

    context_dict = {
        'survey' : survey,
    }

    return render(request, 'survey_upload.html', context_dict)
Beispiel #5
0
def survey_upload(request, slug):
    survey = get_survey_or_404(request, slug, upload=True)

    csrf.get_token(request)

    if not survey.initialized:
        raise Http404

    context_dict = {
        'survey': survey,
    }

    return render(request, 'survey_upload.html', context_dict)
Beispiel #6
0
def survey_review_sheet(request, slug, sheet):
    djsurvey = get_survey_or_404(request, slug, review=True)

    # Get CSRF token, so that cookie will be included
    csrf.get_token(request)

    sheet = int(sheet)

    # XXX: Throw sane error in this case!
    #if djsurvey.active_task:
    #    raise Http404

    if not djsurvey.initialized:
        raise Http404

    # Now this is getting hairy, we need to unpickle the data :-(
    #with models.LockedSurvey(djsurvey.id, 5):

    survey = SDAPSSurvey.load(djsurvey.path)

    try:
        survey.goto_nth_sheet(sheet)
    except:
        raise Http404

    if request.method == 'POST':
        post_data = json.loads(request.read())
        data = post_data['data']

        survey.questionnaire.sdaps_ctl.set_data(data)

        survey.save()

    # Assume image is NUMBER.tif
    res = {
        'images' : [
            {
                'image' : int(image.filename[:-4]),
                'image_page' : image.tiff_page,
                'page' : image.page_number if image.survey_id == survey.survey_id else -1,
                'rotated' : image.rotated,
                'pxtomm' : tuple(image.matrix.px_to_mm()),
                'mmtopx' : tuple(image.matrix.mm_to_px()),
            } for image in survey.sheet.images if not image.ignored
        ],
        'data' : survey.questionnaire.sdaps_ctl.get_data()
    }

    return HttpResponse(json.dumps(res), content_type="application/json")
Beispiel #7
0
def add(request, orgID):
    if request.method == "GET":
        form = EventForm()

        csrf_token = get_token(request)
        csrf_token_html = '<input type="hidden" name="csrfmiddlewaretoken" value="{}" />'.format(
            csrf_token)

        return HttpResponse("<form method='post'>" + form.as_ul() +
                            csrf_token_html + "<input type='submit'></form>")

    elif request.method == "POST":
        # TODO: Do some validation
        form = EventForm(request.POST)

        if form.is_valid():
            organization = Organization.objects.filter(id=orgID)

            if len(organization) > 0:
                organization = organization[0]

                if organization in request.user.student.organizations.all():
                    event = form.save()
                    event.owner = request.user.username
                    event.save()
                    event.organizations.add(organization)

                    return HttpResponse("Success")

    return HttpResponse("Fail")
Beispiel #8
0
def update(request, id):
    updatingEvent = Event.objects.filter(id=id)

    if len(updatingEvent) > 0:
        updatingEvent = updatingEvent[0]

        if request.method == "GET":
            form = EventForm(instance=updatingEvent)

            csrf_token = get_token(request)
            csrf_token_html = '<input type="hidden" name="csrfmiddlewaretoken" value="{}" />'.format(
                csrf_token)

            return HttpResponse("<form method='post'>" + form.as_ul() +
                                csrf_token_html +
                                "<input type='submit'></form>")

        elif request.method == "POST":
            form = EventForm(request.POST, instance=updatingEvent)

            for organization in form.organizations.all():
                if organization in request.user.student.organizations.all():
                    form.save()
                    return HttpResponse("Success")

    return HttpResponse("No Event Found")
Beispiel #9
0
def questionnaire(request, survey_id):
    survey = get_survey_or_404(request, survey_id, change=True)

    # Get CSRF token, so that cookie will be included
    csrf.get_token(request)

    # XXX: Nicer error message?
    if survey.initialized:
        raise Http404

    if request.method == 'POST':
        survey.questionnaire = request.read()
        survey.save()
        tasks.queue_timed_write_and_render(survey)

    return HttpResponse(survey.questionnaire, content_type="application/json")
Beispiel #10
0
def survey_upload(request, survey_id):
    survey = get_survey_or_404(request, survey_id, upload=True)

    # XXX: Throw sane error in this case!
    if survey.active_task:
        raise Http404

    csrf.get_token(request)

    if not survey.initialized:
        raise Http404

    context_dict = {
        'survey' : survey,
    }

    return render(request, 'survey_upload.html', context_dict)
Beispiel #11
0
def feedback(request, event_id):
    """Feedback page to receive feedback using WebSockets."""
    # Get a list of rooms, ordered alphabetically
    csrf = get_token(request)
    rooms = Room.objects.order_by("title")
    event = Event.objects.get(id=event_id)
    ctx_dict = {"rooms": rooms, "event":event , "csrf" : csrf}
    return render(request, "feedback/feedback.html", ctx_dict)
Beispiel #12
0
    def get(self, request):
        consumed = Consumer('parse').get()

        if consumed is not None:
            consumed = {
                **consumed,
                'csrfmiddlewaretoken': get_token(request),
            }

        return JsonResponse(consumed, safe=False)
Beispiel #13
0
def index(request):
    print("Entrando a la funcion index")
    http_msg = ""

    csrf_token = get_token(request)

    if request.method == 'GET':
        url_stored = NewURL.objects.all()

        for url in url_stored:
            http_msg += ("<tr><td><a href=" + url.URL_long + ">" +
                         url.URL_long + "</a></td>" + "<td><a href=" +
                         url.URL_short + ">" + url.URL_short + "</a>" +
                         "</td></tr>")

        return HttpResponse(
            PAGE_MAIN_GET.format(token=csrf_token, table=http_msg))

    elif request.method == 'POST':
        try:
            url = request.POST['url']
        except KeyError:
            http_msg = (
                "El formulario introducido no proviene de la pagina correcta."
                + "Se redirigira a la pagina principal")

            return HttpResponseBadRequest(
                PAGE_ERROR.format(port=request.META['SERVER_PORT'],
                                  msg=http_msg))

        url_to_add = check_url(url)

        if NewURL.objects.filter(URL_long=url_to_add).exists():
            url_short = NewURL.objects.get(URL_long=url_to_add).URL_short
        else:
            url_count = NewURL.objects.count()
            url_short = "http://127.0.0.1:" + request.META[
                'SERVER_PORT'] + "/" + str(url_count)
            new_url_obj = NewURL(URL_long=url_to_add, URL_short=url_short)
            new_url_obj.save()

        return HttpResponse(
            PAGE_RETURN_URL.format(url1=url_to_add, url2=url_short))

    else:
        http_msg = "El metodo enviado no esta soportado por el servidor. Se redirigira a la pagina principal"

        return HttpResponseNotAllowed(
            PAGE_ERROR.format(port=request.META['SERVER_PORT'], msg=http_msg))
Beispiel #14
0
def questionnaire(request, slug):
    '''GET always gives you the questionnaire as json file. POST is accepted
    when the survey is not initialized for sending in the questionnaire draft
    via the editor. The json gets written as latex and then rendered for the
    editor preview.'''
    survey = get_survey_or_404(request, slug, change=True)

    # Get CSRF token, so that cookie will be included
    csrf.get_token(request)

    if request.method == 'POST':
        if survey.initialized:
            raise Http404
        else:
            survey.questionnaire = request.read()
            survey.save()

            survey_id = str(survey.id)
            if tasks.write_questionnaire.apply_async(args=(survey_id, )):
                tasks.render_questionnaire.apply_async(args=(survey_id, ))
            return HttpResponse(status=202)

    elif request.method == 'GET':
        return HttpResponse(survey.questionnaire, content_type="application/json")
Beispiel #15
0
def createUser(request):
	if request.method == "GET":
		form = UserCreationForm()
		
		csrf_token = get_token(request)
		csrf_token_html = '<input type="hidden" name="csrfmiddlewaretoken" value="{}" />'.format(csrf_token)

		return HttpResponse("<form method='post'>" + form.as_ul() + csrf_token_html + "<input type='submit'></form>")
		
	elif request.method == "POST":
		form = UserCreationForm(request.POST)
	
		if form.is_valid():
			user = form.save()
			student = Student.objects.create(user=user)
			return HttpResponse("Success")

	return HttpResponse("Fail")
Beispiel #16
0
def loginUser(request):
	if request.method == "GET":
		form = LoginForm()
		
		csrf_token = get_token(request)
		csrf_token_html = '<input type="hidden" name="csrfmiddlewaretoken" value="{}" />'.format(csrf_token)

		return HttpResponse("<form method='post'>" + form.as_ul() + csrf_token_html + "<input type='submit'></form>")
	else:
		username = request.POST["username"]
		password = request.POST["password"]
	
		user = authenticate(request, username=username,password=password)

		if user != None:
			login(request,user)
			return HttpResponse("Success")
		
	return HttpResponse("Fail")
Beispiel #17
0
def createOrg(request):
    if request.method == "GET":
        form = OrganizationForm()

        csrf_token = get_token(request)
        csrf_token_html = '<input type="hidden" name="csrfmiddlewaretoken" value="{}" />'.format(
            csrf_token)

        return HttpResponse("<form method='post'>" + form.as_ul() +
                            csrf_token_html + "<input type='submit'></form>")

    elif request.method == "POST":
        # TODO: Do some validation
        form = OrganizationForm(request.POST)

        if form.is_valid():
            form.save()
            return HttpResponse("Success")
        else:
            return HttpResponse("Fail")
Beispiel #18
0
def get_csrf_token(request):
    return csrf.get_token(request)
Beispiel #19
0
def token_csrf(request):
    return JsonResponse({
        'status': 'success',
        'csrf_token': get_token(request)
    })
Beispiel #20
0
def get_csrf_token(request):
    return HttpResponse(get_token(request))
def get_csrf(request):
    return HttpResponse("{0}".format(csrf.get_token(request)), content_type="text/plain")
Beispiel #22
0
def init(request):
    return JsonResponse({"result": get_token(request)})
Beispiel #23
0
def token_csrf(request):
    return JsonResponse({'status': 'success', 'csrf_token': get_token(request)})