Пример #1
0
def createhollowqsets(questionnaire, qsets=None, highlights=None):

    if qsets == None:
        qsets = ordered_dict()

    rHighlights = None
    qhighlights = None

    if highlights != None:
        if "results" in highlights and runcode in highlights["results"]:
            rHighlights = highlights["results"][runcode]
        if "questions" in highlights:
            qhighlights = highlights["questions"]

    qsets_query = QuestionSet.objects.filter(questionnaire=questionnaire).order_by('sortid')

    for qset in qsets_query:
        if qset.sortid != 0 and qset.sortid != 99:
            question_group = QuestionGroup()
            question_group.sortid = qset.sortid
            question_group.qsid = qset.id

            qsets[qset.text] = question_group

    return qsets
Пример #2
0
def createhollowqsets(questionnaire, qsets=None, highlights=None):

    if qsets == None:
        qsets = ordered_dict()

    rHighlights = None
    qhighlights = None

    if highlights != None:
        if "results" in highlights and runcode in highlights["results"]:
            rHighlights = highlights["results"][runcode]
        if "questions" in highlights:
            qhighlights = highlights["questions"]

    qsets_query = QuestionSet.objects.filter(
        questionnaire=questionnaire).order_by('sortid')

    for qset in qsets_query:
        if qset.sortid != 0 and qset.sortid != 99:
            question_group = QuestionGroup()
            question_group.sortid = qset.sortid
            question_group.qsid = qset.id

            qsets[qset.text] = question_group

    return qsets
Пример #3
0
def handle_qset(fingerprint, clean, qsets, qset, answers, fingerprint_ttype, rHighlights, qhighlights, getAnswers=True, noprocessing=False, changeSearch=False):
    name = ""
    question_group = QuestionGroup()
    question_group.sortid = qset.sortid
    question_group.qsid = qset.id
    question_group.highlights = False

    qsets[qset.text] = question_group
    # questions() already gives us questions ordered by number
    list_questions = qset.questions()

    for question in list_questions:
        t = Tag()
        t.id = question.id
        t.tag = question.text
        t.value = ""
        t.number = question.number
        t.ttype = question.type
        t.lastChange = None
        t.meta = question.meta()
        question_group.list_ordered_tags.append(t)

    qsets[qset.text] = question_group

    if getAnswers:
        for answer in answers:
            question = answer.question

            slug = question.slug_fk.slug1

            t = Tag()

            qs = None
            question_group = None
            q_number = None


            if question != None:
                t.id = question.id

                text = question.slug_fk.description
                qs = qset.text
                q_number = qs = question.number

                if qsets.has_key(qset.text):
                    # Add the Tag to the QuestionGroup
                    question_group = qsets[qset.text]

            else:
                text = (slug, answer.data)

            info = text
            t.tag = info

            if question_group != None and question_group.list_ordered_tags != None:
                try:
                    t = question_group.list_ordered_tags[question_group.list_ordered_tags.index(t)]
                except:
                    pass

            raw_value = str(answer.data.encode('utf-8'))
            value = clean_value(raw_value)

            qs_text = slug + "qs"
            id_text = "questionaire_"+str(fingerprint_ttype)
            if qhighlights != None and id_text in qhighlights and qs_text in qhighlights[id_text]:
                t.tag = qhighlights[id_text][qs_text][0].encode('utf-8')

            if answer.comment != None:
                t.comment = answer.comment

            if changeSearch:
                changes = AnswerChange.objects.filter(answer=answer).order_by('-id')

                if len(changes) == 0:
                    t.lastChange = answer.fingerprint_id.created
                else:
                    t.lastChange = changes[0].revision_head.date

            if clean:
                t.value = value.replace("#", " ")
                highlighted = False

                if rHighlights != None and slug+'_t' in rHighlights:
                    try:
                        qsets[question.questionset.text].highlights = True
                    except:
                        pass

                    t.value = rHighlights[slug+'_t'][0].encode('utf-8')
                    highlighted = True
                    #if len(highlights["results"][k])>1:
                    #print t.value

                if not noprocessing:
                    if t.ttype in Fingerprint_Summary:
                        if highlighted:
                            t.value = Fingerprint_Summary[t.ttype](t.value)
                        else:
                            t.value = Fingerprint_Summary[t.ttype](raw_value)

            else:
                t.value = value

            if slug == "database_name":
                name = raw_value

            if question_group != None:
                try:
                    question_group.list_ordered_tags[question_group.list_ordered_tags.index(t)] = t
                except:
                    pass

    return (qsets, name)
Пример #4
0
def handle_qset(fingerprint,
                clean,
                qsets,
                qset,
                answers,
                fingerprint_ttype,
                rHighlights,
                qhighlights,
                getAnswers=True,
                noprocessing=False,
                changeSearch=False):
    name = ""
    question_group = QuestionGroup()
    question_group.sortid = qset.sortid
    question_group.qsid = qset.id
    question_group.highlights = False

    qsets[qset.text] = question_group
    # questions() already gives us questions ordered by number
    list_questions = qset.questions()

    for question in list_questions:
        t = Tag()
        t.id = question.id
        t.tag = question.text
        t.value = ""
        t.number = question.number
        t.ttype = question.type
        t.lastChange = None
        t.meta = question.meta()
        question_group.list_ordered_tags.append(t)

    qsets[qset.text] = question_group

    if getAnswers:
        for answer in answers:
            question = answer.question

            slug = question.slug_fk.slug1

            t = Tag()

            qs = None
            question_group = None
            q_number = None

            if question != None:
                t.id = question.id

                text = question.slug_fk.description
                qs = qset.text
                q_number = qs = question.number

                if qsets.has_key(qset.text):
                    # Add the Tag to the QuestionGroup
                    question_group = qsets[qset.text]

            else:
                text = (slug, answer.data)

            info = text
            t.tag = info

            if question_group != None and question_group.list_ordered_tags != None:
                try:
                    t = question_group.list_ordered_tags[
                        question_group.list_ordered_tags.index(t)]
                except:
                    pass

            raw_value = str(answer.data.encode('utf-8'))
            value = clean_value(raw_value)

            qs_text = slug + "qs"
            id_text = "questionaire_" + str(fingerprint_ttype)
            if qhighlights != None and id_text in qhighlights and qs_text in qhighlights[
                    id_text]:
                t.tag = qhighlights[id_text][qs_text][0].encode('utf-8')

            if answer.comment != None:
                t.comment = answer.comment

            if changeSearch:
                changes = AnswerChange.objects.filter(
                    answer=answer).order_by('-id')

                if len(changes) == 0:
                    t.lastChange = answer.fingerprint_id.created
                else:
                    t.lastChange = changes[0].revision_head.date

            if clean:
                t.value = value.replace("#", " ")
                highlighted = False

                if rHighlights != None and slug + '_t' in rHighlights:
                    try:
                        qsets[question.questionset.text].highlights = True
                    except:
                        pass

                    t.value = rHighlights[slug + '_t'][0].encode('utf-8')
                    highlighted = True
                    #if len(highlights["results"][k])>1:
                    #print t.value

                if not noprocessing:
                    if t.ttype in Fingerprint_Summary:
                        if highlighted:
                            t.value = Fingerprint_Summary[t.ttype](t.value)
                        else:
                            t.value = Fingerprint_Summary[t.ttype](raw_value)

            else:
                t.value = value

            if slug == "database_name":
                name = raw_value

            if question_group != None:
                try:
                    question_group.list_ordered_tags[
                        question_group.list_ordered_tags.index(t)] = t
                except:
                    pass

    return (qsets, name)