add person-based questionnaire

control team- and person-based questionnaires via questionnaireType;
person-based questionnaire: refer to (answer questions for) other person.
This commit is contained in:
Helmut Merz 2016-04-07 08:24:27 +02:00
parent 5b2b28da19
commit 5f8ed47165
5 changed files with 39 additions and 5 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# Copyright (c) 2016 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -41,9 +41,18 @@ class Questionnaire(AdapterBase, Questionnaire):
_contextAttributes = list(IQuestionnaire)
_adapterAttributes = AdapterBase._adapterAttributes + (
'teamBasedEvaluation',
'questionGroups', 'questions', 'responses',)
_noexportAttributes = _adapterAttributes
def getTeamBasedEvaluation(self):
return (self.questionnaireType == 'team' or
getattr(self.context, '_teamBasedEvaluation', False))
def setTeamBasedEvaluation(self, value):
if not value and getattr(self.context, '_teamBasedEvaluation', False):
self.context._teamBasedEvaluation = False
teamBasedEvaluation = property(getTeamBasedEvaluation, setTeamBasedEvaluation)
@property
def questionGroups(self):
return self.getQuestionGroups()

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# Copyright (c) 2016 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -228,6 +228,8 @@ class SurveyView(InstitutionMixin, ConceptView):
if self.adapted.teamBasedEvaluation and self.institution:
respManager.institutionId = self.getUidForObject(
baseObject(self.institution))
if self.adapted.questionnaireType == 'person':
respManager.referrerId = respManager.getPersonId()
if self.adapted.questionnaireType == 'pref_selection':
return self.prefsResults(respManager, form, action)
data = {}
@ -378,6 +380,8 @@ class SurveyView(InstitutionMixin, ConceptView):
if self.adapted.teamBasedEvaluation and self.institution:
respManager.institutionId = self.getUidForObject(
baseObject(self.institution))
if self.adapted.questionnaireType == 'person':
respManager.referrerId = respManager.getPersonId()
self.data = respManager.load()
def getValues(self, question):

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
# Copyright (c) 2016 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -45,6 +45,8 @@ class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire):
description=_(u'Select the type of the questionnaire.'),
source=KeywordVocabulary((
('standard', _(u'Standard Questionnaire')),
('person', _(u'Person-related Questionnaire')),
('team', _(u'Team-related Questionnaire')),
('pref_selection', _(u'Preference Selection')),
)),
default='standard',
@ -84,6 +86,8 @@ class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire):
default=False,
required=False)
#teamBasedEvaluation = Attribute('Team-based Evaluation')
feedbackColumns = Records(
title=_(u'Feedback Columns'),
description=_(u'Column definitions for the results table '

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# Copyright (c) 2016 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -36,6 +36,7 @@ class Responses(BaseRecordManager):
storageName = 'survey_responses'
personId = None
institutionId = None
referrerId = None
def __init__(self, context):
self.context = context
@ -45,18 +46,24 @@ class Responses(BaseRecordManager):
id = self.personId
if self.institutionId:
id += '.' + self.institutionId
if self.referrerId:
id += '.' + self.referrerId
self.storage.saveUserTrack(self.uid, 0, id, data,
update=True, overwrite=True)
def load(self, personId=None, institutionId=None):
def load(self, personId=None, referrerId=None, institutionId=None):
if personId is None:
personId = self.personId
if referrerId is None:
referrerId = self.referrerId
if institutionId is None:
institutionId = self.institutionId
if personId:
id = personId
if institutionId:
id += '.' + institutionId
if referrerId:
id += '.' + referrerId
tracks = self.storage.getUserTracks(self.uid, 0, id)
if not tracks: # then try without institution
tracks = self.storage.getUserTracks(self.uid, 0, personId)

View file

@ -104,6 +104,16 @@
</metal:block>
<metal:block define-macro="quest_person">
<metal:block use-macro="item/template/macros/quest_standard" />
</metal:block>
<metal:block define-macro="quest_team">
<metal:block use-macro="item/template/macros/quest_standard" />
</metal:block>
<metal:block define-macro="quest_pref_selection">
<h3 i18n:translate="">Questionnaire</h3>
<div class="error"