def getMyAnswer(self, multiple=False): """Return the answer of the current user or None if it doesn't exist. If multiple answers exist, only the first one is returned. """ if self.isAnonymousUser(): return None respondent = self.REQUEST.AUTHENTICATED_USER.getUserName() catalog = self.getCatalogTool() objects = [] for brain in catalog( {"path": path2url(self.getPhysicalPath()), "meta_type": SurveyAnswer.meta_type, "respondent": respondent} ): obj = brain.getObject() # if the "respondent" index is missing for some reason, we get # all answers, so we must do the filtering ourselves. if obj.respondent != respondent: continue if not multiple: return obj else: objects.append(obj) if objects: return objects else: return None
def getAnswerForRespondent(self, multiple=False, draft=False, respondent=None): """Return the answer of the respondent (or current user if None) Returns None if the answer doesn't exist. If multiple answers exist, only the first one is returned. Filters out the draft ones. """ if respondent is None: respondent = self.REQUEST.AUTHENTICATED_USER.getUserName() if respondent == 'Anonymous User': return None catalog = self.getCatalogTool() objects = [] for brain in catalog({'path': path2url(self.getPhysicalPath()), 'meta_type': SurveyAnswer.meta_type, 'respondent': respondent}): obj = brain.getObject() # if the "respondent" index is missing for some reason, we get # all answers, so we must do the filtering ourselves. if obj.respondent != respondent: continue if obj.is_draft() != bool(draft): continue if not multiple: return obj else: objects.append(obj) if objects: return objects else: return None
def getURL(self, relative=False): """ convert the physical path into a url, if it was stored """ path = self.getPath() path = path.encode('utf-8') schema = 'https://' try: url = self.request.physicalPathToURL(path, relative) domain = self.get('domain')[0] if self.get( 'cms_system') != cms_system() or domain != portal_domains()[0]: if '://' in domain: url = domain + self.get('context_path_string') else: url = schema + domain + self.get('context_path_string') #if path.startswith(('/prototyp-1/sp', '/prototyp-1/in')): # url = url.replace('/prototyp-1/sp', '') # url = url.replace('/prototyp-1/in', '') # url = url.replace('fucntions', '') except AttributeError: url = path2url(path.split('/')) except (TypeError, Exception): url = None # "/missing/value" return url
def getURL(self, relative=False): """ convert the physical path into a url, if it was stored """ path = self.getPath() try: url = self.request.physicalPathToURL(path, relative) except AttributeError: url = path2url(path.split('/')) return url
def getAnswerForRespondent(self, multiple=False, draft=False, all=False, respondent=None): """Return the answer of the respondent (or current user if None) Returns None if the answer doesn't exist. If multiple answers exist, only the first one is returned. Filters out the draft ones. """ if respondent is None: respondent = self.REQUEST.AUTHENTICATED_USER.getUserName() if respondent == 'Anonymous User': return None catalog = self.getCatalogTool() objects = [] for brain in catalog({ 'path': path2url(self.getPhysicalPath()), 'meta_type': SurveyAnswer.meta_type, 'respondent': respondent }): obj = brain.getObject() # if the "respondent" index is missing for some reason, we get # all answers, so we must do the filtering ourselves. if obj.respondent != respondent: continue if not all and obj.is_draft() != bool(draft): continue if not multiple: return obj else: objects.append(obj) if objects: return objects else: return None