Esempio n. 1
0
 def root_view(self):
     contents = []
     for obj in self.context.values():
         if IOrganisation.providedBy(obj) and security.context_has_permission(obj, security.VIEW, self.userid):
             contents.append(obj)
     contents = sorted(contents, key = lambda x: x.title.lower())
     self.response['listing'] = self.listing_sniplet(contents)
     return self.response
 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
 def check_safe_delete(self, request):
     root = find_root(self)
     results = []
     #This code is ugly and could probably be done in a better way.
     for org in [x for x in root.values() if IOrganisation.providedBy(x)]:
         for surv in [x for x in org['surveys'].values() if ISurvey.providedBy(x)]:
             for surv_sect in [x for x in surv.values() if ISurveySection.providedBy(x)]:
                 if self.__name__ in surv_sect.question_ids:
                     results.append(surv_sect)
     if not results:
         return True
     #FIXME: Only flash messages can handle html right now
     out = u"<br/><br/>"
     rurl = request.resource_url
     out += ",<br/>".join([u'<a href="%s">%s</a>' % (rurl(x), x.title) for x in results])
     request.session.flash(_(u"Can't delete this since it's used in the following survey sections: ${out}",
                             mapping = {'out': out}))
     return False
def fix_nonpersistent_variants(*args):
    """ Organisations stored language variants in a regular dict that isn't persistent
        This fixes that.
    """
    worker = ScriptWorker('fix_nonpersistent_variants')
    
    orgs = [x for x in worker.root.values() if IOrganisation.providedBy(x)]
    for org in orgs:
        for (q_uid, value) in org.variants.items():
            if not isinstance(org.variants[q_uid], dict):
                continue
            org.variants[q_uid] = OOBTree(value)
            print "Fixing variant in %s" % org

    transaction.commit()
    print "Done"
    
    worker.shutdown()
    
Esempio n. 5
0
def _valid_organisaitons(root, userid):
    results = []
    for obj in root.values():
        if IOrganisation.providedBy(obj) and context_has_permission(obj, EDIT, userid):
            results.append(obj)
    return sorted(results, key = lambda x: x.title.lower())