コード例 #1
0
def survey(request, survey_slug=None, template='survey/survey.html'):
    if request.GET.get('id', None) is not None and request.GET.get(
            'return', None) is not None:
        survey = get_object_or_404(
            Survey, slug='puget-sound-coastal-recreation-survey', anon=True)
        respondant, created = Respondant.objects.get_or_create(
            survey=survey, uuid=request.GET.get('id'))
        respondant.gfk_returnURL = request.GET.get('return')
        respondant.save()
        return redirect(
            "/respond#/survey/puget-sound-coastal-recreation-survey/%s" %
            (respondant.uuid))
    elif survey_slug is not None:
        survey = get_object_or_404(Survey, slug=survey_slug, anon=True)
        respondant = Respondant(survey=survey)
        respondant.save()
        if request.GET.get('get-uid', None) is not None:
            return HttpResponse(
                simplejson.dumps({
                    'success': "true",
                    "uuid": respondant.uuid
                }))
        return redirect("/respond#/survey/%s/%s" %
                        (survey.slug, respondant.uuid))
    context = {'ANALYTICS_ID': settings.ANALYTICS_ID}
    return render_to_response(template, RequestContext(request, context))
コード例 #2
0
ファイル: views.py プロジェクト: cheryltchen/geosurvey
def survey(request, survey_slug=None, template='survey/survey.html'):
    if survey_slug is not None:
        survey = get_object_or_404(Survey, slug=survey_slug, anon=True)
        respondant = Respondant(survey=survey)
        respondant.save()
        if request.GET.get('get-uid', None) is not None:
            return HttpResponse(simplejson.dumps({'success': "true", "uuid": respondant.uuid}))
        return redirect("/respond#/survey/%s/%s" % (survey.slug, respondant.uuid))
    return render_to_response(template, RequestContext(request, {}))
コード例 #3
0
ファイル: views.py プロジェクト: point97/survey-ost
def survey(request, survey_slug=None, template='survey/survey.html'):
    if survey_slug is not None:
        survey = get_object_or_404(Survey, slug=survey_slug, anon=True)
        respondant = Respondant(survey=survey, user=request.user)
        respondant.save()
        if request.GET.get('get-uid', None) is not None:
            return HttpResponse(simplejson.dumps({'success': "true", "uuid": respondant.uuid}))
        return redirect("/respond#/survey/%s/0/%s/landing" % (survey.slug, respondant.uuid))
    context = {'ANALYTICS_ID': settings.ANALYTICS_ID}
    return render_to_response(template, RequestContext(request, context))
コード例 #4
0
ファイル: views.py プロジェクト: twelch/hapifis
def dash(request, survey_slug=None, template='survey/dash.html'):
    if survey_slug is not None:
        survey = get_object_or_404(Survey, slug=survey_slug, anon=True)
        respondant = Respondant(survey=survey)
        respondant.save()
        if request.GET.get('get-uid', None) is not None:
            return HttpResponse(simplejson.dumps({'success': "true", "uuid": respondant.uuid}))
        return redirect("/respond#/survey/%s/%s" % (survey.slug, respondant.uuid))

    return render_to_response(template, RequestContext(request, {'api_key': request.user.api_key.key}))
コード例 #5
0
ファイル: views.py プロジェクト: twelch/hapifis
def survey(request, survey_slug=None, template='survey/survey.html'):
    if survey_slug is not None:
        survey = get_object_or_404(Survey, slug=survey_slug, anon=True)
        respondant = Respondant(survey=survey, surveyor=request.user)
        respondant.save()
        if request.GET.get('get-uid', None) is not None:
            return HttpResponse(simplejson.dumps({'success': "true", "uuid": respondant.uuid}))
        return redirect("/respond#/survey/%s/%s" % (survey.slug, respondant.uuid))
    context = {'ANALYTICS_ID': settings.ANALYTICS_ID}
    return render_to_response(template, RequestContext(request, context))
コード例 #6
0
ファイル: views.py プロジェクト: point97/puget-sound
def survey(request, survey_slug=None, template='survey/survey.html'):
    if request.GET.get('id', None) is not None and request.GET.get('return', None) is not None:
        survey = get_object_or_404(Survey, slug='puget-sound-coastal-recreation-survey', anon=True)
        respondant, created = Respondant.objects.get_or_create(survey=survey, uuid=request.GET.get('id'))
        respondant.gfk_returnURL = request.GET.get('return')
        respondant.save()
        return redirect("/respond#/survey/puget-sound-coastal-recreation-survey/%s" % (respondant.uuid))
    elif survey_slug is not None:
        survey = get_object_or_404(Survey, slug=survey_slug, anon=True)
        respondant = Respondant(survey=survey)
        respondant.save()
        if request.GET.get('get-uid', None) is not None:
            return HttpResponse(simplejson.dumps({'success': "true", "uuid": respondant.uuid}))
        return redirect("/respond#/survey/%s/%s" % (survey.slug, respondant.uuid))
    context = {'ANALYTICS_ID': settings.ANALYTICS_ID}
    return render_to_response(template, RequestContext(request, context))
コード例 #7
0
ファイル: views.py プロジェクト: wraithan/solomon
def surveyor_stats_json(request, survey_slug, interval):
    form = SurveyorStatsForm(request.GET)
    if not form.is_valid():
        return _error(**form.errors)

    res = Respondant.stats_report_filter(survey_slug, **form.cleaned_data)

    if not res.exists():
        return _error('No records for these filters.')

    res = (res.extra(select={'timestamp': "date_trunc('%s', ts)" % interval})
              .values('surveyor__first_name', 'surveyor__last_name',
                      'timestamp')
              .annotate(count=Count('pk')))

    res = res.order_by('timestamp')

    grouped_data = defaultdict(list)

    for respondant in res:
        name = _get_fullname(respondant)
        grouped_data[name].append(
            (calendar.timegm(respondant['timestamp'].utctimetuple()) * 1000,
             respondant['count'])
        )

    graph_data = []
    for name, data in grouped_data.iteritems():
        graph_data.append({'data': data, 'name': name})

    return HttpResponse(json.dumps({
        'success': True,
        'graph_data': graph_data
    }, cls=DateTimeJSONEncoder), content_type='application/json')
コード例 #8
0
ファイル: views.py プロジェクト: wraithan/solomon
def full_data_dump_csv(request, survey_slug):
    survey = Survey.objects.get(slug=survey_slug)
    response = _create_csv_response('full_dump_{0}.csv'.format(
        datetime.date.today().strftime('%d-%m-%Y')))
    fields = OrderedDict(Respondant.get_field_names().items() +
                         survey.generate_field_names().items())

    writer = SlugCSVWriter(response, fields)
    writer.writeheader()
    for resp in survey.respondant_set.all():
        writer.writerow(resp.generate_flat_dict())
    return response
コード例 #9
0
ファイル: views.py プロジェクト: abhijitdalavi/django-survey
def full_data_dump_csv(request, survey_slug):
    survey = Survey.objects.get(slug=survey_slug)
    response = _create_csv_response('full_dump_{0}.csv'.format(
        datetime.date.today().strftime('%d-%m-%Y')))
    fields = OrderedDict(Respondant.get_field_names().items() +
                         survey.generate_field_names().items())

    writer = SlugCSVWriter(response, fields)
    writer.writeheader()
    for resp in survey.respondant_set.all():
        writer.writerow(json.loads(resp.csv_row.json_data))
    return response
コード例 #10
0
ファイル: views.py プロジェクト: point97/survey-ost
def full_data_dump_csv(request, survey_slug):
    survey = Survey.objects.get(slug=survey_slug)
    response = _create_csv_response("full_dump_{0}.csv".format(datetime.date.today().strftime("%d-%m-%Y")))

    fields = OrderedDict(Respondant.get_field_names().items() + survey.generate_field_names().items())

    writer = SlugCSVWriter(response, fields)
    writer.writeheader()
    for resp in survey.respondant_set.filter(complete=True):
        # very basic removal of some characters that were causing issue in writing rows
        # row_string = resp.csv_row.json_data.replace('\u2019', '\"')
        # row_string = row_string.replace('\u2026', '\"')
        row_ascii = resp.csv_row.json_data.encode("ascii", errors="ignore")
        writer.writerow(json.loads(row_ascii))
    return response
コード例 #11
0
ファイル: views.py プロジェクト: wraithan/solomon
def surveyor_stats_raw_data_csv(request, survey_slug):
    form = SurveyorStatsForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest(json.dumps(form.errors))

    res = (Respondant.stats_report_filter(survey_slug, **form.cleaned_data)
                     .select_related('surveyor'))

    response = _create_csv_response('surveyor_stats.csv')
    writer = csv.writer(response)
    writer.writerow(('Surveyor', 'market', 'timestamp', 'status'))
    for row in res:
        writer.writerow((row.surveyor.get_full_name() if row.surveyor else '',
                         row.survey_site, row.ts, row.review_status))

    return response
コード例 #12
0
ファイル: views.py プロジェクト: abhijitdalavi/django-survey
def surveyor_stats_raw_data_csv(request, survey_slug):
    form = SurveyorStatsForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest(json.dumps(form.errors))

    res = (Respondant.stats_report_filter(
        survey_slug, **form.cleaned_data).select_related('surveyor'))

    response = _create_csv_response('surveyor_stats.csv')
    writer = csv.writer(response)
    writer.writerow(('Surveyor', 'market', 'timestamp', 'status'))
    for row in res:
        writer.writerow((row.surveyor.get_full_name() if row.surveyor else '',
                         row.survey_site, row.ts, row.review_status))

    return response
コード例 #13
0
def full_data_dump_csv(request, survey_slug):
    survey = Survey.objects.get(slug=survey_slug)
    response = _create_csv_response('full_dump_{0}.csv'.format(
        datetime.date.today().strftime('%d-%m-%Y')))

    fields = OrderedDict(Respondant.get_field_names().items() +
                         survey.generate_field_names().items())

    writer = SlugCSVWriter(response, fields)
    writer.writeheader()
    for resp in survey.respondant_set.filter(complete=True):
        # very basic removal of some characters that were causing issue in writing rows
        # row_string = resp.csv_row.json_data.replace('\u2019', '\"')
        # row_string = row_string.replace('\u2026', '\"')
        row_ascii = resp.csv_row.json_data.encode('ascii', errors='ignore')
        writer.writerow(json.loads(row_ascii))
    return response
コード例 #14
0
ファイル: views.py プロジェクト: wraithan/solomon
def surveyor_stats_csv(request, survey_slug, interval):
    form = SurveyorStatsForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest(json.dumps(form.errors))

    res = Respondant.stats_report_filter(survey_slug, **form.cleaned_data)

    res = (res.extra(select={'timestamp': "date_trunc('%s', ts)" % interval})
              .values('surveyor__first_name', 'surveyor__last_name',
                      'timestamp')
              .annotate(count=Count('pk')))

    response = _create_csv_response('raw_surveyor_stats.csv')
    writer = csv.writer(response)
    writer.writerow(('Surveyor', 'timestamp', 'count'))
    for row in res:
        writer.writerow((_get_fullname(row), row['timestamp'], row['count']))

    return response
コード例 #15
0
ファイル: views.py プロジェクト: abhijitdalavi/django-survey
def surveyor_stats_csv(request, survey_slug, interval):
    form = SurveyorStatsForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest(json.dumps(form.errors))

    res = Respondant.stats_report_filter(survey_slug, **form.cleaned_data)

    res = (res.extra(select={
        'timestamp': "date_trunc(%s, ts)"
    },
                     select_params=(interval, )).values(
                         'surveyor__first_name', 'surveyor__last_name',
                         'timestamp').annotate(count=Count('pk')))

    response = _create_csv_response('raw_surveyor_stats.csv')
    writer = csv.writer(response)
    writer.writerow(('Surveyor', 'timestamp', 'count'))
    for row in res:
        writer.writerow((_get_fullname(row), row['timestamp'], row['count']))

    return response
コード例 #16
0
ファイル: views.py プロジェクト: abhijitdalavi/django-survey
def surveyor_stats_json(request, survey_slug, interval):
    form = SurveyorStatsForm(request.GET)
    if not form.is_valid():
        return _error(**form.errors)

    res = Respondant.stats_report_filter(survey_slug, **form.cleaned_data)

    if not res.exists():
        return _error('No records for these filters.')

    res = (res.extra(select={
        'timestamp': "date_trunc(%s, ts)"
    },
                     select_params=(interval, )).values(
                         'surveyor__first_name', 'surveyor__last_name',
                         'timestamp').annotate(count=Count('pk')))

    res = res.order_by('timestamp')

    grouped_data = defaultdict(list)

    for respondant in res:
        name = _get_fullname(respondant)
        grouped_data[name].append(
            (calendar.timegm(respondant['timestamp'].utctimetuple()) * 1000,
             respondant['count']))

    graph_data = []
    for name, data in grouped_data.iteritems():
        graph_data.append({'data': data, 'name': name})

    return HttpResponse(json.dumps({
        'success': True,
        'graph_data': graph_data
    },
                                   cls=CustomJSONEncoder),
                        content_type='application/json')