Exemplo n.º 1
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        self.p = Portal.objects.create()
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(title="Page 1-1", slug="page-1-1", parent=self.p1)
        self.p111 = Page.objects.create(title="Page 1-1-1", slug="page-1-1-1", parent=self.p11)
        self.p12 = Page.objects.create(title="Page 1-2", slug="page-1-2", parent=self.p1)

        # for i18n tests
        self.p2en = Page.objects.create(title="Page 2 (en)", slug="page-2",
                                        language='en')
        self.p2de = Page.objects.create(title="Page 2 (de)", slug="page-2",
                                      language='de', canonical=self.p2en)
        self.p2fr = Page.objects.create(title="Page 2 (fr)", slug="page-2",
                                        language='fr', canonical=self.p2en)

        self.anonymous = permissions.utils.register_role("Anonymous")
        self.permission = permissions.utils.register_permission("View", "view")
Exemplo n.º 2
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize

        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        self.p = Portal.objects.create()
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(title="Page 1-1", slug="page-1-1", parent=self.p1)
        self.p111 = Page.objects.create(title="Page 1-1-1", slug="page-1-1-1", parent=self.p11)
        self.p12 = Page.objects.create(title="Page 1-2", slug="page-1-2", parent=self.p1)

        # for i18n tests
        self.p2en = Page.objects.create(title="Page 2 (en)", slug="page-2", language="en")
        self.p2de = Page.objects.create(title="Page 2 (de)", slug="page-2", language="de", canonical=self.p2en)
        self.p2fr = Page.objects.create(title="Page 2 (fr)", slug="page-2", language="fr", canonical=self.p2en)

        self.anonymous = permissions.utils.register_role("Anonymous")
        self.permission = permissions.utils.register_permission("View", "view")
Exemplo n.º 3
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        self.p = Portal.objects.create()
        self.p.notification_emails = "[email protected], [email protected]"
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(title="Page 1-1",
                                       slug="page-1-1",
                                       parent=self.p1)
        self.p111 = Page.objects.create(title="Page 1-1-1",
                                        slug="page-1-1-1",
                                        parent=self.p11)
        self.p12 = Page.objects.create(title="Page 1-2",
                                       slug="page-1-2",
                                       parent=self.p1)
        self.p12 = Page.objects.create(title="Page 2", slug="page-2")

        self.anonymous = permissions.utils.register_role("Anonymous")
        self.permission = permissions.utils.register_permission("View", "view")
Exemplo n.º 4
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        Portal.objects.create()
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p2 = Page.objects.create(title="Page 2", slug="page-2")
Exemplo n.º 5
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize(create_resources=False)

        Portal.objects.create()
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p2 = Page.objects.create(title="Page 2", slug="page-2")
Exemplo n.º 6
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass
Exemplo n.º 7
0
    def setUp(self):
        from lfc.utils.initialize import initialize
        initialize()

        Portal.objects.create(id=1)
        self.p1 = Page.objects.create(id=1, title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(id=11, title="Page 1-1", slug="page-1-1", parent = self.p1)
        self.p2 = Page.objects.create(id=2, title="Page 2", slug="page-2")
        
        self.client = Client()
        self.client.login(username="******", password="******")
Exemplo n.º 8
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass
Exemplo n.º 9
0
    def setUp(self):
        from lfc.utils.initialize import initialize
        initialize()

        Portal.objects.create(id=1)
        self.p1 = Page.objects.create(id=1, title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(id=11,
                                       title="Page 1-1",
                                       slug="page-1-1",
                                       parent=self.p1)
        self.p2 = Page.objects.create(id=2, title="Page 2", slug="page-2")

        self.client = Client()
        self.client.login(username="******", password="******")
Exemplo n.º 10
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize(create_resources=False)

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        self.p = Portal.objects.create()
        self.p.notification_emails = "[email protected], [email protected]"
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
Exemplo n.º 11
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        Portal.objects.create()
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p2 = Page.objects.create(title="Page 2", slug="page-2")
Exemplo n.º 12
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        self.p = Portal.objects.create()
        self.p.notification_emails = "[email protected], [email protected]"
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
Exemplo n.º 13
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        self.p = Portal.objects.create()
        self.p.notification_emails = "[email protected], [email protected]"
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(title="Page 1-1", slug="page-1-1", parent=self.p1)
        self.p111 = Page.objects.create(title="Page 1-1-1", slug="page-1-1-1", parent=self.p11)
        self.p12 = Page.objects.create(title="Page 1-2", slug="page-1-2", parent=self.p1)
        self.p12 = Page.objects.create(title="Page 2", slug="page-2")

        self.anonymous = permissions.utils.register_role("Anonymous")
        self.permission = permissions.utils.register_permission("View", "view")
Exemplo n.º 14
0
    def setUp(self):
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        Portal.objects.create(id=1)
        self.p1 = Page.objects.create(id=1, title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(id=11, title="Page 1-1", slug="page-1-1", parent=self.p1)
        self.p2 = Page.objects.create(id=2, title="Page 2", slug="page-2")

        self.client = Client()
        self.client.login(username="******", password="******")
Exemplo n.º 15
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass

        self.p = Portal.objects.create()
        self.p.notification_emails = "[email protected], [email protected]"
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(title="Page 1-1", slug="page-1-1", parent=self.p1)
        self.p111 = Page.objects.create(title="Page 1-1-1", slug="page-1-1-1", parent=self.p11)
        self.p12 = Page.objects.create(title="Page 1-2", slug="page-1-2", parent=self.p1)
        self.p12 = Page.objects.create(title="Page 2", slug="page-2")

        self.anonymous = permissions.utils.register_role("Anonymous")
        self.permission = permissions.utils.register_permission("View", "view")
Exemplo n.º 16
0
    def setUp(self):
        """
        """
        from lfc.utils.initialize import initialize
        initialize(create_resources=False)

        self.p = Portal.objects.create()
        self.p1 = Page.objects.create(title="Page 1", slug="page-1")
        self.p11 = Page.objects.create(title="Page 1-1", slug="page-1-1", parent=self.p1)
        self.p111 = Page.objects.create(title="Page 1-1-1", slug="page-1-1-1", parent=self.p11)
        self.p12 = Page.objects.create(title="Page 1-2", slug="page-1-2", parent=self.p1)

        # for i18n tests
        self.p2en = Page.objects.create(title="Page 2 (en)", slug="page-2",
                                        language='en')
        self.p2de = Page.objects.create(title="Page 2 (de)", slug="page-2",
                                      language='de', canonical=self.p2en)
        self.p2fr = Page.objects.create(title="Page 2 (fr)", slug="page-2",
                                        language='fr', canonical=self.p2en)

        self.anonymous = permissions.utils.register_role("Anonymous")
        self.permission = permissions.utils.register_permission("View", "view")
def load_data():
    """This will create default portlets, templates and content types, simple
    Roles and two workflows at first the portal workflow which is adequate for 
    portals with different roles, like editor, reviewer, manager, etc.
    
    This can be used for portals.
    """
    # Register default portlets, templates and content types.
    initialize()
    
    # Register site
    site = Site.objects.all()[0]
    site.name = site.domain = "www.example.com"
    site.save()
    
    # Create portal
    portal = Portal.objects.create()

    # Register roles
    anonymous     = permissions.utils.register_role("Anonymous")
    owner         = permissions.utils.register_role("Owner")
    editor        = permissions.utils.register_role("Editor")
    reader        = permissions.utils.register_role("Reader")
    reviewer      = permissions.utils.register_role("Reviewer")
    manager       = permissions.utils.register_role("Manager")

    # Registers permissions
    add    = permissions.utils.register_permission("Add", "add")
    delete = permissions.utils.register_permission("Delete", "delete")
    edit   = permissions.utils.register_permission("Edit", "edit")
    view   = permissions.utils.register_permission("View", "view")

    ctype = ContentType.objects.get_for_model(Portal)
    manage_portal = permissions.utils.register_permission("Manage Portal", "manage_portal", [ctype])

    # Create slots
    left_slot, created = Slot.objects.get_or_create(name="Left")
    right_slot, created = Slot.objects.get_or_create(name="Right")

    # Set permissions for portal
    permissions.utils.grant_permission(portal, anonymous, "view")

    permissions.utils.grant_permission(portal, editor, "add", )
    permissions.utils.grant_permission(portal, editor, "delete")
    permissions.utils.grant_permission(portal, editor, "view")
    permissions.utils.grant_permission(portal, editor, "edit")

    permissions.utils.grant_permission(portal, manager, "add", )
    permissions.utils.grant_permission(portal, manager, "delete")
    permissions.utils.grant_permission(portal, manager, "edit")
    permissions.utils.grant_permission(portal, manager, "manage_portal")
    permissions.utils.grant_permission(portal, manager, "view")

    permissions.utils.grant_permission(portal, owner, "add")
    permissions.utils.grant_permission(portal, owner, "delete")
    permissions.utils.grant_permission(portal, owner, "edit")
    permissions.utils.grant_permission(portal, owner, "view")

    permissions.utils.grant_permission(portal, reader, "view")
    permissions.utils.grant_permission(portal, reviewer, "view")

    # Simple Workflow
    ##########################################################################

    # Add workflow
    workflow, created = Workflow.objects.get_or_create(name="Simple")

    # Add states
    private = State.objects.create(name="Private", workflow=workflow)
    public = State.objects.create(name="Public", workflow=workflow)

    # Create transitions
    make_public = Transition.objects.create(name="Make public", workflow=workflow, destination = public)
    make_private = Transition.objects.create(name="Make private", workflow=workflow, destination = private)

    # Add transitions
    private.transitions.add(make_public)
    public.transitions.add(make_private)

    # Add all permissions which are managed by the workflow
    WorkflowPermissionRelation.objects.create(workflow=workflow, permission=add)
    WorkflowPermissionRelation.objects.create(workflow=workflow, permission=delete)
    WorkflowPermissionRelation.objects.create(workflow=workflow, permission=edit)
    WorkflowPermissionRelation.objects.create(workflow=workflow, permission=view)

    # Add permissions for single states

    # Private
    StatePermissionRelation.objects.create(state=private, permission=add, role=owner)
    StatePermissionRelation.objects.create(state=private, permission=delete, role=owner)
    StatePermissionRelation.objects.create(state=private, permission=edit, role=owner)
    StatePermissionRelation.objects.create(state=private, permission=view, role=owner)

    StatePermissionRelation.objects.create(state=private, permission=add, role=manager)
    StatePermissionRelation.objects.create(state=private, permission=delete, role=manager)
    StatePermissionRelation.objects.create(state=private, permission=edit, role=manager)
    StatePermissionRelation.objects.create(state=private, permission=view, role=manager)

    # Public
    StatePermissionRelation.objects.create(state=public, permission=view, role=anonymous)

    StatePermissionRelation.objects.create(state=public, permission=view, role=editor)

    StatePermissionRelation.objects.create(state=public, permission=view, role=reader)

    StatePermissionRelation.objects.create(state=public, permission=view, role=reviewer)

    StatePermissionRelation.objects.create(state=public, permission=add, role=owner)
    StatePermissionRelation.objects.create(state=public, permission=delete, role=owner)
    StatePermissionRelation.objects.create(state=public, permission=edit, role=owner)
    StatePermissionRelation.objects.create(state=public, permission=view, role=owner)

    StatePermissionRelation.objects.create(state=public, permission=add, role=manager)
    StatePermissionRelation.objects.create(state=public, permission=delete, role=manager)
    StatePermissionRelation.objects.create(state=public, permission=edit, role=manager)
    StatePermissionRelation.objects.create(state=public, permission=view, role=manager)

    # Add inheritance block for single states
    StateInheritanceBlock.objects.create(state=private, permission=add)
    StateInheritanceBlock.objects.create(state=private, permission=delete)
    StateInheritanceBlock.objects.create(state=private, permission=edit)
    StateInheritanceBlock.objects.create(state=private, permission=view)

    StateInheritanceBlock.objects.create(state=public, permission=add)
    StateInheritanceBlock.objects.create(state=public, permission=delete)
    StateInheritanceBlock.objects.create(state=public, permission=edit)
    StateInheritanceBlock.objects.create(state=public, permission=view)

    # Define public state
    WorkflowStatesInformation.objects.create(state=public, public=True)

    # Define initial state
    workflow.initial_state = private
    workflow.save()

    # Portal Workflow
    ##########################################################################

    # Add workflow
    portal_workflow, created = Workflow.objects.get_or_create(name="Portal")

    # Add states
    private = State.objects.create(name="Private", workflow=portal_workflow)
    submitted = State.objects.create(name="Submitted", workflow=portal_workflow)
    public = State.objects.create(name="Public", workflow=portal_workflow)

    # Create transitions
    submit_t = Transition.objects.create(name="Submit", workflow=portal_workflow, destination = submitted)
    make_public = Transition.objects.create(name="Make public", workflow=portal_workflow, destination = public)
    make_private = Transition.objects.create(name="Make private", workflow=portal_workflow, destination = private)
    reject = Transition.objects.create(name="Reject", workflow=portal_workflow, destination = private)

    # Add transitions
    private.transitions.add(submit_t)
    submitted.transitions.add(make_public)
    submitted.transitions.add(reject)
    public.transitions.add(make_private)

    # Add all permissions which are managed by the workflow
    WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=add)
    WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=delete)
    WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=edit)
    WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=view)

    # Add permissions for single states

    # Private
    StatePermissionRelation.objects.create(state=private, permission=add, role=owner)
    StatePermissionRelation.objects.create(state=private, permission=delete, role=owner)
    StatePermissionRelation.objects.create(state=private, permission=edit, role=owner)
    StatePermissionRelation.objects.create(state=private, permission=view, role=owner)

    StatePermissionRelation.objects.create(state=private, permission=add, role=manager)
    StatePermissionRelation.objects.create(state=private, permission=delete, role=manager)
    StatePermissionRelation.objects.create(state=private, permission=edit, role=manager)
    StatePermissionRelation.objects.create(state=private, permission=view, role=manager)

    StateInheritanceBlock.objects.create(state=private, permission=add)
    StateInheritanceBlock.objects.create(state=private, permission=delete)
    StateInheritanceBlock.objects.create(state=private, permission=edit)
    StateInheritanceBlock.objects.create(state=private, permission=view)

    # Submitted
    StatePermissionRelation.objects.create(state=submitted, permission=view, role=owner)

    StatePermissionRelation.objects.create(state=submitted, permission=add,    role=manager)
    StatePermissionRelation.objects.create(state=submitted, permission=delete, role=manager)
    StatePermissionRelation.objects.create(state=submitted, permission=edit,   role=manager)
    StatePermissionRelation.objects.create(state=submitted, permission=view,   role=manager)

    StatePermissionRelation.objects.create(state=submitted, permission=add,    role=reviewer)
    StatePermissionRelation.objects.create(state=submitted, permission=delete, role=reviewer)
    StatePermissionRelation.objects.create(state=submitted, permission=edit,   role=reviewer)
    StatePermissionRelation.objects.create(state=submitted, permission=view,   role=reviewer)

    StateInheritanceBlock.objects.create(state=submitted, permission=add)
    StateInheritanceBlock.objects.create(state=submitted, permission=delete)
    StateInheritanceBlock.objects.create(state=submitted, permission=edit)
    StateInheritanceBlock.objects.create(state=submitted, permission=view)

    # Public
    StatePermissionRelation.objects.create(state=public, permission=add,    role=manager)
    StatePermissionRelation.objects.create(state=public, permission=delete, role=manager)
    StatePermissionRelation.objects.create(state=public, permission=edit,   role=manager)
    StatePermissionRelation.objects.create(state=public, permission=view,   role=manager)

    StatePermissionRelation.objects.create(state=public, permission=view, role=reader)

    StateInheritanceBlock.objects.create(state=public, permission=add)
    StateInheritanceBlock.objects.create(state=public, permission=delete)
    StateInheritanceBlock.objects.create(state=public, permission=edit)

    # Define public state
    WorkflowStatesInformation.objects.create(state=public, public=True)

    # Define review state
    WorkflowStatesInformation.objects.create(state=submitted, review=True)

    # Define initial state
    portal_workflow.initial_state = private
    portal_workflow.save()

    # Set workflow for Page
    ctype = ContentType.objects.get_for_model(Page)
    workflows.utils.set_workflow_for_model(ctype, portal_workflow)
Exemplo n.º 18
0
    def handle(self, *args, **options):

        initialize(create_resources=True)

        # Register site
        site = Site.objects.all()[0]
        site.name = site.domain = "www.example.com"
        site.save()

        # Create portal
        portal = Portal.objects.create()

        # Register roles
        anonymous = permissions.utils.register_role("Anonymous")

        # Registers permissions
        view = permissions.utils.register_permission("View", "view")

        # Create slots
        left_slot, created = Slot.objects.get_or_create(name="Left")
        right_slot, created = Slot.objects.get_or_create(name="Right")

        # Set permissions for portal
        permissions.utils.grant_permission(portal, anonymous, "view")

        # Simple Workflow
        ##########################################################################

        # Add workflow
        workflow, created = Workflow.objects.get_or_create(name="Simple")

        # Add states
        private = State.objects.create(name="Private", workflow=workflow)
        public = State.objects.create(name="Public", workflow=workflow)

        # Create transitions
        make_public = Transition.objects.create(name="Make public",
                                                workflow=workflow,
                                                destination=public)
        make_private = Transition.objects.create(name="Make private",
                                                 workflow=workflow,
                                                 destination=private)

        # Add transitions
        private.transitions.add(make_public)
        public.transitions.add(make_private)

        # Add all permissions which are managed by the workflow
        WorkflowPermissionRelation.objects.create(workflow=workflow,
                                                  permission=view)

        # Add permissions for single states
        # Private
        StateInheritanceBlock.objects.create(state=private, permission=view)

        # Define public state
        WorkflowStatesInformation.objects.create(state=public, public=True)

        # Define initial state
        workflow.initial_state = private
        workflow.save()

        # Set workflow for Page
        ctype = ContentType.objects.get_for_model(Page)
        workflows.utils.set_workflow_for_model(ctype, workflow)

        # Welcome Page
        page = Page.objects.create(title="Welcome to LFC",
                                   slug="welcome-to-lfc",
                                   text=WELCOME_DESCRIPTION)
        workflows.utils.set_state(page, public)

        portal.standard = page
        portal.save()
Exemplo n.º 19
0
    def handle(self, *args, **options):
        # Register default portlets, templates and content types.
        initialize(create_resources=True)

        # Register site
        site = Site.objects.all()[0]
        site.name = site.domain = "www.example.com"
        site.save()

        # Create portal
        portal = Portal.objects.create(id=1, title="LFC")

        # Register roles
        anonymous = permissions.utils.register_role("Anonymous")
        owner = permissions.utils.register_role("Owner")
        editor = permissions.utils.register_role("Editor")
        contributor = permissions.utils.register_role("Contributor")
        reviewer = permissions.utils.register_role("Reviewer")
        manager = permissions.utils.register_role("Manager")

        # Registers permissions
        add = permissions.utils.register_permission("Add", "add")
        delete = permissions.utils.register_permission("Delete", "delete")
        edit = permissions.utils.register_permission("Edit", "edit")
        view = permissions.utils.register_permission("View", "view")
        manage_local_roles = permissions.utils.register_permission("Manage local roles", "manage_local_roles")
        manage_permissions = permissions.utils.register_permission("Manage permissions", "manage_permissions")

        ctype = ContentType.objects.get_for_model(Portal)

        publish = permissions.utils.register_permission("Publish", "publish")
        submit = permissions.utils.register_permission("Submit", "submit")
        reject = permissions.utils.register_permission("Reject", "reject")
        retract = permissions.utils.register_permission("Retract", "retract")

        manage_portal = permissions.utils.register_permission("Manage portal", "manage_portal", [ctype])
        review = permissions.utils.register_permission("Review", "review", [ctype])

        # Create slots
        left_slot, created = Slot.objects.get_or_create(name="Left")
        right_slot, created = Slot.objects.get_or_create(name="Right")

        # Set permissions for portal
        permissions.utils.grant_permission(portal, anonymous, "view")

        permissions.utils.grant_permission(portal, editor, "delete")
        permissions.utils.grant_permission(portal, editor, "view")
        permissions.utils.grant_permission(portal, editor, "edit")
        permissions.utils.grant_permission(portal, editor, "retract")
        permissions.utils.grant_permission(portal, editor, "submit")

        permissions.utils.grant_permission(portal, manager, "add", )
        permissions.utils.grant_permission(portal, manager, "delete")
        permissions.utils.grant_permission(portal, manager, "edit")
        permissions.utils.grant_permission(portal, manager, "manage_local_roles")
        permissions.utils.grant_permission(portal, manager, "manage_permissions")
        permissions.utils.grant_permission(portal, manager, "manage_portal")
        permissions.utils.grant_permission(portal, manager, "view")
        permissions.utils.grant_permission(portal, manager, "submit")
        permissions.utils.grant_permission(portal, manager, "reject")
        permissions.utils.grant_permission(portal, manager, "review")
        permissions.utils.grant_permission(portal, manager, "publish")

        permissions.utils.grant_permission(portal, owner, "add")
        permissions.utils.grant_permission(portal, owner, "delete")
        permissions.utils.grant_permission(portal, owner, "edit")
        permissions.utils.grant_permission(portal, owner, "manage_local_roles")
        permissions.utils.grant_permission(portal, owner, "retract")
        permissions.utils.grant_permission(portal, owner, "submit")
        permissions.utils.grant_permission(portal, owner, "view")

        permissions.utils.grant_permission(portal, contributor, "add")
        permissions.utils.grant_permission(portal, contributor, "view")

        permissions.utils.grant_permission(portal, reviewer, "view")
        permissions.utils.grant_permission(portal, reviewer, "publish")
        permissions.utils.grant_permission(portal, reviewer, "reject")
        permissions.utils.grant_permission(portal, reviewer, "review")

        # Simple Workflow
        ##########################################################################

        # Add workflow
        workflow, created = Workflow.objects.get_or_create(name="Simple")

        # Add states
        private = State.objects.create(name="Private", workflow=workflow)
        public = State.objects.create(name="Public", workflow=workflow)

        # Create transitions
        make_public = Transition.objects.create(name="Make public", workflow=workflow, destination = public)
        make_private = Transition.objects.create(name="Make private", workflow=workflow, destination = private)

        # Add transitions
        private.transitions.add(make_public)
        public.transitions.add(make_private)

        # Add all permissions which are managed by the workflow
        WorkflowPermissionRelation.objects.create(workflow=workflow, permission=add)
        WorkflowPermissionRelation.objects.create(workflow=workflow, permission=delete)
        WorkflowPermissionRelation.objects.create(workflow=workflow, permission=edit)
        WorkflowPermissionRelation.objects.create(workflow=workflow, permission=view)

        # Add permissions for single states

        # Private
        StatePermissionRelation.objects.create(state=private, permission=add, role=owner)
        StatePermissionRelation.objects.create(state=private, permission=delete, role=owner)
        StatePermissionRelation.objects.create(state=private, permission=edit, role=owner)
        StatePermissionRelation.objects.create(state=private, permission=view, role=owner)

        StatePermissionRelation.objects.create(state=private, permission=add, role=manager)
        StatePermissionRelation.objects.create(state=private, permission=delete, role=manager)
        StatePermissionRelation.objects.create(state=private, permission=edit, role=manager)
        StatePermissionRelation.objects.create(state=private, permission=view, role=manager)

        # Public
        StatePermissionRelation.objects.create(state=public, permission=view, role=anonymous)

        StatePermissionRelation.objects.create(state=public, permission=view, role=editor)

        StatePermissionRelation.objects.create(state=public, permission=view, role=contributor)

        StatePermissionRelation.objects.create(state=public, permission=view, role=reviewer)

        StatePermissionRelation.objects.create(state=public, permission=add, role=owner)
        StatePermissionRelation.objects.create(state=public, permission=delete, role=owner)
        StatePermissionRelation.objects.create(state=public, permission=edit, role=owner)
        StatePermissionRelation.objects.create(state=public, permission=view, role=owner)

        StatePermissionRelation.objects.create(state=public, permission=add, role=manager)
        StatePermissionRelation.objects.create(state=public, permission=delete, role=manager)
        StatePermissionRelation.objects.create(state=public, permission=edit, role=manager)
        StatePermissionRelation.objects.create(state=public, permission=view, role=manager)

        # Add inheritance block for single states
        StateInheritanceBlock.objects.create(state=private, permission=add)
        StateInheritanceBlock.objects.create(state=private, permission=delete)
        StateInheritanceBlock.objects.create(state=private, permission=edit)
        StateInheritanceBlock.objects.create(state=private, permission=view)

        StateInheritanceBlock.objects.create(state=public, permission=add)
        StateInheritanceBlock.objects.create(state=public, permission=delete)
        StateInheritanceBlock.objects.create(state=public, permission=edit)
        StateInheritanceBlock.objects.create(state=public, permission=view)

        # Define public state
        WorkflowStatesInformation.objects.create(state=public, public=True)

        # Define initial state
        workflow.initial_state = private
        workflow.save()

        # Portal Workflow
        ##########################################################################

        # Add workflow
        portal_workflow, created = Workflow.objects.get_or_create(name="Portal")

        # Add states
        private = State.objects.create(name="Private", workflow=portal_workflow)
        submitted = State.objects.create(name="Submitted", workflow=portal_workflow)
        public = State.objects.create(name="Public", workflow=portal_workflow)

        # Create transitions
        submit_t = Transition.objects.create(name="Submit", workflow=portal_workflow, destination = submitted, permission=submit)
        make_public = Transition.objects.create(name="Make public", workflow=portal_workflow, destination = public, permission=publish)
        make_private = Transition.objects.create(name="Make private", workflow=portal_workflow, destination = private, permission=review)
        reject_t = Transition.objects.create(name="Reject", workflow=portal_workflow, destination = private, permission=reject)
        retract = Transition.objects.create(name="Retract", workflow=portal_workflow, destination = private, permission=retract)

        # Add transitions
        private.transitions.add(submit_t)
        private.transitions.add(make_public)
        submitted.transitions.add(make_public)
        submitted.transitions.add(reject_t)
        submitted.transitions.add(retract)
        public.transitions.add(make_private)
        public.transitions.add(retract)

        # Add all permissions which are managed by the workflow
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=add)
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=delete)
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=edit)
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow, permission=view)

        # Add permissions for single states

        # Private
        StatePermissionRelation.objects.create(state=private, permission=add, role=owner)
        StatePermissionRelation.objects.create(state=private, permission=delete, role=owner)
        StatePermissionRelation.objects.create(state=private, permission=edit, role=owner)
        StatePermissionRelation.objects.create(state=private, permission=view, role=owner)

        StatePermissionRelation.objects.create(state=private, permission=add, role=manager)
        StatePermissionRelation.objects.create(state=private, permission=delete, role=manager)
        StatePermissionRelation.objects.create(state=private, permission=edit, role=manager)
        StatePermissionRelation.objects.create(state=private, permission=view, role=manager)

        StatePermissionRelation.objects.create(state=private, permission=delete, role=editor)
        StatePermissionRelation.objects.create(state=private, permission=edit, role=editor)
        StatePermissionRelation.objects.create(state=private, permission=view, role=editor)

        StatePermissionRelation.objects.create(state=private, permission=add, role=contributor)
        StatePermissionRelation.objects.create(state=private, permission=view, role=contributor)

        StateInheritanceBlock.objects.create(state=private, permission=add)
        StateInheritanceBlock.objects.create(state=private, permission=delete)
        StateInheritanceBlock.objects.create(state=private, permission=edit)
        StateInheritanceBlock.objects.create(state=private, permission=view)

        # Submitted
        StatePermissionRelation.objects.create(state=submitted, permission=view, role=owner)

        StatePermissionRelation.objects.create(state=submitted, permission=add, role=manager)
        StatePermissionRelation.objects.create(state=submitted, permission=delete, role=manager)
        StatePermissionRelation.objects.create(state=submitted, permission=edit, role=manager)
        StatePermissionRelation.objects.create(state=submitted, permission=view, role=manager)

        StatePermissionRelation.objects.create(state=submitted, permission=delete, role=editor)
        StatePermissionRelation.objects.create(state=submitted, permission=edit, role=editor)
        StatePermissionRelation.objects.create(state=submitted, permission=view, role=editor)

        StatePermissionRelation.objects.create(state=submitted, permission=add, role=contributor)
        StatePermissionRelation.objects.create(state=submitted, permission=view, role=contributor)
        
        StatePermissionRelation.objects.create(state=submitted, permission=view, role=reviewer)

        StateInheritanceBlock.objects.create(state=submitted, permission=add)
        StateInheritanceBlock.objects.create(state=submitted, permission=delete)
        StateInheritanceBlock.objects.create(state=submitted, permission=edit)
        StateInheritanceBlock.objects.create(state=submitted, permission=view)

        # Public
        StatePermissionRelation.objects.create(state=public, permission=add, role=manager)
        StatePermissionRelation.objects.create(state=public, permission=delete, role=manager)
        StatePermissionRelation.objects.create(state=public, permission=edit, role=manager)
        StatePermissionRelation.objects.create(state=public, permission=view, role=manager)

        StatePermissionRelation.objects.create(state=public, permission=delete, role=editor)
        StatePermissionRelation.objects.create(state=public, permission=edit, role=editor)
        StatePermissionRelation.objects.create(state=public, permission=view, role=editor)

        StatePermissionRelation.objects.create(state=public, permission=view, role=owner)

        StatePermissionRelation.objects.create(state=public, permission=add, role=contributor)
        StatePermissionRelation.objects.create(state=public, permission=view, role=contributor)

        StatePermissionRelation.objects.create(state=public, permission=view, role=reviewer)

        StateInheritanceBlock.objects.create(state=public, permission=add)
        StateInheritanceBlock.objects.create(state=public, permission=delete)
        StateInheritanceBlock.objects.create(state=public, permission=edit)

        # Define public state
        WorkflowStatesInformation.objects.create(state=public, public=True)

        # Define review state
        WorkflowStatesInformation.objects.create(state=submitted, review=True)

        # Define initial state
        portal_workflow.initial_state = private
        portal_workflow.save()

        # Set workflow for Page
        ctype = ContentType.objects.get_for_model(Page)
        workflows.utils.set_workflow_for_model(ctype, portal_workflow)

        # Welcome Page
        creator = User.objects.filter()[0]
        page = Page.objects.create(title="Welcome to LFC", slug="welcome-to-lfc", text=WELCOME_DESCRIPTION, creator=creator)        
        workflows.utils.set_state(page, public)

        portal.standard = page
        portal.save()
Exemplo n.º 20
0
 def setUp(self):
     """
     """
     from lfc.utils.initialize import initialize
     initialize()
Exemplo n.º 21
0
 def setUp(self):
     """
     """
     from lfc.utils.initialize import initialize
     initialize(create_resources=False)
Exemplo n.º 22
0
    def handle(self, *args, **options):

        initialize()

        # Register site
        site = Site.objects.all()[0]
        site.name = site.domain = "www.example.com"
        site.save()

        # Create portal
        portal = Portal.objects.create()

        # Register roles
        anonymous = permissions.utils.register_role("Anonymous")

        # Registers permissions
        view = permissions.utils.register_permission("View", "view")

        # Create slots
        left_slot, created = Slot.objects.get_or_create(name="Left")
        right_slot, created = Slot.objects.get_or_create(name="Right")

        # Set permissions for portal
        permissions.utils.grant_permission(portal, anonymous, "view")

        # Simple Workflow
        ##########################################################################

        # Add workflow
        workflow, created = Workflow.objects.get_or_create(name="Simple")

        # Add states
        private = State.objects.create(name="Private", workflow=workflow)
        public = State.objects.create(name="Public", workflow=workflow)

        # Create transitions
        make_public = Transition.objects.create(name="Make public", workflow=workflow, destination=public)
        make_private = Transition.objects.create(name="Make private", workflow=workflow, destination=private)

        # Add transitions
        private.transitions.add(make_public)
        public.transitions.add(make_private)

        # Add all permissions which are managed by the workflow
        WorkflowPermissionRelation.objects.create(workflow=workflow, permission=view)

        # Add permissions for single states
        # Private
        StateInheritanceBlock.objects.create(state=private, permission=view)

        # Define public state
        WorkflowStatesInformation.objects.create(state=public, public=True)

        # Define initial state
        workflow.initial_state = private
        workflow.save()

        # Set workflow for Page
        ctype = ContentType.objects.get_for_model(Page)
        workflows.utils.set_workflow_for_model(ctype, workflow)

        # Welcome Page
        page = Page.objects.create(title="Welcome to LFC", slug="welcome-to-lfc", text=WELCOME_DESCRIPTION)
        workflows.utils.set_state(page, public)

        portal.standard = page
        portal.save()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass
Exemplo n.º 23
0
    def handle(self, *args, **options):
        # Register default portlets, templates and content types.
        initialize()

        # Register site
        site = Site.objects.all()[0]
        site.name = site.domain = "www.example.com"
        site.save()

        # Create portal
        portal = Portal.objects.create(id=1, title="LFC")

        # Register roles
        anonymous = permissions.utils.register_role("Anonymous")
        author = permissions.utils.register_role("Author")
        owner = permissions.utils.register_role("Owner")
        editor = permissions.utils.register_role("Editor")
        reviewer = permissions.utils.register_role("Reviewer")
        manager = permissions.utils.register_role("Manager")

        # Registers permissions
        add = permissions.utils.register_permission("Add", "add")
        delete = permissions.utils.register_permission("Delete", "delete")
        edit = permissions.utils.register_permission("Edit", "edit")
        view = permissions.utils.register_permission("View", "view")
        manage_local_roles = permissions.utils.register_permission(
            "Manage local roles", "manage_local_roles")
        manage_permissions = permissions.utils.register_permission(
            "Manage permissions", "manage_permissions")
        view_management = permissions.utils.register_permission(
            "View management", "view_management")

        publish = permissions.utils.register_permission("Publish", "publish")
        submit = permissions.utils.register_permission("Submit", "submit")
        reject = permissions.utils.register_permission("Reject", "reject")
        retract = permissions.utils.register_permission("Retract", "retract")

        ctype = ContentType.objects.get_for_model(Portal)
        manage_portal = permissions.utils.register_permission(
            "Manage portal", "manage_portal", [ctype])
        review = permissions.utils.register_permission("Review", "review",
                                                       [ctype])

        # Create slots
        left_slot, created = Slot.objects.get_or_create(name="Left")
        right_slot, created = Slot.objects.get_or_create(name="Right")

        # Set permissions for portal
        permissions.utils.grant_permission(portal, anonymous, "view")

        permissions.utils.grant_permission(portal, author, "view_management")
        permissions.utils.grant_permission(portal, author, "add")

        permissions.utils.grant_permission(portal, editor, "view_management")
        permissions.utils.grant_permission(portal, editor, "delete")
        permissions.utils.grant_permission(portal, editor, "view")
        permissions.utils.grant_permission(portal, editor, "edit")
        permissions.utils.grant_permission(portal, editor, "retract")
        permissions.utils.grant_permission(portal, editor, "submit")

        permissions.utils.grant_permission(portal, manager, "view_management")
        permissions.utils.grant_permission(
            portal,
            manager,
            "add",
        )
        permissions.utils.grant_permission(portal, manager, "delete")
        permissions.utils.grant_permission(portal, manager, "edit")
        permissions.utils.grant_permission(portal, manager,
                                           "manage_local_roles")
        permissions.utils.grant_permission(portal, manager,
                                           "manage_permissions")
        permissions.utils.grant_permission(portal, manager, "manage_portal")
        permissions.utils.grant_permission(portal, manager, "view")
        permissions.utils.grant_permission(portal, manager, "submit")
        permissions.utils.grant_permission(portal, manager, "reject")
        permissions.utils.grant_permission(portal, manager, "review")
        permissions.utils.grant_permission(portal, manager, "publish")

        permissions.utils.grant_permission(portal, owner, "add")
        permissions.utils.grant_permission(portal, owner, "delete")
        permissions.utils.grant_permission(portal, owner, "edit")
        permissions.utils.grant_permission(portal, owner, "manage_local_roles")
        permissions.utils.grant_permission(portal, owner, "retract")
        permissions.utils.grant_permission(portal, owner, "submit")
        permissions.utils.grant_permission(portal, owner, "view")

        permissions.utils.grant_permission(portal, reviewer, "view_management")
        permissions.utils.grant_permission(portal, reviewer, "view")
        permissions.utils.grant_permission(portal, reviewer, "publish")
        permissions.utils.grant_permission(portal, reviewer, "reject")
        permissions.utils.grant_permission(portal, reviewer, "review")

        # Simple Workflow
        ##########################################################################

        # Add workflow
        workflow, created = Workflow.objects.get_or_create(name="Simple")

        # Add states
        private = State.objects.create(name="Private", workflow=workflow)
        public = State.objects.create(name="Public", workflow=workflow)

        # Create transitions
        make_public = Transition.objects.create(name="Make public",
                                                workflow=workflow,
                                                destination=public)
        make_private = Transition.objects.create(name="Make private",
                                                 workflow=workflow,
                                                 destination=private)

        # Add transitions
        private.transitions.add(make_public)
        public.transitions.add(make_private)

        # Add all permissions which are managed by the workflow
        WorkflowPermissionRelation.objects.create(workflow=workflow,
                                                  permission=add)
        WorkflowPermissionRelation.objects.create(workflow=workflow,
                                                  permission=delete)
        WorkflowPermissionRelation.objects.create(workflow=workflow,
                                                  permission=edit)
        WorkflowPermissionRelation.objects.create(workflow=workflow,
                                                  permission=view)

        # Add permissions for single states

        # Private
        StatePermissionRelation.objects.create(state=private,
                                               permission=add,
                                               role=owner)
        StatePermissionRelation.objects.create(state=private,
                                               permission=delete,
                                               role=owner)
        StatePermissionRelation.objects.create(state=private,
                                               permission=edit,
                                               role=owner)
        StatePermissionRelation.objects.create(state=private,
                                               permission=view,
                                               role=owner)

        StatePermissionRelation.objects.create(state=private,
                                               permission=add,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=delete,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=edit,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=view,
                                               role=manager)

        # Public
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=anonymous)

        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=editor)

        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=reviewer)

        StatePermissionRelation.objects.create(state=public,
                                               permission=add,
                                               role=owner)
        StatePermissionRelation.objects.create(state=public,
                                               permission=delete,
                                               role=owner)
        StatePermissionRelation.objects.create(state=public,
                                               permission=edit,
                                               role=owner)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=owner)

        StatePermissionRelation.objects.create(state=public,
                                               permission=add,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=delete,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=edit,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=manager)

        # Add inheritance block for single states
        StateInheritanceBlock.objects.create(state=private, permission=add)
        StateInheritanceBlock.objects.create(state=private, permission=delete)
        StateInheritanceBlock.objects.create(state=private, permission=edit)
        StateInheritanceBlock.objects.create(state=private, permission=view)

        StateInheritanceBlock.objects.create(state=public, permission=add)
        StateInheritanceBlock.objects.create(state=public, permission=delete)
        StateInheritanceBlock.objects.create(state=public, permission=edit)
        StateInheritanceBlock.objects.create(state=public, permission=view)

        # Define public state
        WorkflowStatesInformation.objects.create(state=public, public=True)

        # Define initial state
        workflow.initial_state = private
        workflow.save()

        # Portal Workflow
        ##########################################################################

        # Add workflow
        portal_workflow, created = Workflow.objects.get_or_create(
            name="Portal")

        # Add states
        private = State.objects.create(name="Private",
                                       workflow=portal_workflow)
        submitted = State.objects.create(name="Submitted",
                                         workflow=portal_workflow)
        public = State.objects.create(name="Public", workflow=portal_workflow)

        # Create transitions
        submit_t = Transition.objects.create(name="Submit",
                                             workflow=portal_workflow,
                                             destination=submitted,
                                             permission=submit)
        make_public = Transition.objects.create(name="Make public",
                                                workflow=portal_workflow,
                                                destination=public,
                                                permission=publish)
        make_private = Transition.objects.create(name="Make private",
                                                 workflow=portal_workflow,
                                                 destination=private,
                                                 permission=review)
        reject_t = Transition.objects.create(name="Reject",
                                             workflow=portal_workflow,
                                             destination=private,
                                             permission=reject)
        retract = Transition.objects.create(name="Retract",
                                            workflow=portal_workflow,
                                            destination=private,
                                            permission=retract)

        # Add transitions
        private.transitions.add(submit_t)
        private.transitions.add(make_public)
        submitted.transitions.add(make_public)
        submitted.transitions.add(reject_t)
        submitted.transitions.add(retract)
        public.transitions.add(make_private)
        public.transitions.add(retract)

        # Add all permissions which are managed by the workflow
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow,
                                                  permission=add)
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow,
                                                  permission=delete)
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow,
                                                  permission=edit)
        WorkflowPermissionRelation.objects.create(workflow=portal_workflow,
                                                  permission=view)

        # Add permissions for single states

        # Private
        StatePermissionRelation.objects.create(state=private,
                                               permission=add,
                                               role=author)
        StatePermissionRelation.objects.create(state=private,
                                               permission=delete,
                                               role=editor)
        StatePermissionRelation.objects.create(state=private,
                                               permission=edit,
                                               role=editor)
        StatePermissionRelation.objects.create(state=private,
                                               permission=view,
                                               role=editor)
        StatePermissionRelation.objects.create(state=private,
                                               permission=add,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=delete,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=edit,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=view,
                                               role=manager)
        StatePermissionRelation.objects.create(state=private,
                                               permission=delete,
                                               role=owner)
        StatePermissionRelation.objects.create(state=private,
                                               permission=edit,
                                               role=owner)
        StatePermissionRelation.objects.create(state=private,
                                               permission=view,
                                               role=owner)

        StateInheritanceBlock.objects.create(state=private, permission=add)
        StateInheritanceBlock.objects.create(state=private, permission=delete)
        StateInheritanceBlock.objects.create(state=private, permission=edit)
        StateInheritanceBlock.objects.create(state=private, permission=view)

        # Submitted
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=add,
                                               role=author)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=view,
                                               role=owner)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=add,
                                               role=manager)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=delete,
                                               role=manager)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=edit,
                                               role=manager)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=view,
                                               role=manager)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=delete,
                                               role=editor)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=edit,
                                               role=editor)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=view,
                                               role=editor)
        StatePermissionRelation.objects.create(state=submitted,
                                               permission=view,
                                               role=reviewer)

        StateInheritanceBlock.objects.create(state=submitted, permission=add)
        StateInheritanceBlock.objects.create(state=submitted,
                                             permission=delete)
        StateInheritanceBlock.objects.create(state=submitted, permission=edit)
        StateInheritanceBlock.objects.create(state=submitted, permission=view)

        # Public
        StatePermissionRelation.objects.create(state=public,
                                               permission=add,
                                               role=author)
        StatePermissionRelation.objects.create(state=public,
                                               permission=delete,
                                               role=editor)
        StatePermissionRelation.objects.create(state=public,
                                               permission=edit,
                                               role=editor)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=editor)
        StatePermissionRelation.objects.create(state=public,
                                               permission=add,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=delete,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=edit,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=anonymous)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=manager)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=owner)
        StatePermissionRelation.objects.create(state=public,
                                               permission=view,
                                               role=reviewer)

        StateInheritanceBlock.objects.create(state=public, permission=add)
        StateInheritanceBlock.objects.create(state=public, permission=delete)
        StateInheritanceBlock.objects.create(state=public, permission=edit)
        StateInheritanceBlock.objects.create(state=public, permission=view)

        # Define public state
        WorkflowStatesInformation.objects.create(state=public, public=True)

        # Define review state
        WorkflowStatesInformation.objects.create(state=submitted, review=True)

        # Define initial state
        portal_workflow.initial_state = private
        portal_workflow.save()

        # Set workflow for Page
        ctype = ContentType.objects.get_for_model(Page)
        workflows.utils.set_workflow_for_model(ctype, portal_workflow)

        # Welcome Page
        creator = User.objects.filter()[0]
        page = Page.objects.create(title="Welcome to LFC",
                                   slug="welcome-to-lfc",
                                   text=WELCOME_DESCRIPTION,
                                   creator=creator)
        workflows.utils.set_state(page, public)

        portal.standard = page
        portal.save()

        import_module("lfc_page").install()
        try:
            Application.objects.create(name="lfc_page")
        except Application.DoesNotExist:
            pass
def load_data():
    """This will create default portlets, templates and content types, simple
    Roles and a simple workflow (just private and public).
    
    This can be used for small sites without different roles.
    """
    # Register default portlets, templates and content types.
    initialize()

    # Register site
    site = Site.objects.all()[0]
    site.name = site.domain = "www.example.com"
    site.save()

    # Create portal
    portal = Portal.objects.create()

    # Register roles
    anonymous = permissions.utils.register_role("Anonymous")

    # Registers permissions
    view = permissions.utils.register_permission("View", "view")

    # Create slots
    left_slot, created = Slot.objects.get_or_create(name="Left")
    right_slot, created = Slot.objects.get_or_create(name="Right")

    # Set permissions for portal
    permissions.utils.grant_permission(portal, anonymous, "view")

    # Simple Workflow
    ##########################################################################

    # Add workflow
    workflow, created = Workflow.objects.get_or_create(name="Simple")

    # Add states
    private = State.objects.create(name="Private", workflow=workflow)
    public = State.objects.create(name="Public", workflow=workflow)

    # Create transitions
    make_public = Transition.objects.create(name="Make public", workflow=workflow, destination=public)
    make_private = Transition.objects.create(name="Make private", workflow=workflow, destination=private)

    # Add transitions
    private.transitions.add(make_public)
    public.transitions.add(make_private)

    # Add all permissions which are managed by the workflow
    WorkflowPermissionRelation.objects.create(workflow=workflow, permission=view)

    # Add permissions for single states
    # Private
    StateInheritanceBlock.objects.create(state=private, permission=view)

    # Define public state
    WorkflowStatesInformation.objects.create(state=public, public=True)

    # Define initial state
    workflow.initial_state = private
    workflow.save()

    # Set workflow for Page
    ctype = ContentType.objects.get_for_model(Page)
    workflows.utils.set_workflow_for_model(ctype, workflow)