provide institution selection for team-based surveys
This commit is contained in:
		
							parent
							
								
									09b75367a7
								
							
						
					
					
						commit
						adbdb2840b
					
				
					 4 changed files with 101 additions and 15 deletions
				
			
		|  | @ -1,5 +1,5 @@ | ||||||
| # | # | ||||||
| #  Copyright (c) 2013 Helmut Merz helmutm@cy55.de | #  Copyright (c) 2015 Helmut Merz helmutm@cy55.de | ||||||
| # | # | ||||||
| #  This program is free software; you can redistribute it and/or modify | #  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 | #  it under the terms of the GNU General Public License as published by | ||||||
|  | @ -30,8 +30,13 @@ from cybertools.typology.interfaces import IType | ||||||
| from loops.browser.action import DialogAction | from loops.browser.action import DialogAction | ||||||
| from loops.browser.common import BaseView | from loops.browser.common import BaseView | ||||||
| from loops.browser.concept import ConceptView | from loops.browser.concept import ConceptView | ||||||
|  | from loops.common import adapted | ||||||
| from loops.knowledge.interfaces import IPerson, ITask | from loops.knowledge.interfaces import IPerson, ITask | ||||||
| from loops.organize.party import getPersonForUser | from loops.organize.party import getPersonForUser | ||||||
|  | from loops.organize.personal import favorite | ||||||
|  | from loops.organize.personal.interfaces import IFavorites | ||||||
|  | from loops.security.common import checkPermission | ||||||
|  | from loops import util | ||||||
| from loops.util import _ | from loops.util import _ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -69,6 +74,60 @@ actions.register('createQualification', 'portlet', DialogAction, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class InstitutionMixin(object): | ||||||
|  | 
 | ||||||
|  |     knowledge_macros = knowledge_macros | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def institutionType(self): | ||||||
|  |         return self.conceptManager['institution'] | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def institutions(self): | ||||||
|  |         if checkPermission('loops.ManageWorkspaces', self.context): | ||||||
|  |             return self.getAllInstitutions() | ||||||
|  |         result = [] | ||||||
|  |         p = getPersonForUser(self.context, self.request) | ||||||
|  |         if p is None: | ||||||
|  |             return result | ||||||
|  |         for parent in p.getParents( | ||||||
|  |                 [self.memberPredicate, self.masterPredicate]): | ||||||
|  |             if parent.conceptType == self.institutionType: | ||||||
|  |                 result.append(dict( | ||||||
|  |                         object=adapted(parent),  | ||||||
|  |                         title=parent.title, | ||||||
|  |                         uid=util.getUidForObject(parent))) | ||||||
|  |         return result | ||||||
|  | 
 | ||||||
|  |     def getAllInstitutions(self): | ||||||
|  |         insts = self.institutionType.getChildren([self.typePredicate]) | ||||||
|  |         return [dict(object=adapted(inst), | ||||||
|  |                      title=inst.title, | ||||||
|  |                      uid=util.getUidForObject(inst)) for inst in insts] | ||||||
|  | 
 | ||||||
|  |     def setInstitution(self, uid): | ||||||
|  |         inst = util.getObjectForUid(uid) | ||||||
|  |         person = getPersonForUser(self.context, self.request) | ||||||
|  |         favorite.setInstitution(person, inst) | ||||||
|  |         self.institution = inst | ||||||
|  |         return True | ||||||
|  | 
 | ||||||
|  |     def getSavedInstitution(self): | ||||||
|  |         person = getPersonForUser(self.context, self.request) | ||||||
|  |         favorites = IFavorites(self.loopsRoot.getRecordManager()['favorites']) | ||||||
|  |         for inst in favorites.list(person, type='institution'): | ||||||
|  |             return adapted(util.getObjectForUid(inst)) | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def institution(self): | ||||||
|  |         saved = self.getSavedInstitution() | ||||||
|  |         for inst in self.institutions: | ||||||
|  |             if inst['object'] == saved: | ||||||
|  |                 return inst['object'] | ||||||
|  |         if self.institutions: | ||||||
|  |             return self.institutions[0]['object'] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class MyKnowledge(ConceptView): | class MyKnowledge(ConceptView): | ||||||
| 
 | 
 | ||||||
|     template = template |     template = template | ||||||
|  |  | ||||||
|  | @ -32,6 +32,7 @@ from cybertools.util.date import formatTimeStamp | ||||||
| from loops.browser.concept import ConceptView | from loops.browser.concept import ConceptView | ||||||
| from loops.browser.node import NodeView | from loops.browser.node import NodeView | ||||||
| from loops.common import adapted, baseObject | from loops.common import adapted, baseObject | ||||||
|  | from loops.knowledge.browser import InstitutionMixin | ||||||
| from loops.knowledge.survey.response import Responses | from loops.knowledge.survey.response import Responses | ||||||
| from loops.organize.party import getPersonForUser | from loops.organize.party import getPersonForUser | ||||||
| from loops.util import getObjectForUid | from loops.util import getObjectForUid | ||||||
|  | @ -40,7 +41,7 @@ from loops.util import _ | ||||||
| 
 | 
 | ||||||
| template = ViewPageTemplateFile('view_macros.pt') | template = ViewPageTemplateFile('view_macros.pt') | ||||||
| 
 | 
 | ||||||
| class SurveyView(ConceptView): | class SurveyView(InstitutionMixin, ConceptView): | ||||||
| 
 | 
 | ||||||
|     data = None |     data = None | ||||||
|     errors = None |     errors = None | ||||||
|  | @ -69,6 +70,11 @@ class SurveyView(ConceptView): | ||||||
|         if self.editable: |         if self.editable: | ||||||
|             return 'index.html' |             return 'index.html' | ||||||
| 
 | 
 | ||||||
|  |     def update(self): | ||||||
|  |         instUid = self.request.form.get('select_institution') | ||||||
|  |         if instUid: | ||||||
|  |             return self.setInstitution(instUid) | ||||||
|  | 
 | ||||||
|     @Lazy |     @Lazy | ||||||
|     def groups(self): |     def groups(self): | ||||||
|         result = [] |         result = [] | ||||||
|  | @ -129,11 +135,12 @@ class SurveyView(ConceptView): | ||||||
|         pred = self.conceptManager.get('ismember') |         pred = self.conceptManager.get('ismember') | ||||||
|         if pred is None: |         if pred is None: | ||||||
|             return result |             return result | ||||||
|         personId = respManager.personId |         #personId = respManager.personId | ||||||
|         person = self.getObjectForUid(personId) |         #person = self.getObjectForUid(personId) | ||||||
|         inst = person.getParents([pred]) |         #inst = person.getParents([pred]) | ||||||
|  |         inst = self.institution | ||||||
|         if inst: |         if inst: | ||||||
|             for c in inst[0].getChildren([pred]): |             for c in inst.getChildren([pred]): | ||||||
|                 uid = self.getUidForObject(c) |                 uid = self.getUidForObject(c) | ||||||
|                 data = respManager.load(uid) |                 data = respManager.load(uid) | ||||||
|                 if data: |                 if data: | ||||||
|  |  | ||||||
|  | @ -40,6 +40,16 @@ class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire): | ||||||
|         missing_value=u'', |         missing_value=u'', | ||||||
|         required=False) |         required=False) | ||||||
| 
 | 
 | ||||||
|  |     questionnaireType = schema.Choice( | ||||||
|  |         title=_(u'Questionnaire Type'), | ||||||
|  |         description=_(u'Select the type of the questionnaire.'), | ||||||
|  |         source=KeywordVocabulary(( | ||||||
|  |                 ('standard', _(u'Standard Questionnaire')), | ||||||
|  |                 ('pref_selection', _(u'Preference Selection')), | ||||||
|  |             )), | ||||||
|  |         default='standard', | ||||||
|  |         required=True) | ||||||
|  | 
 | ||||||
|     defaultAnswerRange = schema.Int( |     defaultAnswerRange = schema.Int( | ||||||
|         title=_(u'Answer Range'), |         title=_(u'Answer Range'), | ||||||
|         description=_(u'Number of items (answer options) to select from.'), |         description=_(u'Number of items (answer options) to select from.'), | ||||||
|  | @ -66,6 +76,12 @@ class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire): | ||||||
|         default=False, |         default=False, | ||||||
|         required=False) |         required=False) | ||||||
| 
 | 
 | ||||||
|  |     teamBasedEvaluation = schema.Bool( | ||||||
|  |         title=_(u'Team-based Evaluation'), | ||||||
|  |         description=_(u'.'), | ||||||
|  |         default=False, | ||||||
|  |         required=False) | ||||||
|  | 
 | ||||||
|     feedbackColumns = Records( |     feedbackColumns = Records( | ||||||
|         title=_(u'Feedback Columns'), |         title=_(u'Feedback Columns'), | ||||||
|         description=_(u'Column definitions for the results table ' |         description=_(u'Column definitions for the results table ' | ||||||
|  |  | ||||||
|  | @ -4,7 +4,8 @@ | ||||||
| 
 | 
 | ||||||
| <metal:block define-macro="survey" | <metal:block define-macro="survey" | ||||||
|               tal:define="feedback item/results; |               tal:define="feedback item/results; | ||||||
|                           errors item/errors"> |                           errors item/errors; | ||||||
|  |                           dummy item/update"> | ||||||
|   <metal:title use-macro="item/conceptMacros/concepttitle_only" /> |   <metal:title use-macro="item/conceptMacros/concepttitle_only" /> | ||||||
|   <tal:description condition="not:feedback"> |   <tal:description condition="not:feedback"> | ||||||
|     <div tal:define="header item/adapted/questionnaireHeader" |     <div tal:define="header item/adapted/questionnaireHeader" | ||||||
|  | @ -60,6 +61,9 @@ | ||||||
| 
 | 
 | ||||||
|   <div id="questionnaire" |   <div id="questionnaire" | ||||||
|        tal:condition="not:feedback"> |        tal:condition="not:feedback"> | ||||||
|  |     <tal:inst condition="item/adapted/teamBasedEvaluation"> | ||||||
|  |       <metal:inst use-macro="item/knowledge_macros/select_institution" /> | ||||||
|  |     </tal:inst> | ||||||
|     <h3 i18n:translate="">Questionnaire</h3> |     <h3 i18n:translate="">Questionnaire</h3> | ||||||
|     <div class="error" |     <div class="error" | ||||||
|          tal:condition="errors"> |          tal:condition="errors"> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue