Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
 def getAllRoles(self):
     managers = [
         UserProvider(manager) for manager in self.context.values()
         if ICountryManager.providedBy(manager)
     ]
     return [(
         manager.getUserId(),
         ("CountryyManager", "Editor", "Contributor", "Reader", "Reviewer"),
     ) for manager in managers]
Exemple #4
0
 def getAllRoles(self):
     info = UserProvider(self.context)
     return [(info.getUserId(), ("Sector",))]
Exemple #5
0
 def getAllRoles(self):
     info = UserProvider(self.context)
     return [(info.getUserId(), ("Sector",))]