Ejemplo n.º 1
0
        def content_parser(selector):

            if selector.startswith("branch:"):
                doc_id = selector.split(":", 1)[1]
                try:
                    document = Document.require_instance(int(doc_id))
                except:
                    raise ArgumentTypeError(
                        f"{doc_id} is not a valid branch ID"
                    )
                else:
                    return ("branch", ("post", document))

            elif selector.startswith("delbranch:"):
                doc_id = selector.split(":", 1)[1]
                try:
                    document = Document.require_instance(int(doc_id))
                except:
                    raise ArgumentTypeError(
                        f"{doc_id} is not a valid branch ID"
                    )
                else:
                    return ("branch", ("delete", document))

            elif selector.startswith("item:"):
                pub_id = selector.split(":", 1)[1]
                try:
                    publishable = Publishable.require_instance(int(pub_id))
                except:
                    raise ArgumentTypeError(
                        f"{pub_id} is not a valid branch ID"
                    )
                else:
                    return ("item", ("post", publishable))

            elif selector.startswith("delitem:"):
                pub_id = selector.split(":", 1)[1]
                try:
                    publishable = Publishable.require_instance(int(pub_id))
                except:
                    raise ArgumentTypeError(
                        f"{pub_id} is not a valid branch ID"
                    )
                else:
                    return ("item", ("delete", publishable))

            elif selector.startswith("export:"):
                export_id = selector.split(":", 1)[1]
                try:
                    export = Export.require_instance(int(export_id))
                except:
                    raise ArgumentTypeError(
                        f"{export_id} is not a valid export ID"
                    )
                else:
                    return ("export", export)
Ejemplo n.º 2
0
def remove_attachments_member(e):

    from woost.models import Document, File, MemberPermission

    for document in Document.select():
        try:
            del document._attachments
        except AttributeError:
            pass

    for file in File.select():
        try:
            del file._Document_attachments
        except AttributeError:
            pass

    full_member_name = "woost.models.document.Document.attachment"

    for permission in MemberPermission.select():
        if permission.matching_members:
            member_count = len(permission.matching_members)
            try:
                permission.matching_members.remove(full_member_name)
            except (KeyError, ValueError):
                pass
            else:
                if member_count == 1:
                    permission.delete()
Ejemplo n.º 3
0
    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]
Ejemplo n.º 4
0
    def test_modified_member(self):

        from woost.models import ModifyTrigger, Item, Document

        self.assert_match(
            ModifyTrigger(matching_members=[
                "woost.models.item.Item.qname",
                "woost.models.document.Document.title"
            ]), (Item(), None, {
                "member": Item.qname
            }, True), (Item(), None, {
                "member": Item.global_id
            }, False), (Document(), None, {
                "member": Document.title
            }, True), (Document(), None, {
                "member": Document.hidden
            }, False))
Ejemplo n.º 5
0
def _get_news_properties(self):

    properties = Document.get_open_graph_properties(self)

    if self.summary:
        properties["og:description"] = export_content(self.summary)

    return properties
Ejemplo n.º 6
0
    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]
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
    def test_insert(self):

        from datetime import datetime
        from woost.models import (Document, User, ChangeSet, changeset_context)

        author = User()
        author.insert()

        with changeset_context(author) as changeset:
            item = Document()
            item.set("title", u"Foo!", "en")
            item.resource_type = u"text/foo"
            item.hidden = True
            assert not changeset.changes
            item.insert()

        assert list(ChangeSet.select()) == [changeset]
        assert changeset.author is author
        assert isinstance(changeset.date, datetime)

        assert changeset.changes.keys() == [item.id]
        change = changeset.changes[item.id]
        assert change.target is item
        assert change.action == "create"
        assert change.changeset is changeset
        assert item.changes == [change]

        for key in "id", "changes", "creation_time", "last_update_time":
            assert not key in change.item_state

        print change.item_state

        assert change.item_state["title"] == {"en": u"Foo!"}
        assert change.item_state["resource_type"] == u"text/foo"
        assert change.item_state["hidden"] == True
        assert change.item_state["translation_enabled"] == \
            {"en": item.get("translation_enabled", "en")}

        assert item.author is author
        assert item.creation_time
        assert item.last_update_time
        assert item.creation_time == item.last_update_time
Ejemplo n.º 9
0
    def inherited_resources(self):

        if self.inherit_resources and self.parent is None:
            catalog = Document.get_instance(
                qname = "woost.extensions.ecommerce.catalog_page"
            )

            if catalog:
                for resource in catalog.inherited_resources:
                    yield resource

                for resource in catalog.branch_resources:
                    yield resource        
        else:
            for resource in Publishable.inherited_resources.__get__(self):
                yield resource
Ejemplo n.º 10
0
#-*- coding: utf-8 -*-
u"""

.. moduleauthor:: Martí Congost <*****@*****.**>
"""
from cocktail import schema
from woost.models import Document

Document.add_member(
    schema.Boolean("ga_tracking_enabled",
                   default=True,
                   required=True,
                   member_group="meta"))

Document.is_ga_tracking_enabled = lambda self: self.ga_tracking_enabled
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
    def test_modify(self):

        from time import sleep
        from datetime import datetime
        from woost.models import (Document, User, ChangeSet, changeset_context)

        author = User()
        author.insert()

        with changeset_context(author) as creation:
            item = Document()
            item.set("title", u"Foo!", "en")
            item.resource_type = u"text/foo"
            item.hidden = True
            item.insert()

        # Make sure creation_time and last_update_time don't match
        sleep(0.1)

        with changeset_context(author) as modification:
            item.set("title", u"Bar!", "en")
            item.resource_type = u"text/bar"
            item.hidden = True

        assert list(ChangeSet.select()) == [creation, modification]
        assert modification.author is author
        assert isinstance(modification.date, datetime)

        assert modification.changes.keys() == [item.id]
        change = modification.changes[item.id]
        assert change.target is item
        assert change.action == "modify"
        assert change.changeset is modification
        assert change.changed_members == set(["title", "resource_type"])
        assert item.changes == [creation.changes[item.id], change]

        for key in "id", "changes", "creation_time", "last_update_time":
            assert not key in change.item_state

        assert change.item_state["title"] == {"en": u"Bar!"}
        assert change.item_state["resource_type"] == u"text/bar"
        assert change.item_state["hidden"] == True
        assert change.item_state["translation_enabled"] == \
            {"en": item.get("translation_enabled", "en")}

        assert item.author is author
        assert item.creation_time
        assert item.last_update_time
        assert not item.creation_time == item.last_update_time
Ejemplo n.º 13
0
#-*- coding: utf-8 -*-
u"""

.. moduleauthor:: Martí Congost <*****@*****.**>
"""
from cocktail.translations import translations
from cocktail import schema
from woost.models import Document

translations.load_bundle("woost.extensions.googleanalytics.document")

Document.add_member(
    schema.Boolean("x_googleanalytics_tracking_enabled",
        default = True,
        required = True,
        listed_by_default = False,
        member_group = "meta"
    )
)

Document.x_googleanalytics_tracking_should_track = \
    lambda self: self.x_googleanalytics_tracking_enabled

Ejemplo n.º 14
0
    def _install(self):

        from woost.models import (
            extension_translations,
            User,
            Controller,
            Document,
            StandardPage,
            Template,
            EmailTemplate
        )
        from woost.extensions.signup.signuppage import SignUpPage

        signup_controller = self._create_asset(
            Controller,
            "signup_controller",
            python_name =
                "woost.extensions.signup.signupcontroller.SignUpController",
            title = extension_translations
        )
        
        signup_confirmation_controller = self._create_asset(
            Controller,
            "signup_confirmation_controller",
            python_name = 
                "woost.extensions.signup.signupconfirmationcontroller."
                "SignUpConfirmationController",
            title = extension_translations
        )

        signup_view = self._create_asset(
            Template,
            "signup_template",
            identifier = "woost.extensions.signup.SignUpView",
            engine = u"cocktail",
            title = extension_translations
        )

        signup_confirmation_view = self._create_asset(
            Template,
            "signup_confirmation_template",
            identifier = u"woost.extensions.signup.SignUpConfirmationView",
            engine = u"cocktail",
            title = extension_translations
        )

        confirmation_email_template = self._create_asset(
            EmailTemplate,
            "signup_confirmation_email_template",
            python_name =
                u"woost.extensions.signup.signupconfirmationemailtemplate."
                "SignUpConfirmationEmailTemplate",
            template_engine = u"mako",
            sender = User.require_instance(qname="woost.administrator").email,
            receivers = u"[user.email]",
            title = extension_translations,
            subject = extension_translations,
            body = extension_translations
        )

        confirmation_target = self._create_asset(
            StandardPage,
            "signup_confirmation_target",
            title = extension_translations,
            controller = signup_confirmation_controller,
            template = signup_confirmation_view,
            hidden = True
        )

        signup_page = self._create_asset(
            SignUpPage,
            "signup_page",
            title = extension_translations,
            user_type = User,
            confirmation_target = confirmation_target,
            parent = Document.get_instance(qname="woost.home"),
        )

        signup_page.children.append(confirmation_target)