def preserve_woost2_info(e): from woost.models import Configuration, Publishable # Rename the staticpub_default_dest member config = Configuration.instance try: default_dest = config._staticpub_default_dest except AttributeError: pass else: del config._staticpub_default_dest del default_dest._Configuration_staticpub_default_dest config.x_staticpub_default_dest = default_dest # Rename the 'included_in_static_publication' member datastore.root.pop( "woost.models.item.Item.included_in_static_publication", None ) for pub in Publishable.select(): value = pub._included_in_static_publication try: del pub._included_in_static_publication except AttributeError: pass else: pub.x_staticpub_exportable = value
def _install(self): from woost.models import (Publishable, Document, Controller, extension_translations) # Sitemap controller sitemap_controller = self._create_asset( Controller, "sitemap_controller", title=extension_translations, python_name= "woost.extensions.sitemap.sitemapcontroller.SitemapController") # Sitemap document sitemap_doc = self._create_asset(Document, "sitemap_document", title=extension_translations, path="sitemap_xml", per_language_publication=False, mime_type="text/xml", hidden=True, sitemap_indexable=False, controller=sitemap_controller) # Force indexing of the 'sitemap_indexable' member # (can't rely on defaults when executing queries) for item in Publishable.select(): if not hasattr(item, "_sitemap_indexable"): item.sitemap_indexable = \ item.sitemap_indexable and not item.hidden
def remove_document_resources(e): from woost.models import Publishable, Document, MemberPermission for document in Document.select(): try: del document._branch_resources except AttributeError: pass try: del document._page_resources except AttributeError: pass for publishable in Publishable.select(): try: del publishable._Document_branch_resources except AttributeError: pass try: del publishable._Document_page_resources except AttributeError: pass try: del publishable._inherit_resources except AttributeError: pass members = ("woost.models.document.Document.branch_resources", "woost.models.document.Document.page_resources", "woost.models.publishable.Publishable.inherit_resources") for permission in MemberPermission.select(): if permission.matching_members: removed = False for full_member_name in members: try: permission.matching_members.remove(full_member_name) except (KeyError, ValueError): pass else: removed = True if removed and not permission.matching_members: permission.delete()
def prefix_members(e): from woost.models import Publishable for pub in Publishable.select(): for key in ("priority", "change_frequency"): old_key = "sitemap_" + key try: value = getattr(pub, old_key) except AttributeError: pass else: delattr(pub, old_key) setattr(pub, "x_sitemap_" + key, 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 fix_opengraph_type_references(e): from woost.models import Publishable from .opengraphtype import OpenGraphType for og_type in OpenGraphType.select(): try: del og_type._Publishable_open_graph_type except AttributeError: pass for pub in Publishable.select(): try: og_type = pub._x_opengraph_type except AttributeError: pass else: del pub._x_opengraph_type pub.x_opengraph_type = og_type
def accessible_items(self): from woost.models import Publishable, IsAccessibleExpression return set(Publishable.select(IsAccessibleExpression(self.user)))