コード例 #1
0
ファイル: views.py プロジェクト: iddqd1/django-crowdsourcing
def submission_for_map(request, id):
    template = 'crowdsourcing/submission_for_map.html'
    if request.user.is_staff:
        sub = get_object_or_404(Submission.objects, pk=id)
    else:
        sub = get_object_or_404(Submission.objects, is_public=True, pk=id)
    return render_to_response(template, dict(submission=sub), _rc(request))
コード例 #2
0
def submission_for_map(request, id):
    template = 'crowdsourcing/submission_for_map.html'
    if request.user.is_staff:
        sub = get_object_or_404(Submission.objects, pk=id)
    else:
        sub = get_object_or_404(Submission.objects, is_public=True, pk=id)
    return render_to_response(template, dict(submission=sub), _rc(request))
コード例 #3
0
ファイル: views.py プロジェクト: wmde/do-index
def _survey_submit(request, survey):
    if 'final-submit' in request.POST:
	if survey.require_login and request.user.is_anonymous():
	    # again, the form should only be shown after the user is logged in, but
	    # to be safe...
	    return HttpResponseRedirect(_login_url(request))
	if not hasattr(request, 'session'):
	    return HttpResponse("Cookies must be enabled to use this application.",
				status=httplib.FORBIDDEN)
	if (_entered_no_more_allowed(request, survey)):
	    slug_template = 'crowdsourcing/%s_already_submitted.html' % survey.slug
	    return render_to_response([slug_template,
				       'crowdsourcing/already_submitted.html'],
				      dict(survey=survey),
				      _rc(request))

	forms = forms_for_survey(survey, request)
	if _submit_valid_forms(forms, request, survey):
	    if survey.can_have_public_submissions():
		return _survey_results_redirect(request, survey, thanks=True)
	     return _survey_show_form(request, survey, ())
	else:
	    return _survey_show_form(request, survey, forms)
    else:
	from django.shortcuts import redirect
	redirect('/')
コード例 #4
0
def _survey_show_form(request, survey, forms):
    specific_template = "crowdsourcing/%s_survey_detail.html" % survey.slug
    entered = _user_entered_survey(request, survey)
    return render_to_response(
        [specific_template, "crowdsourcing/survey_detail.html"],
        dict(survey=survey, forms=forms, entered=entered, login_url=_login_url(request), request=request),
        _rc(request),
    )
コード例 #5
0
def _survey_show_form(request, survey, forms):
    specific_template = 'crowdsourcing/%s_survey_detail.html' % survey.slug
    entered = _user_entered_survey(request, survey)
    return render_to_response(
        [specific_template, 'crowdsourcing/survey_detail.html'],
        dict(survey=survey,
             forms=forms,
             entered=entered,
             login_url=_login_url(request),
             request=request), _rc(request))
コード例 #6
0
ファイル: views.py プロジェクト: GiorgioNatili/ntfenervit
def embeded_survey_questions(request, slug):
    survey = _get_survey_or_404(slug, request)
    templates = ['admin/survey/embeded_survey_questions_%s.html' % slug,
                 'admin/survey/embeded_survey_questions.html']
    forms = ()
    if _can_show_form(request, survey):
        forms = forms_for_survey(survey, request)
        if request.method == 'POST':
            if _submit_valid_forms(forms, request, survey):
                forms = ()
    return render_to_string(templates, dict(
        entered=_user_entered_survey(request, survey),
        request=request,
        forms=forms,
        survey=survey,
        login_url=_login_url(request)), _rc(request))
コード例 #7
0
ファイル: views.py プロジェクト: abeltan/django_crowd
def embeded_survey_questions(request, slug):
    survey = _get_survey_or_404(slug, request)
    templates = ['crowdsourcing/embeded_survey_questions_%s.html' % slug,
                 'crowdsourcing/embeded_survey_questions.html']
    forms = ()
    if _can_show_form(request, survey):
        forms = forms_for_survey(survey, request)
        if request.method == 'POST':
            if _submit_valid_forms(forms, request, survey):
                forms = ()
    return render_to_response(templates, dict(
        entered=_user_entered_survey(request, survey),
        request=request,
        forms=forms,
        survey=survey,
        login_url=_login_url(request)), _rc(request))
コード例 #8
0
ファイル: views.py プロジェクト: GiorgioNatili/ntfenervit
def _survey_show_form(request, survey, forms):
    contact = None
    if request.GET.get('email'):
        contacts = Contact.objects.all().filter(email=request.GET.get('email'))
        if contacts.count() > 0:
            contact = contacts[0]
    specific_template = 'admin/survey/%s_survey_detail.html' % survey.slug
    entered = False  #_user_entered_survey(request, survey)
    return render_to_response([specific_template,
                               'admin/survey/survey_detail.html'],
                              dict(survey=survey,
                                   forms=forms,
                                   entered=entered,
                                   login_url=_login_url(request),
                                   contact=contact,
                                   request=request),
                              _rc(request))
コード例 #9
0
def embeded_survey_questions(request, slug):
    survey = _get_survey_or_404(slug, request)
    templates = ["crowdsourcing/embeded_survey_questions_%s.html" % slug, "crowdsourcing/embeded_survey_questions.html"]
    forms = ()
    if _can_show_form(request, survey):
        forms = forms_for_survey(survey, request)
        if request.method == "POST":
            if _submit_valid_forms(forms, request, survey):
                forms = ()
    return render_to_response(
        templates,
        dict(
            entered=_user_entered_survey(request, survey),
            request=request,
            forms=forms,
            survey=survey,
            login_url=_login_url(request),
        ),
        _rc(request),
    )
コード例 #10
0
ファイル: views.py プロジェクト: iddqd1/django-crowdsourcing
def embeded_survey_questions(request, slug):
    survey = _get_survey_or_404(slug, request)
    templates = ['crowdsourcing/embeded_survey_questions_%s.html' % slug,
                 'crowdsourcing/embeded_survey_questions.html']

    crispy_helper = FormHelper()
    crispy_helper.form_tag = False

    forms = ()
    if _can_show_form(request, survey):
        forms = forms_for_survey(survey, request)
        if request.method == 'POST':
            if _submit_valid_forms(forms, request, survey):
                forms = ()
    return render_to_response(templates, dict(
        entered=_user_entered_survey(request, survey),
        request=request,
        forms=forms,
        survey=survey,
        crispy_helper=crispy_helper,
        login_url=_login_url(request)), _rc(request))
コード例 #11
0
def _survey_submit(request, survey):
    if survey.require_login and request.user.is_anonymous():
        # again, the form should only be shown after the user is logged in, but
        # to be safe...
        return HttpResponseRedirect(_login_url(request))
    if not hasattr(request, 'session'):
        return HttpResponse("Cookies must be enabled to use this application.",
                            status=httplib.FORBIDDEN)
    if (_entered_no_more_allowed(request, survey)):
        slug_template = 'crowdsourcing/%s_already_submitted.html' % survey.slug
        return render_to_response(
            [slug_template, 'crowdsourcing/already_submitted.html'],
            dict(survey=survey), _rc(request))

    forms = forms_for_survey(survey, request)

    if _submit_valid_forms(forms, request, survey):
        if survey.can_have_public_submissions():
            return _survey_results_redirect(request, survey, thanks=True)
        return _survey_show_form(request, survey, ())
    else:
        return _survey_show_form(request, survey, forms)
コード例 #12
0
ファイル: views.py プロジェクト: iddqd1/django-crowdsourcing
def _survey_report(request, slug, report, page, templates):
    """ Show a report for the survey. As rating is done in a separate
    application we don't directly check request.GET["sort"] here.
    crowdsourcing_settings.PRE_REPORT is the place for that. """
    if page is None:
        page = 1
    else:
        try:
            page = int(page)
        except ValueError:
            raise Http404
    survey = _get_survey_or_404(slug, request)
    # is the survey anything we can actually have a report on?
    is_public = survey.is_live and survey.can_have_public_submissions()
    if not is_public and not request.user.is_staff:
        raise Http404
    reports = survey.surveyreport_set.all()
    if report:
        report_obj = get_object_or_404(reports, slug=report)
    elif survey.default_report:
        args = {"slug": survey.slug, "report": survey.default_report.slug}
        return HttpResponseRedirect(reverse("survey_report_page_1",
                                    kwargs=args))
    else:
        report_obj = _default_report(survey)

    archive_fields = list(survey.get_public_archive_fields())
    is_staff = request.user.is_staff
    if is_staff:
        submissions = survey.submission_set.all()
        fields = list(survey.get_fields())
    else:
        submissions = survey.public_submissions()
        fields = list(survey.get_public_fields())
    filters = get_filters(survey, request.GET)

    id_field = "crowdsourcing_submission.id"
    if not report_obj.display_individual_results:
        submissions = submissions.none()
    else:
        submissions = extra_from_filters(submissions,
                                         id_field,
                                         survey,
                                         request.GET)
        # If you want to sort based on rating, wire it up here.
        if crowdsourcing_settings.PRE_REPORT:
            pre_report = get_function(crowdsourcing_settings.PRE_REPORT)
            submissions = pre_report(
                submissions=submissions,
                report=report_obj,
                request=request)
        if report_obj.featured:
            submissions = submissions.filter(featured=True)
        if report_obj.limit_results_to:
            submissions = submissions[:report_obj.limit_results_to]
    paginator, page_obj = paginate_or_404(submissions, page)

    page_answers = get_all_answers(
        page_obj.object_list,
        include_private_questions=is_staff)

    pages_to_link = pages_to_link_from_paginator(page, paginator)

    display_individual_results = all([
        report_obj.display_individual_results,
        archive_fields or (is_staff and fields)])
    context = dict(
        survey=survey,
        submissions=submissions,
        paginator=paginator,
        page_obj=page_obj,
        pages_to_link=pages_to_link,
        fields=fields,
        archive_fields=archive_fields,
        filters=filters,
        report=report_obj,
        page_answers=page_answers,
        is_public=is_public,
        display_individual_results=display_individual_results,
        request=request)

    return render_to_response(templates, context, _rc(request))
コード例 #13
0
ファイル: views.py プロジェクト: iddqd1/django-crowdsourcing
def submission(request, id):
    template = 'crowdsourcing/submission.html'
    sub = get_object_or_404(Submission.objects, is_public=True, pk=id)
    return render_to_response(template, dict(submission=sub), _rc(request))
コード例 #14
0
def _survey_report(request, slug, report, page, templates):
    """ Show a report for the survey. As rating is done in a separate
    application we don't directly check request.GET["sort"] here.
    crowdsourcing_settings.PRE_REPORT is the place for that. """
    if page is None:
        page = 1
    else:
        try:
            page = int(page)
        except ValueError:
            raise Http404
    survey = _get_survey_or_404(slug, request)
    # is the survey anything we can actually have a report on?
    is_public = survey.is_live and survey.can_have_public_submissions()
    if not is_public and not request.user.is_staff:
        raise Http404
    reports = survey.surveyreport_set.all()
    if report:
        report_obj = get_object_or_404(reports, slug=report)
    elif survey.default_report:
        args = {"slug": survey.slug, "report": survey.default_report.slug}
        url = reverse("survey_report_page_1", kwargs=args)
        return HttpResponseRedirect(url)
    else:
        report_obj = _default_report(survey)

    archive_fields = list(survey.get_public_archive_fields())
    is_staff = request.user.is_staff
    if is_staff:
        submissions = survey.submission_set.all()
        fields = list(survey.get_fields())
    else:
        submissions = survey.public_submissions()
        fields = list(survey.get_public_fields())
    filters = get_filters(survey, request.GET)

    id_field = "crowdsourcing_submission.id"
    if not report_obj.display_individual_results:
        submissions = submissions.none()
    else:
        submissions = extra_from_filters(submissions, id_field, survey,
                                         request.GET)
        # If you want to sort based on rating, wire it up here.
        if crowdsourcing_settings.PRE_REPORT:
            pre_report = get_function(crowdsourcing_settings.PRE_REPORT)
            submissions = pre_report(submissions=submissions,
                                     report=report_obj,
                                     request=request)
        if report_obj.featured:
            submissions = submissions.filter(featured=True)
        if report_obj.limit_results_to:
            submissions = submissions[:report_obj.limit_results_to]
    paginator, page_obj = paginate_or_404(submissions, page)

    page_answers = get_all_answers(page_obj.object_list,
                                   include_private_questions=is_staff)

    pages_to_link = pages_to_link_from_paginator(page, paginator)

    display_individual_results = all([
        report_obj.display_individual_results, archive_fields
        or (is_staff and fields)
    ])
    context = dict(survey=survey,
                   submissions=submissions,
                   paginator=paginator,
                   page_obj=page_obj,
                   pages_to_link=pages_to_link,
                   fields=fields,
                   archive_fields=archive_fields,
                   filters=filters,
                   report=report_obj,
                   page_answers=page_answers,
                   is_public=is_public,
                   display_individual_results=display_individual_results,
                   request=request)

    return render_to_string(templates, context, _rc(request))
コード例 #15
0
def submission(request, id):
    template = 'crowdsourcing/submission.html'
    sub = get_object_or_404(Submission.objects, is_public=True, pk=id)
    return render_to_response(template, dict(submission=sub), _rc(request))
コード例 #16
0
ファイル: views.py プロジェクト: quinode/pfes
def _survey_report(request, slug, report, page, templates):
    """ Show a report for the survey. As rating is done in a separate
    application we don't directly check request.GET["sort"] here.
    local_settings.PRE_REPORT is the place for that. """
    if page is None:
        page = 1
    else:
        try:
            page = int(page)
        except ValueError:
            raise Http404
    survey = _get_survey_or_404(slug, request)
    # is the survey anything we can actually have a report on?
    is_public = survey.is_live and survey.can_have_public_submissions()
    if not is_public and not request.user.is_staff:
        raise Http404
    reports = survey.surveyreport_set.all()
    if report:
        report_obj = get_object_or_404(reports, slug=report)
    elif survey.default_report:
        args = {"slug": survey.slug, "report": survey.default_report.slug}
        return HttpResponseRedirect(reverse("survey_report_page_1",
                                    kwargs=args))
    else:
        report_obj = _default_report(survey)
    archive_fields = list(survey.get_public_archive_fields())
    is_staff = request.user.is_staff
    if is_staff:
        fields = list(survey.get_fields())
    else:
        fields = list(survey.get_public_fields())
    filters = get_filters(survey, request.GET)
    public = survey.public_submissions()
    id_field = "crowdsourcing_submission.id"
    submissions = extra_from_filters(public, id_field, survey, request.GET)
    # If you want to sort based on rating, wire it up here.
    if local_settings.PRE_REPORT:
        pre_report = get_function(local_settings.PRE_REPORT)
        submissions = pre_report(
            submissions=submissions,
            report=report_obj,
            request=request)
    if report_obj.featured:
        submissions = submissions.filter(featured=True)
    if report_obj.limit_results_to:
        submissions = submissions[:report_obj.limit_results_to]
    if not report_obj.display_individual_results:
        submissions = submissions.none()
    paginator, page_obj = paginate_or_404(submissions, page)
    page_answers = get_all_answers(
        page_obj.object_list,
        include_private_questions=is_staff)
    pages_to_link = []
    for i in range(page - 5, page + 5):
        if 1 <= i <= paginator.num_pages:
            pages_to_link.append(i)
    if pages_to_link[0] > 1:
        pages_to_link = [1, False] + pages_to_link
    if pages_to_link[-1] < paginator.num_pages:
        pages_to_link = pages_to_link + [False, paginator.num_pages]
 
    id_questions = Question.objects.filter(survey__id__exact = survey.pk).values_list('id')
    
    comments_list = {}
    for id in id_questions:
        comments_list[id[0]] = []
    
    reponses = Answer.objects.filter(submission__survey__id__exact = survey.pk).order_by('-id')
    
    liste_reponses = []   
    for reponse in reponses:
        if reponse.comment != '' and reponse.question_id not in liste_reponses:
            auteur = reponse.submission.user.first_name +' '+ reponse.submission.user.last_name
            items = comments_list[reponse.question_id]
            comments_list[reponse.question_id] = items + [[auteur,reponse.comment,]]
            liste_reponses.append(reponse.question_id)
 
    context = dict(
        survey=survey,
        submissions=submissions,
        comments_list=comments_list,
        paginator=paginator,
        page_obj=page_obj,
        pages_to_link=pages_to_link,
        fields=fields,
        archive_fields=archive_fields,
        filters=filters,
        report=report_obj,
        page_answers=page_answers,
        is_public=is_public,
        request=request)
    return render_to_response(templates, context, _rc(request))