def test_websites_can_override_language_visibility(self): from woost.models import Configuration, Website, set_current_website w1 = Website() w2 = Website() self.config.languages = ["ca", "es", "en"] for website in (None, w1, w2): set_current_website(website) for lang in ["ca", "es", "en"]: assert self.config.language_is_enabled(lang) self.config.published_languages = ["en"] for website in (None, w1, w2): set_current_website(website) assert self.config.language_is_enabled("en") assert not self.config.language_is_enabled("ca") assert not self.config.language_is_enabled("es") w1.published_languages = ["ca"] set_current_website(w1) assert self.config.language_is_enabled("ca") assert not self.config.language_is_enabled("es") assert not self.config.language_is_enabled("en") set_current_website(w2) assert self.config.language_is_enabled("en") assert not self.config.language_is_enabled("ca") assert not self.config.language_is_enabled("es")
def test_descendants_inherit_availability(self): from woost.models import Website, Document w1 = Website() w2 = Website() d1 = Document() d1.websites = [w1] d2 = Document() d2.websites = [w2] d2.parent = d1 assert list(d2.websites) == [w1] d3 = Document() d3.parent = d2 assert list(d3.websites) == [w1] d1.websites.append(w2) assert list(d2.websites) == [w1, w2] assert list(d3.websites) == [w1, w2] d1.websites = [] assert not d2.websites assert not d3.websites
def test_designating_a_website_home_implies_exclusivity(self): from woost.models import Website, Document d1 = Document() w1 = Website() w1.home = d1 assert list(d1.websites) == [w1]
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)]
def test_solves_collissions_by_relative_order_of_websites_in_configuration(self): from woost.models import Website w1 = Website() w1.hosts.append("bar.com") w1.hosts.append("foo.com") self.config.websites.append(w1) w2 = Website() w2.hosts.append("foo.com") self.config.websites.append(w2) assert self.config.get_website_by_host("foo.com") is w1
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())
def test_can_match_more_than_one_host(self): from woost.models import Website w1 = Website() w1.hosts.append("foo.com") w1.hosts.append("foo.net") self.config.websites.append(w1) w2 = Website() w2.hosts.append("bar.com") w2.hosts.append("spam.bar.com") self.config.websites.append(w2) assert self.config.get_website_by_host("foo.com") is w1 assert self.config.get_website_by_host("foo.net") is w1 assert self.config.get_website_by_host("bar.com") is w2 assert self.config.get_website_by_host("spam.bar.com") is w2
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)])
def import_old_settings(e): from woost.models import Configuration, Website for obj in (list(Configuration.select()) + list(Website.select())): try: value = obj._google_tag_manager_account except AttributeError: pass else: del obj._google_tag_manager_account obj.x_googletagmananager_container = value
def get_publishable_website(publishable): acceptable_websites = publishable.websites current_website = app.website if current_website is not None: if not acceptable_websites or current_website in acceptable_websites: return current_website for website in Website.select(): if not acceptable_websites or website in acceptable_websites: return website
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())
def preserve_woost2_data(e): from woost.models import Website catalog = BlocksCatalog.require_instance( qname="woost.extensions.notices.blocks_catalog") for website in Website.select(): blocks = set() try: value = website._notices except AttributeError: pass else: del website._notices if value: catalog.blocks.extend(value)
def preserve_woost2_info(e): from woost.models import Configuration, Website, Publishable from .opengraphtype import OpenGraphType broken = datastore.root.get("woost2_broken_objects") ext_map = \ broken and broken.get("woost.extensions.opengraph.OpenGraphExtension") ext = ext_map and ext_map.popitem()[1] if ext: # Must run before rebuild_indexes_after_conversion_to_python3, since # the index rebuilding can trigger the default value production for # Publication.x_opengraph_type, which in turn will attempt to obtain # a type by code. OpenGraphType.code.rebuild_index() def rename_attrib(obj, name, new_name=None): old_key = "_open_graph_" + name try: value = getattr(obj, old_key) except AttributeError: pass else: delattr(obj, old_key) new_key = "_x_opengraph_" + (new_name or name) setattr(obj, new_key, value) # Disable installation for the extension extensions_manager.set_installed("opengrah", True) for config in Configuration.select(): rename_attrib(config, "default_image") if ext: config._x_opengraph_fb_admins = ext["_facebook_administrators"] config._x_opengraph_fb_apps = ext["_facebook_applications"] for website in Website.select(): rename_attrib(website, "default_image") for pub in Publishable.select(): rename_attrib(pub, "enabled") rename_attrib(pub, "type")
def test_websites_own_document_trees_exclusively(self): from woost.models import Website, Document d1 = Document() w1 = Website() w1.home = d1 w2 = Website() w2.home = d1 assert list(d1.websites) == [w2]
def set_exportable_flag(): for item in [Configuration.instance] + list(Website.select()): for key in ("login_page", "maintenance_page", "generic_error_page", "not_found_error_page", "forbidden_error_page"): page = getattr(item, key, None) if page: page.x_staticpub_exportable = False for qname in ("woost.password_change_page", "woost.password_change_confirmation_page"): page = Publishable.get_instance(qname=qname) if page: page.included_in_static_publication = False for cls in get_publishable_models(): member = cls.get_member("x_staticpub_exportable") if member and member.indexed: member.rebuild_index()
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
#-*- coding: utf-8 -*- u""" .. moduleauthor:: Martí Congost <*****@*****.**> """ from cocktail import schema from woost.models import Website, Document Website.add_member( schema.String("google_search_engine_id", member_group="services.google_cse")) Website.add_member( schema.Reference("google_search_results_page", type=Document, related_end=schema.Collection(), member_group="services.google_cse"))
#-*- coding: utf-8 -*- u""" .. moduleauthor:: Martí Congost <*****@*****.**> """ from cocktail import schema from woost.models import Website Website.add_member( schema.String("google_analytics_account", text_search = False, member_group = "services.google_analytics", synchronizable = False, listed_by_default = False ) )
#-*- coding: utf-8 -*- u""" .. moduleauthor:: Jordi Fernández <*****@*****.**> """ from cocktail import schema from woost.models import Website Website.add_member( schema.String("external_files_host", text_search = False, member_group = "publication", listed_by_default = False ) )
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)])
#-*- coding: utf-8 -*- u""" .. moduleauthor:: Jordi Fernández <*****@*****.**> """ from cocktail import schema from woost.models import Website Website.members_order.extend( ["campaign_monitor_api_key", "campaign_monitor_client_id"]) Website.add_member( schema.String("campaign_monitor_api_key", member_group="services.campaign_monitor", listed_by_default=False)) Website.add_member( schema.String("campaign_monitor_client_id", member_group="services.campaign_monitor", listed_by_default=False))