예제 #1
0
    def test_index_is_updated_after_deleting_website(self):

        from woost.models import Website, Publishable

        index = Publishable.per_website_publication_index

        w1 = Website()
        w1.insert()

        w2 = Website()
        w2.insert()

        p1 = Publishable()
        p1.websites = [w1]
        p1.insert()

        p2 = Publishable()
        p2.websites = [w1, w2]
        p2.insert()

        w1.delete()
        assert set(index.items()) == set([(None, p1.id), (w2.id, p2.id)])

        w2.delete()
        assert set(index.items()) == set([(None, p1.id), (None, p2.id)])
예제 #2
0
    def test_content_can_change_its_designated_websites(self):

        from woost.models import Website, Publishable

        index = Publishable.per_website_publication_index

        p1 = Publishable()
        p1.insert()

        w1 = Website()
        w1.insert()

        w2 = Website()
        w2.insert()

        assert list(index.items()) == [(None, p1.id)]

        p1.websites = [w1]
        assert list(index.items()) == [(w1.id, p1.id)]

        p1.websites = [w2]
        assert list(index.items()) == [(w2.id, p1.id)]

        p1.websites = [w1, w2]
        assert set(index.items()) == set([(w1.id, p1.id), (w2.id, p1.id)])

        p1.websites = []
        assert list(index.items()) == [(None, p1.id)]
예제 #3
0
    def test_content_is_not_indexed_until_inserted(self):

        from woost.models import Website, Publishable

        index = Publishable.per_website_publication_index

        w1 = Website()
        w1.insert()

        p1 = Publishable()
        assert not list(index.items())

        p1.websites = [w1]
        assert not list(index.items())
예제 #4
0
    def test_content_is_published_for_all_websites_by_default(self):
        
        from woost.models import Website, Publishable
        
        index = Publishable.per_website_publication_index

        w1 = Website()
        w1.insert()

        p1 = Publishable()
        p1.insert()

        assert list(index.items()) == [(None, p1.id)]

        p2 = Publishable()
        p2.insert()

        assert set(index.items()) == set([(None, p1.id), (None, p2.id)])
예제 #5
0
    def test_index_is_updated_after_deleting_publishable(self):

        from woost.models import Website, Publishable

        index = Publishable.per_website_publication_index

        p1 = Publishable()
        p1.insert()
        p1.delete()

        assert (None, p1.id) not in list(index.items())

        w1 = Website()
        w1.insert()

        p2 = Publishable()
        p2.websites = [w1]
        p2.insert()
        p2.delete()

        assert not list(index.items())
예제 #6
0
def add_multisite_support(e):
    from cocktail.persistence import datastore
    from woost.models import Configuration, Website, Item
    root = datastore.root

    # Remove all back-references from the Site and Language models
    for item in Item.select():
        for key in dir(item):
            if (key == "_site" or key.startswith("_Site_")
                    or key.startswith("_Language_")):
                delattr(item, key)

    # Remove the instance of Site from the database
    site_id = list(Item.qname.index.values(key="woost.main_site"))[0]
    site = Item.index[site_id]
    site_state = site.__Broken_state__.copy()
    site_state["translations"] = dict(
        (lang, translation.__Broken_state__.copy())
        for lang, translation in site_state.pop("_translations").iteritems())
    Item.index.remove(site_id)
    Item.keys.remove(site_id)

    # Create the configuration object
    config = Configuration()
    config.qname = "woost.configuration"
    config.insert()

    # Create a website
    website = Website()
    website.insert()
    website.hosts = ["localhost"]
    config.websites.append(website)

    # Languages
    published_languages = []

    for lang_id in root["woost.models.language.Language-keys"]:
        language = Item.index[lang_id]
        Item.index.remove(lang_id)
        Item.keys.remove(lang_id)
        language_state = language.__Broken_state__
        config.languages.append(language_state["_iso_code"])
        if language_state["_enabled"]:
            published_languages.append(language_state["_iso_code"])

    if list(config.languages) != published_languages:
        config.published_languages = published_languages

    # Delete old indexes from the database
    for key in list(root):
        if (key.startswith("woost.models.site.Site")
                or key.startswith("woost.models.language.Language")):
            del root[key]

    # Settings that now belong in Configuration, as attributes
    config.secret_key = site_state.pop("secret_key")

    # Settings that now belong in Configuration, as regular fields
    for key in ("login_page", "generic_error_page", "not_found_error_page",
                "forbidden_error_page", "default_language",
                "backoffice_language", "heed_client_language", "timezone",
                "smtp_host", "smtp_user", "smtp_password"):
        config.set(key, site_state.pop("_" + key))

    # Settings that now belong in Configuration, as collections
    for key in ("publication_schemes", "caching_policies", "renderers",
                "image_factories", "triggers"):
        config.set(key, list(site_state.pop("_" + key)))

    # Settings that now belong in Website, becoming translated fields
    for key in ("town", "region", "country"):
        value = site_state.pop("_" + key)
        for lang in config.languages:
            website.set(key, value, lang)

    # Settings that now belong in website, as translated fields
    for key in ("site_name", "organization_name", "keywords", "description"):
        for lang, translation_state in site_state["translations"].iteritems():
            value = translation_state.pop("_" + key)
            website.set(key, value, lang)

    # Settings that now belong in website, as regular fields
    for key in ("logo", "icon", "home", "organization_url", "address",
                "postal_code", "phone_number", "fax_number", "email",
                "https_policy", "https_persistence"):
        website.set(key, site_state.pop("_" + key))

    # Extension specific changes
    from woost.extensions.blocks import BlocksExtension
    if BlocksExtension.instance.enabled:
        config.common_blocks = list(site_state.pop("_common_blocks"))

    from woost.extensions.audio import AudioExtension
    if AudioExtension.instance.enabled:
        config.audio_encoders = list(site_state.pop("_audio_encoders"))
        config.audio_decoders = list(site_state.pop("_audio_decoders"))

    from woost.extensions.mailer import MailerExtension
    if MailerExtension.instance.enabled:
        from woost.extensions.mailer.mailing import Mailing
        for mailing in Mailing.select():
            language = mailing._language
            if language:
                mailing._language = language.__Broken_state__["_iso_code"]

    from woost.extensions.googleanalytics import GoogleAnalyticsExtension
    if GoogleAnalyticsExtension.instance.enabled:
        account = GoogleAnalyticsExtension.instance._account
        del GoogleAnalyticsExtension.instance._account
        config.google_analytics_account = account

    # Rebuild all indexes
    Item.rebuild_indexes()

    # Preserve the remaining state
    datastore.root["woost.models.migration.multisite_leftovers"] = site_state