Example #1
0
def main():
    _staff = Staff(CONFIG.STAFF_INDEX)
    for ban in _staff.list_banners():
        _staff.delete_banner(ban.id)

    for i, ban in enumerate(load_banners_json("web_front_banners")):
        _staff.add_banner(title=FRONT_PAGE_TITLE, platform="pc", position="homepage", banner=ban["key"], order=i,
                          url=FRONT_PAGE_URL, language="zh_cn", status=True)

    for i, ban in enumerate(load_banners_json("web_exchange_banners")):
        _staff.add_banner(title=FRONT_PAGE_TITLE, platform="pc", position="exchange_homepage", banner=ban["key"], order=i,
                          url=FRONT_PAGE_URL, language="zh_cn", status=True)

    for i, ban in enumerate(load_banners_json("app_front_banners")):
        _staff.add_banner(title=EXCHANGE_TITLE, platform="mobile", position="homepage", banner=ban["key"], order=i,
                          url=EXCHANGE_URL, language="zh_cn", status=True)

    for i, ban in enumerate(load_banners_json("app_exchange_banners")):
        _staff.add_banner(title=EXCHANGE_TITLE, platform="mobile", position="exchange_homepage", banner=ban["key"],
                          order=i, url=EXCHANGE_URL, language="zh_cn", status=True)

    for i, exchage in enumerate(exchange_items):
        _tenant = Tenant(i)
        for ban in _tenant.list_banners():
            _tenant.delete_banner(banner_id=ban.id)
        for ban in load_banners_json("web_exchange_private_banners"):
            _tenant.add_banner(title=EXCHANGE_INTERNAL_TITLE, url=EXCHANGE_INTERNAL_URL, banner=ban["key"])
def setup(request):
    banner = dict(title="hello world",
                  banner="今晚打老虎",
                  url="http://helloworld_rule_the_world/banner.jpg")

    banner_modified = dict(title="go go go",
                           banner="夜上海, 夜上海",
                           url="http://go_go_go_never_stop/banner.jpg")

    _tenant = Tenant(CONFIG.TENANT_INDEX)
    for ban in _tenant.list_banners():
        _tenant.delete_banner(ban.id)

    _tenant.add_banner(title=banner["title"],
                       banner=banner["banner"],
                       url=banner["url"])

    def finalize():
        for ban in _tenant.list_banners():
            _tenant.delete_banner(ban.id)

    request.addfinalizer(finalize)
    return _tenant, banner, banner_modified