provide team evaluation of survey
This commit is contained in:
parent
2fc7709c56
commit
66bf217ee8
3 changed files with 57 additions and 16 deletions
|
@ -60,9 +60,30 @@ class SurveyView(ConceptView):
|
|||
sft = self.adapted.showFeedbackText
|
||||
return sft is None and True or sft
|
||||
|
||||
def getTeamData(self, respManager, myResponse):
|
||||
result = [myResponse]
|
||||
pred = self.conceptManager.get('ismember')
|
||||
if pred is None:
|
||||
return result
|
||||
personId = respManager.personId
|
||||
person = self.getObjectForUid(personId)
|
||||
inst = person.getParents([pred])
|
||||
if inst:
|
||||
for c in inst[0].getChildren([pred]):
|
||||
uid = self.getUidForObject(c)
|
||||
if uid != personId:
|
||||
data = respManager.load(uid)
|
||||
if data:
|
||||
resp = Response(self.adapted, None)
|
||||
for qu in self.adapted.questions:
|
||||
resp.values[qu] = data[qu.uid]
|
||||
result.append(resp)
|
||||
return result
|
||||
|
||||
def results(self):
|
||||
result = []
|
||||
values = []
|
||||
response = None
|
||||
respManager = Responses(self.context)
|
||||
form = self.request.form
|
||||
if 'submit' in form:
|
||||
self.data = {}
|
||||
|
@ -75,15 +96,25 @@ class SurveyView(ConceptView):
|
|||
value = int(value)
|
||||
self.data[uid] = value
|
||||
response.values[question] = value
|
||||
Responses(self.context).save(self.data)
|
||||
respManager.save(self.data)
|
||||
self.errors = self.check(response)
|
||||
if self.errors:
|
||||
return []
|
||||
ranks = averages = []
|
||||
if response is not None:
|
||||
result = response.getGroupedResult()
|
||||
return [dict(category=r[0].title, text=r[1].text,
|
||||
if self.adapted.showTeamResults:
|
||||
values, ranks, averages = response.getTeamResult(
|
||||
self.getTeamData(respManager, response))
|
||||
else:
|
||||
values = response.getGroupedResult()
|
||||
result = [dict(category=r[0].title, text=r[1].text,
|
||||
score=int(round(r[2] * 100)))
|
||||
for r in result]
|
||||
for r in values]
|
||||
if ranks or averages:
|
||||
for idx, qgdata in enumerate(result):
|
||||
qgdata['rank'] = ranks[idx]
|
||||
qgdata['average'] = int(round(averages[idx] * 100))
|
||||
return result
|
||||
|
||||
def check(self, response):
|
||||
errors = []
|
||||
|
|
|
@ -43,9 +43,11 @@ class Responses(BaseRecordManager):
|
|||
self.storage.saveUserTrack(self.uid, 0, self.personId, data,
|
||||
update=True, overwrite=True)
|
||||
|
||||
def load(self):
|
||||
if self.personId:
|
||||
tracks = self.storage.getUserTracks(self.uid, 0, self.personId)
|
||||
def load(self, personId=None):
|
||||
if personId is None:
|
||||
personId = self.personId
|
||||
if personId:
|
||||
tracks = self.storage.getUserTracks(self.uid, 0, personId)
|
||||
if tracks:
|
||||
return tracks[0].data
|
||||
return {}
|
||||
|
|
|
@ -19,22 +19,30 @@
|
|||
<th i18n:translate="">Category</th>
|
||||
<th tal:condition="item/showFeedbackText"
|
||||
i18n:translate="">Response</th>
|
||||
<th i18n:translate="">%</th>
|
||||
<th class="center"
|
||||
i18n:translate="">%</th>
|
||||
<tal:team condition="item/adapted/showTeamResults">
|
||||
<th i18n:translate="">Rank</th>
|
||||
<th i18n:translate="">Team Score %</th>
|
||||
<th i18n:translate="">Team Rank</th>
|
||||
<th class="center"
|
||||
i18n:translate="">Rank</th>
|
||||
<th class="center"
|
||||
i18n:translate="">Team Score %</th>
|
||||
<th class="center"
|
||||
tal:condition="nothing"
|
||||
i18n:translate="">Team Rank</th>
|
||||
</tal:team>
|
||||
</tr>
|
||||
<tr tal:repeat="fbitem feedback">
|
||||
<td tal:content="fbitem/category" />
|
||||
<td tal:condition="item/showFeedbackText"
|
||||
tal:content="fbitem/text" />
|
||||
<td tal:content="fbitem/score" />
|
||||
<td class="center"
|
||||
tal:content="fbitem/score" />
|
||||
<tal:team condition="item/adapted/showTeamResults">
|
||||
<td />
|
||||
<td />
|
||||
<td />
|
||||
<td class="center"
|
||||
tal:content="fbitem/rank" />
|
||||
<td class="center"
|
||||
tal:content="fbitem/average" />
|
||||
<td tal:condition="nothing" />
|
||||
</tal:team>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
Loading…
Add table
Reference in a new issue