Example #1
0
def index(request):
    # this is the index for a actual survey-taking
    # it falls back to 'group management' if no 'gid' is provided.
    # i.e. it expects gid to be part of the request!

    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        raise Http404()
    if survey_user is None:
        return HttpResponseRedirect(reverse(group_management))

    # Check if the user has filled user profile
    profile = pollster_utils.get_user_profile(request.user.id, survey_user.global_id)
    if profile is None:
        messages.add_message(request, messages.INFO, 
            _(u'Before we take you to the symptoms questionnaire, please complete the short background questionnaire below. You will only have to complete this once.'))
        url = reverse('apps.survey.views.profile_index')
        url_next = reverse('apps.survey.views.index')
        url = '%s?gid=%s&next=%s' % (url, survey_user.global_id, url_next)
        return HttpResponseRedirect(url)

    try:
        survey = pollster.models.Survey.get_by_shortname('weekly')
    except:
        raise Exception("The survey application requires a published survey with the shortname 'weekly'")

    next = None
    if 'next' not in request.GET:
        next = reverse(group_management) # is this necessary? Or would it be the default?

    return pollster_views.survey_run(request, survey.shortname, next=next)
Example #2
0
def index(request):
    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        raise Http404()
    if survey_user is None:
        url = '%s?next=%s' % (reverse(select_user), reverse(index))
        return HttpResponseRedirect(url)

    # Check if the user has filled user profile
    profile = pollster_utils.get_user_profile(request.user.id,
                                              survey_user.global_id)
    if profile is None:
        messages.add_message(request, messages.INFO,
                             _('You have to fill your profile data first.'))
        url = reverse('apps.survey.views.profile_index')
        url_next = reverse('apps.survey.views.index')
        url = '%s?gid=%s&next=%s' % (url, survey_user.global_id, url_next)
        return HttpResponseRedirect(url)

    try:
        survey = pollster.models.Survey.get_by_shortname('weekly')
    except:
        raise Exception(
            "The survey application requires a published survey with the shortname 'weekly'"
        )

    next = None
    if 'next' not in request.GET:
        next = reverse(thanks)

    return pollster_views.survey_run(request, survey.shortname, next=next)
Example #3
0
def index(request):
    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        raise Http404()
    if survey_user is None:
        url = "%s?next=%s" % (reverse(select_user), reverse(index))
        return HttpResponseRedirect(url)

    # Check if the user has filled user profile
    profile = pollster_utils.get_user_profile(request.user.id, survey_user.global_id)
    if profile is None:
        messages.add_message(request, messages.INFO, _("You have to fill your profile data first."))
        url = reverse("apps.survey.views.profile_index")
        url_next = reverse("apps.survey.views.index")
        url = "%s?gid=%s&next=%s" % (url, survey_user.global_id, url_next)
        return HttpResponseRedirect(url)

    try:
        survey = pollster.models.Survey.get_by_shortname("weekly")
    except:
        raise Exception("The survey application requires a published survey with the shortname 'weekly'")

    next = None
    if "next" not in request.GET:
        next = reverse(thanks)

    return pollster_views.survey_run(request, survey.shortname, next=next)
def group_management(request):
    try:
        survey = pollster.models.Survey.get_by_shortname('weekly')
    except:
        raise Exception("The survey application requires a published survey with the shortname 'weekly'")
    Weekly = survey.as_model()
    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        pass

    if request.method == "POST":
        global_ids = request.POST.getlist('global_ids')

        for survey_user in request.user.surveyuser_set.filter(global_id__in=global_ids):
            if request.POST.get('action') == 'healthy':
                messages.add_message(request, messages.INFO, 
                    _(u'The participant "%(user_name)s" has been marked as healthy.') % {'user_name': survey_user.name})

                profile = pollster_utils.get_user_profile(request.user.id, survey_user.global_id)
                if not profile:
                    messages.add_message(request, messages.INFO, 
                        _(u'Please complete the background questionnaire for the participant "%(user_name)s" before marking him/her as healthy.') % {'user_name': survey_user.name})
                    continue

                Weekly.objects.create(
                    user=request.user.id,
                    global_id=survey_user.global_id,
                    Q1_0=True, # Q1_0 => "No symptoms. The other fields are assumed to have the correct default information in them.
                    timestamp=datetime.now(),
                )
            elif request.POST.get('action') == 'delete':
                survey_user.deleted = True
                survey_user.save()

    history = list(_get_health_history(request, survey))
    persons = models.SurveyUser.objects.filter(user=request.user, deleted=False)
    persons_dict = dict([(p.global_id, p) for p in persons])
    for item in history:
        item['person'] = persons_dict.get(item['global_id'])
    for person in persons:
        person.health_status, person.diag = _get_person_health_status(request, survey, person.global_id)
        person.health_history = [i for i in history if i['global_id'] == person.global_id][:10]
        person.is_female = _get_person_is_female(person.global_id)

    return render_to_response('survey/group_management.html', {'persons': persons, 'history': history, 'gid': request.GET.get("gid")},
                              context_instance=RequestContext(request))
Example #5
0
def index(request):
    # this is the index for a actual survey-taking
    # it falls back to 'group management' if no 'gid' is provided.
    # i.e. it expects gid to be part of the request!

    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        raise Http404()
    if survey_user is None:
        return HttpResponseRedirect(reverse(group_management))

    # Check if the user has filled user profile
    profile = pollster_utils.get_user_profile(request.user.id,
                                              survey_user.global_id)
    if profile is None:
        messages.add_message(
            request, messages.INFO,
            _(u'Before we take you to the symptoms questionnaire, please complete the short background questionnaire below. You will only have to complete this once.'
              ))
        url = reverse('apps.survey.views.profile_index')
        url_next = reverse('apps.survey.views.index')
        url = '%s?gid=%s&next=%s' % (url, survey_user.global_id, url_next)
        return HttpResponseRedirect(url)

    try:
        survey = pollster.models.Survey.get_by_shortname('weekly')
    except:
        raise Exception(
            "The survey application requires a published survey with the shortname 'weekly'"
        )

    next = None
    if 'next' not in request.GET:
        next = reverse(
            group_management)  # is this necessary? Or would it be the default?

    return pollster_views.survey_run(request, survey.shortname, next=next)
Example #6
0
File: views.py Project: pfhm/hrpt
def index(request):
    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        raise Http404()
        # pass
    # return render_to_response('survey/utvardering.html',{'person': survey_user}, context_instance=RequestContext(request))
    if survey_user is None:
        url = "%s?next=%s" % (reverse(select_user), reverse(index))
        return HttpResponseRedirect(url)

    # Check if the user has filled user profile
    profile = pollster_utils.get_user_profile(request.user.id, survey_user.global_id)
    if profile is None:
        messages.add_message(
            request,
            messages.INFO,
            _(
                "Before we take you to the symptoms questionnaire, please complete the short background questionnaire below. You will only have to complete this once."
            ),
        )
        url = reverse("apps.survey.views.profile_index")
        url_next = reverse("apps.survey.views.index")
        url = "%s?gid=%s&next=%s" % (url, survey_user.global_id, url_next)
        return HttpResponseRedirect(url)

    try:
        survey = pollster.models.Survey.get_by_shortname("weekly")
    except:
        raise Exception("The survey application requires a published survey with the shortname 'weekly'")

    next = None
    if "next" not in request.GET:
        next = reverse(thanks)

    return pollster_views.survey_run(request, survey.shortname, next=next)
Example #7
0
def index(request):
    # this is the index for a actual survey-taking
    # it falls back to 'group management' if no 'gid' is provided.
    # i.e. it expects gid to be part of the request!
    function = 'def index:'
    logger.debug('%s' % function)
    logger.debug('%s User:%s' % (function, request.user.id))

    dt = 0
    survey_name = 'monthly'
    next = request.GET.get('next', None)
    if next is None:
        next = reverse(index)


    # Check if the user has filled user profile
    logger.debug('%s- Check Profile' % function)
    profile = pollster_utils.get_user_profile(request.user.id)

    if profile is None:
        logger.debug('%s- Check Profile is None' % function)
        next = reverse('apps.survey.views.survey_management')
        return survey_intake(request, next=next)

    try:
        # Busqueda para saber si ha rellenado el formulario monthly
        survey = pollster.models.Survey.get_by_shortname(survey_name)

    except Exception as e:
        logger.debug('%s - except: %s (%s)' % (function, e.message, type(e)))
        raise Exception("The survey application requires a published survey with the shortname %s" % survey_name)

    next = None
    if 'next' not in request.GET:
        next = reverse(survey_management) # is this necessary? Or would it be the default?

    logger.debug('%s - user: %s' % (function, request.user.id))
    last = survey.get_last_participation_data(request.user.id)
    if last:
        datenow = datetime.now()

        #datenow = datetime.strptime(str('2014-06-15'), '%Y-%m-%d')

        if datenow.month != last['timestamp'].month:
            logger.debug('%s - shortname: %s' % (function, survey.shortname))
            logger.debug('%s: survey_user(2)' % function)

	    # Since we want to redirect monthly survey queries to intake
            # questionnaire update so data is updated there, we check if
            # the shortname is monthly and in that case redirect to the
            # update of intake questionnaire
#	    if survey.shortname == 'monthly':
#			# Redirection to intake update
#			return pollster_views.pollster_update(request, 'intake', 'records', 0)
#	    else:
#	        	return pollster_views.pollster_run(request, survey.shortname, next=next)
	    logger.debug('Display records')
	    return survey_intake_update(request, "records")
        else:
            messages.info(request, _("You have done the survey in course, please come back in few days and you will complete a new one."))
            return show_message(request)
    else:
        logger.debug('%s - shortname(2): %s' % (function, survey.shortname))

        logger.debug('%s: survey_user(3)' % function)

	# Since we want to redirect monthly survey queries to intake
	# questionnaire update so data is updated there, we check if
	# the shortname is monthly and in that case redirect to the
	# update of intake questionnaire
	if survey.shortname == 'monthly':
		# Redirection to intake update
        	return pollster_views.pollster_update(request, 'intake', 'records', 0)
	else:
              	return pollster_views.pollster_run(request, survey.shortname, next=next)
Example #8
0
def group_management(request):
    try:
        survey = pollster.models.Survey.get_by_shortname('weekly')
    except:
        raise Exception(
            "The survey application requires a published survey with the shortname 'weekly'"
        )
    Weekly = survey.as_model()
    try:
        survey_user = get_active_survey_user(request)
    except ValueError:
        pass

    if request.method == "POST":
        global_ids = request.POST.getlist('global_ids')

        for survey_user in request.user.surveyuser_set.filter(
                global_id__in=global_ids):
            if request.POST.get('action') == 'healthy':
                messages.add_message(
                    request, messages.INFO,
                    _(u'The participant "%(user_name)s" has been marked as healthy.'
                      ) % {'user_name': survey_user.name})

                profile = pollster_utils.get_user_profile(
                    request.user.id, survey_user.global_id)
                if not profile:
                    messages.add_message(
                        request, messages.INFO,
                        _(u'Please complete the background questionnaire for the participant "%(user_name)s" before marking him/her as healthy.'
                          ) % {'user_name': survey_user.name})
                    continue

                Weekly.objects.create(
                    user=request.user.id,
                    global_id=survey_user.global_id,
                    Q1_0=
                    True,  # Q1_0 => "No symptoms. The other fields are assumed to have the correct default information in them.
                    timestamp=datetime.now(),
                )
            elif request.POST.get('action') == 'delete':
                survey_user.deleted = True
                survey_user.save()

    history = list(_get_health_history(request, survey))
    persons = models.SurveyUser.objects.filter(user=request.user,
                                               deleted=False)
    persons_dict = dict([(p.global_id, p) for p in persons])
    for item in history:
        item['person'] = persons_dict.get(item['global_id'])
    for person in persons:
        person.health_status, person.diag = _get_person_health_status(
            request, survey, person.global_id)
        person.health_history = [
            i for i in history if i['global_id'] == person.global_id
        ][:10]
        person.is_female = _get_person_is_female(person.global_id)

    return render_to_response('survey/group_management.html', {
        'persons': persons,
        'history': history,
        'gid': request.GET.get("gid")
    },
                              context_instance=RequestContext(request))
Example #9
0
def index(request):
    # this is the index for a actual survey-taking
    # it falls back to 'group management' if no 'gid' is provided.
    # i.e. it expects gid to be part of the request!
    function = 'def index:'
    logger.debug('%s' % function)
    logger.debug('%s User:%s' % (function, request.user.id))

    dt = 0
    survey_name = 'monthly'
    next = request.GET.get('next', None)
    if next is None:
        next = reverse(index)

    # Check if the user has filled user profile
    logger.debug('%s- Check Profile' % function)
    profile = pollster_utils.get_user_profile(request.user.id)

    if profile is None:
        logger.debug('%s- Check Profile is None' % function)
        next = reverse('apps.survey.views.survey_management')
        return survey_intake(request, next=next)

    try:
        # Busqueda para saber si ha rellenado el formulario monthly
        survey = pollster.models.Survey.get_by_shortname(survey_name)

    except Exception as e:
        logger.debug('%s - except: %s (%s)' % (function, e.message, type(e)))
        raise Exception(
            "The survey application requires a published survey with the shortname %s"
            % survey_name)

    next = None
    if 'next' not in request.GET:
        next = reverse(survey_management
                       )  # is this necessary? Or would it be the default?

    logger.debug('%s - user: %s' % (function, request.user.id))
    last = survey.get_last_participation_data(request.user.id)
    if last:
        datenow = datetime.now()

        #datenow = datetime.strptime(str('2014-06-15'), '%Y-%m-%d')

        if datenow.month != last['timestamp'].month:
            logger.debug('%s - shortname: %s' % (function, survey.shortname))
            logger.debug('%s: survey_user(2)' % function)

            # Since we want to redirect monthly survey queries to intake
            # questionnaire update so data is updated there, we check if
            # the shortname is monthly and in that case redirect to the
            # update of intake questionnaire
            #	    if survey.shortname == 'monthly':
            #			# Redirection to intake update
            #			return pollster_views.pollster_update(request, 'intake', 'records', 0)
            #	    else:
            #	        	return pollster_views.pollster_run(request, survey.shortname, next=next)
            logger.debug('Display records')
            return survey_intake_update(request, "records")
        else:
            messages.info(
                request,
                _("You have done the survey in course, please come back in few days and you will complete a new one."
                  ))
            return show_message(request)
    else:
        logger.debug('%s - shortname(2): %s' % (function, survey.shortname))

        logger.debug('%s: survey_user(3)' % function)

        # Since we want to redirect monthly survey queries to intake
        # questionnaire update so data is updated there, we check if
        # the shortname is monthly and in that case redirect to the
        # update of intake questionnaire
        if survey.shortname == 'monthly':
            # Redirection to intake update
            return pollster_views.pollster_update(request, 'intake', 'records',
                                                  0)
        else:
            return pollster_views.pollster_run(request,
                                               survey.shortname,
                                               next=next)