Beispiel #1
0
def setup_content(context):

    if sht.isNotThisProfile(context, "g24.importer-setup_content.txt"):
        return

    site = context.getSite()

    # delete some default folders AND posts folder
    sht.delete_items(site, ("front-page", "news", "events", "Members"), logger)

    site.setLayout("stream")

    _type = "g24.elements.basetypecontainer"

    posts = create(site, _type)
    posts.id = "posts"
    posts = add(posts, site)
    posts.setLayout("stream")
    posts.title = u"Posts"

    events = create(site, _type)
    events.id = "events"
    events = add(events, site)
    events.setLayout("event_listing")
    events.title = u"Events"

    places = create(site, _type)
    places.id = "places"
    places = add(places, site)
    places.setLayout("stream")
    places.title = u"Places"
    def create_g24_posting(container, texts, cats, maxchilds):
        content = []
        for i in range(2, randint(3, 12)):
            content.append(texts[randint(0, len(texts)-1)])

        data = {
            'is_title': True,
            'title': texts[randint(0, len(texts)-1)],
            'text': u'\n'.join(content),
            'subjects': (cats[randint(0, len(cats)-1)], cats[randint(0, len(cats)-1)]),
        }

        obj = create(container, G24_BASETYPE)
        obj = add(obj, container)

        obj.setCreators(choice(users)) # set the creators by loginname. if more than one, seperate by whitespace
        obj.creation_date = base_DT + int(obj.id)

        edit(obj, data, order=FEATURES, ignores=IGNORES)
        logger.info('Created object with id: %s' % obj.id)

        myChilds = randint(0, maxchilds)
        for i in range(0, myChilds):
            create_g24_posting(obj, texts, cats, maxchilds - myChilds)

        return obj