예제 #1
0
def _fetch_questions_for_tags(context):
    if IQuestions.providedBy(context):
        questions = context.values()
    else:
        questions = []
        questions.extend(find_root(context)['questions'].values())
        org = find_interface(context, IOrganisation)
        if org:
            questions.extend(org['questions'].values())
    return questions
예제 #2
0
 def questions_view(self):
     """ This view is for any IQuestions context, both the global one and the local one + the Organisation objects 'variants' view.
     """
     schema = createSchema('QuestionSearchSchema').bind(context = self.context, request = self.request)
     form = Form(schema, buttons = (), formid = 'tag_select', action = 'javascript:')
     self.response['form_resources'] = form.get_widget_resources()
     self.response['tag_form'] = form.render()
     #Get questions, sorted - behaves differently for variants!
     if IOrganisation.providedBy(self.context):
         questions = self.root['questions'].values()
     else:
         questions = self.context.values()
     self.response['questions'] = sorted(questions, key = lambda q: q.get_field_value('title').lower())
     self.response['is_org'] = IOrganisation.providedBy(self.context)
     self.response['show_edit_variants'] = self.response['is_org'] and \
         security.context_has_permission(self.context, security.MANAGE_SURVEY, self.userid)
     self.response['show_edit'] = IQuestions.providedBy(self.context) and \
         security.context_has_permission(self.context, security.EDIT, self.userid) or False
     return self.response