def ImportSector(plone, options, filename): input = open(filename, "r") dom = lxml.objectify.parse(input) xml_sector = dom.getroot() country = GetCountry(plone, options) if not hasattr(xml_sector, "survey"): return sector = GetSector(country, xml_sector, options) if sector is None: raise Abort("No sector specified and no account information found.") # Login as the sector sup = UserProvider(sector) sectoruser = plone.acl_users.getUserById(sup.getUserId()) sm = getSecurityManager() try: newSecurityManager(None, sectoruser) name = options.name or six.text_type(xml_sector.survey.title.text) if hasattr(sector, name): raise Abort("There is already a survey named '%s'" % name) log.info("Importing survey '%s' with version '%s'", name, options.version) importer = SurveyImporter(sector) survey = importer(xml_sector, name, options.version) if options.publish: log.info("Publishing survey") publisher = publish.PublishSurvey(survey, None) publisher.publish() finally: setSecurityManager(sm)
def ImportSector(plone, options, filename): input = open(filename, "r") dom = lxml.objectify.parse(input) xml_sector = dom.getroot() country = GetCountry(plone, options) if not hasattr(xml_sector, "survey"): return sector = GetSector(country, xml_sector, options) if sector is None: raise Abort("No sector specified and no account information found.") # Login as the sector sup = UserProvider(sector) sectoruser = plone.acl_users.getUserById(sup.getUserId()) sm = getSecurityManager() try: newSecurityManager(None, sectoruser) name = options.name or unicode(xml_sector.survey.title.text) if hasattr(sector, name): raise Abort("There is already a survey named '%s'" % name) log.info(u"Importing survey '%s' with version '%s'", name, options.version) importer = SurveyImporter(sector) survey = importer(xml_sector, name, options.version) if options.publish: log.info("Publishing survey") publisher = publish.PublishSurvey(survey, None) publisher.publish() finally: setSecurityManager(sm)
def getAllRoles(self): info = UserProvider(self.context) return [(info.getUserId(), ("Sector",))]