Ejemplo n.º 1
0
        def setUpPloneSite(self, portal):
            self.applyProfile(portal, 'plone.app.dexterity:default')

            # Register two portal_types.
            self._add_folder_type(portal)
            builder_registry.register('Folder', FolderBuilder)

            # Install our profile at the end, because we change the
            # type info of the Folder.
            self.applyProfile(portal, 'ftw.contenttemplates:default')
Ejemplo n.º 2
0
                         content_type='message/rfc822',
                         data=self.data,
                         portal_type='ftw.mail.mail')
        return result['success']

    def with_message(self, data, filename=None):
        self.data = data
        if filename:
            self.filename = filename
        return self

    def with_asset_message(self, filename):
        self.with_message(assets.load(filename), unicode(filename))
        return self

builder_registry.register('quickuploaded_mail', QuickuploadMailBuilder)


class QuickuploadDocumentBuilder(PloneObjectBuilder):

    def __init__(self, session):
        super(QuickuploadDocumentBuilder, self).__init__(session)
        self.data = None
        self.filename = 'document.txt'
        self.content_type = 'text/plain'

    def create_object(self, **kwargs):
        factory = IQuickUploadFileFactory(self.container)
        assert factory, 'invalid container'

        result = factory(filename=self.filename,
Ejemplo n.º 3
0
from ftw.builder.dexterity import DexterityBuilder
from ftw.builder import builder_registry


class DXFolderBuilder(DexterityBuilder):
    portal_type = 'dxfolder'


builder_registry.register('dxfolder', DXFolderBuilder)
Ejemplo n.º 4
0
                       profile=self.profile_builder.profile_name,
                       directory='.')
        zcml._upgrade_step_declarations[self.profile_builder.name] = True

    def _create_upgrade(self):
        name = self.name.replace(' ', '_').replace('\.$', '')
        step_name = '{0}_{1}'.format(self.destination_version,
                                     inflection.underscore(name))
        if self.code is None:
            self.code = scaffold.PYTHON_TEMPLATE.format(
                classname=inflection.camelize(name),
                docstring=inflection.humanize(inflection.underscore(name)))

        self.package.with_file(os.path.join(step_name, '__init__.py'),
                               '',
                               makedirs=True)

        self.package.with_file(os.path.join(step_name, 'upgrade.py'),
                               self.code)
        return step_name

    def _register_files_and_dirs_in_package_builder(self, step_name):
        for relative_path in self.directories:
            self.package.with_directory(os.path.join(step_name, relative_path))

        for path, contents in self.files:
            self.package.with_file(os.path.join(step_name, path), contents)


builder_registry.register('ftw upgrade step', UpgradeStepBuilder)
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder


class DexterityTypeBuilder(DexterityBuilder):
    portal_type = 'DexterityType'


builder_registry.register('dexterity type', DexterityTypeBuilder)
Ejemplo n.º 6
0
from ftw.builder import Builder
from ftw.builder import builder_registry
from ftw.builder import create


class RepositoryTreeBuilder(object):
    """Meta builder to create a simple repository-tree."""
    def __init__(self, session):
        self.session = session

    def create(self):
        repository_root = create(Builder('repository_root'))
        repository_folder = create(
            Builder('repository').within(repository_root))

        return repository_root, repository_folder


builder_registry.register('repository_tree', RepositoryTreeBuilder)
Ejemplo n.º 7
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from ftw.simplelayout.tests import builders
from ftw.slider.tests import builders


class SliderBlockBuilder(DexterityBuilder):
    portal_type = 'ftw.sliderblock.SliderBlock'

builder_registry.register('sliderblock', SliderBlockBuilder)
Ejemplo n.º 8
0
    def with_labels(self, *labels):
        self.labels.extend(labels)
        return self

    def after_create(self, obj):
        super(LabelRootBuilder, self).after_create(obj)
        jar = ILabelJar(obj)
        for title, color in self.labels:
            jar.add(title, color)

        if self.session.auto_commit:
            transaction.commit()


builder_registry.register('label root', LabelRootBuilder)


class LabelDisplayBuilder(ArchetypesBuilder):

    portal_type = 'Folder'

    def __init__(self, *args, **kwargs):
        super(LabelDisplayBuilder, self).__init__(*args, **kwargs)
        self.providing(ILabelJarChild)


builder_registry.register('label display', LabelDisplayBuilder)


class LabelledPageBuilder(ArchetypesBuilder):
Ejemplo n.º 9
0
            'scope': 'global',
        }
        self.owner = None

    def having(self, **kwargs):
        self.arguments.update(kwargs)
        return self

    def titled(self, title):
        self.arguments['title'] = title
        return self

    def owned_by(self, owner):
        self.owner = owner
        return self

    def create(self, **kwargs):
        action = {}
        action.update(self.arguments)
        storage = getMultiAdapter((getSite(), getRequest()),
                                  IWebActionsStorage)
        action_id = storage.add(action)

        if self.owner is not None:
            storage._actions[action_id]['owner'] = self.owner

        return storage.get(action_id)


builder_registry.register('webaction', WebActionBuilder)
Ejemplo n.º 10
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder


class DexterityFolderBuilder(DexterityBuilder):
    portal_type = 'DexterityFolder'


builder_registry.register('dexterity folder', DexterityFolderBuilder)
Ejemplo n.º 11
0
from ftw.builder.dexterity import DexterityBuilder
from ftw.builder import builder_registry


class EGovServiceBuilder(DexterityBuilder):

    portal_type = 'izug.refegovservice.egovservice'


builder_registry.register('egov service', EGovServiceBuilder)


class RefEgovServiceBuilder(DexterityBuilder):

    portal_type = 'izug.refegovservice.refegovservice'

builder_registry.register('ref egov service', RefEgovServiceBuilder)
Ejemplo n.º 12
0
            'title': 'Key Title',
        }

    def having(self, **kwargs):
        self.arguments.update(kwargs)
        return self

    def create(self, **kwargs):
        private_key, service_key = self.plugin.issue_keypair(
            self.arguments.get('user_id'), self.arguments.get('title'),
            self.arguments.get('ip_range'))

        return service_key


builder_registry.register('service_key', ServiceKeyBuilder)


class KeyPairBuilder(object):
    """Creates a key pair consisting of private_key and service_key.

    The service_key is NOT persisted in storage, so this builder can be used
    in unit tests (no dependency on Plone at all), and for tests that require
    the use of both the private and the public keys (like signing JWTs).

    On the other hand, it obviously can't be used in tests where persistence
    of the service_key in storage is required.
    """
    def __init__(self, session):
        self.session = session
        self.arguments = {
Ejemplo n.º 13
0
from ftw.builder import builder_registry
from ftw.builder.content import ImageBuilderMixin
from ftw.builder.dexterity import DexterityBuilder


class NoticeBoardBuilder(DexterityBuilder):
    portal_type = 'ftw.noticeboard.NoticeBoard'


builder_registry.register('noticeboard', NoticeBoardBuilder)


class NoticeCategoryBuilder(DexterityBuilder):
    portal_type = 'ftw.noticeboard.NoticeCategory'


builder_registry.register('noticecategory', NoticeCategoryBuilder)


class NoticeBuilder(DexterityBuilder):
    portal_type = 'ftw.noticeboard.Notice'


builder_registry.register('notice', NoticeBuilder)


class NoticeImageBuilder(ImageBuilderMixin, DexterityBuilder):
    portal_type = 'ftw.noticeboard.NoticeImage'


builder_registry.register('noticeimage', NoticeImageBuilder)
Ejemplo n.º 14
0
from ftw.builder.dexterity import DexterityBuilder
from ftw.builder import builder_registry


class SubsiteBuilder(DexterityBuilder):

    portal_type = 'ftw.subsite.Subsite'

    def with_language(self, language_code):
        if 'title' not in self.arguments:
            return self.having(force_language=language_code,
                               title=language_code)
        else:
            return self.having(force_language=language_code)


builder_registry.register('subsite', SubsiteBuilder)
Ejemplo n.º 15
0
from ftw.lawgiver.tests.helpers import EXAMPLE_WF_DEF
from ftw.lawgiver.tests.helpers import EXAMPLE_WF_SPEC
from ftw.lawgiver.tests.helpers import EXAMPLE_WORKFLOW_DIR


class PackageWithWorkflowBuilder(object):
    def __init__(self, session):
        self.session = session
        self.profile_builder = (Builder('genericsetup profile').with_file(
            'workflows/{}/specification.txt'.format(EXAMPLE_WORKFLOW_DIR.name),
            EXAMPLE_WF_SPEC.bytes(),
            makedirs=True).with_file('workflows/{}/definition.xml'.format(
                EXAMPLE_WORKFLOW_DIR.name),
                                     EXAMPLE_WF_DEF.bytes(),
                                     makedirs=True))

        self.package_builder = (
            Builder('python package').named('the.package').with_profile(
                self.profile_builder).with_directory(
                    'locales/de/LC_MESSAGES').with_directory('upgrades'))

    def with_layer(self, layer):
        self.package_builder.at_path(layer['temp_directory'])
        return self

    def create(self, **kwargs):
        return self.package_builder.create(**kwargs)


builder_registry.register('package with workflow', PackageWithWorkflowBuilder)
Ejemplo n.º 16
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from ftw.simplelayout.tests import builders


class HtmlBlockBuilder(DexterityBuilder):
    portal_type = 'ftw.htmlblock.HtmlBlock'


builder_registry.register('html block', HtmlBlockBuilder)
Ejemplo n.º 17
0
from ftw.builder.archetypes import ArchetypesBuilder
from ftw.builder import builder_registry


class ParagraphBuilder(ArchetypesBuilder):

    portal_type = 'Paragraph'

builder_registry.register('paragraph', ParagraphBuilder)

class PageBuilder(ArchetypesBuilder):

    portal_type = 'Page'

builder_registry.register('sl-page', PageBuilder)
Ejemplo n.º 18
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from plone.namedfile.file import NamedImage
from StringIO import StringIO


class SliderContainerBuilder(DexterityBuilder):
    portal_type = 'ftw.slider.Container'

builder_registry.register('slider container', SliderContainerBuilder)


class SliderPaneBuilder(DexterityBuilder):
    portal_type = 'ftw.slider.Pane'

    def with_dummy_image(self):
        dummy_image = StringIO(
            'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00'
            '\x00!\xf9\x04\x04\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00'
            '\x01\x00\x00\x02\x02D\x01\x00;')

        self.arguments["image"] = NamedImage(dummy_image.read(),
                                                 filename=u"image.gif")
        return self

builder_registry.register('slider pane', SliderPaneBuilder)
Ejemplo n.º 19
0
        self.update_fullname(firstname, lastname)
        self.update_email(firstname, lastname)

    def update_fullname(self, firstname, lastname):
        if not self.properties.get('fullname', None):
            self.properties['fullname'] = ' '.join((lastname, firstname))

    def update_email(self, firstname, lastname):
        if not self.properties.get('email', None):
            firstname = self.normalize_name_for_email(firstname)
            lastname = self.normalize_name_for_email(lastname)
            email = '%s@%s.com' % (firstname, lastname)
            self.properties['email'] = email

    def update_userid_and_username(self, firstname, lastname):
        if self.userid is None:
            normalizer = getUtility(IIDNormalizer)
            first = normalizer.normalize(firstname)
            last = normalizer.normalize(lastname)
            self.userid = '.'.join((first, last))

        if not self.properties.get('username', None):
            self.properties['username'] = self.userid

    def normalize_name_for_email(self, name):
        name = name.lower()
        name = name.replace(' ', '-')
        return strip_diacricits(name)

builder_registry.register('user', UserBuilder)
Ejemplo n.º 20
0
            data=self.data,
            portal_type='ftw.mail.mail')
        return result['success']

    def with_message(self, data, filename=None):
        self.data = data
        if filename:
            self.filename = filename
        return self

    def with_asset_message(self, filename):
        self.with_message(assets.load(filename), unicode(filename))
        return self


builder_registry.register('quickuploaded_mail', QuickuploadMailBuilder)


class QuickuploadDocumentBuilder(PloneObjectBuilder):
    def __init__(self, session):
        super(QuickuploadDocumentBuilder, self).__init__(session)
        self.data = None
        self.filename = 'document.txt'
        self.content_type = 'text/plain'

    def create_object(self, **kwargs):
        factory = IQuickUploadFileFactory(self.container)
        assert factory, 'invalid container'

        result = factory(
            filename=self.filename,
Ejemplo n.º 21
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from ftw.simplelayout.tests import builders


class CollectionBlockBuilder(DexterityBuilder):
    portal_type = 'ftw.collectionblock.CollectionBlock'

    def with_default_query(self):
        self.arguments['query'] = [{
            'i': 'Type',
            'o': 'plone.app.querystring.operation.string.is',
            'v': 'ContentPage',
        }]
        return self


builder_registry.register('sl collectionblock', CollectionBlockBuilder)
Ejemplo n.º 22
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from plone.namedfile.file import NamedBlobFile


class DXItemBuilder(DexterityBuilder):
    portal_type = 'DXItem'

    def attach_image(self, image_asset):
        image = NamedBlobFile(data=image_asset.bytes(),
                              filename=unicode(image_asset.name))
        return self.having(image_field=image)

    def attach_file(self, file_asset):
        file_ = NamedBlobFile(data=file_asset.bytes(),
                              filename=unicode(file_asset.name))
        return self.having(file_field=file_)


builder_registry.register('dx item', DXItemBuilder)
Ejemplo n.º 23
0
    def with_layout(self, layout_iface):
        dotted_name = '.'.join(
            (layout_iface.__module__, layout_iface.__name__))
        self.having(latex_layout=dotted_name)
        self.apply_layer = layout_iface
        return self

    def after_create(self, obj):
        provide_request_layer(obj.REQUEST, IWithinBookLayer)
        if self.apply_layer:
            provide_request_layer(obj.REQUEST, self.apply_layer)
        super(BookBuilder, self).after_create(obj)


builder_registry.register('book', BookBuilder)


class ChapterBuilder(ArchetypesBuilder):

    portal_type = 'Chapter'


builder_registry.register('chapter', ChapterBuilder)


class TextBlockBuilder(ArchetypesBuilder):

    portal_type = 'BookTextBlock'

Ejemplo n.º 24
0
        attributes.update(self.arguments)

        # Calculate some computed values based on merged attributes
        attributes['fullname'] = ' '.join([attributes['firstname'],
                                           attributes['lastname']])
        attributes['displayName'] = attributes['fullname']
        attributes['email'] = "{}@4teamwork.ch".format(attributes['userid'])

        # Overlay arguments again to make sure specified values take precedence
        attributes.update(self.arguments)
        dn = USER_DN_TEMPLATE.format(attributes['userid'])
        obj = (dn, attributes)
        return obj


builder_registry.register('ldapuser', LDAPUserBuilder)


GROUP_TEMPLATE = {
    'cn': 'og_mandant1_users',
    'objectClass': ['groupOfUniqueNames', 'top'],
    'uniqueMember': [
        'cn=Sekretariat1 Mandant1,ou=Users,ou=Dev,ou=OneGovGEVER,dc=4teamwork,dc=ch',
        'cn=Sekretariat2 Mandant1,ou=Users,ou=Dev,ou=OneGovGEVER,dc=4teamwork,dc=ch',
    ]
}

GROUP_DN_TEMPLATE = "cn={},ou=Groups,ou=Dev,ou=OneGovGEVER,dc=4teamwork,dc=ch"


class LDAPGroupBuilder(object):
Ejemplo n.º 25
0
        return self

    def watchers(self, watchers):
        if isinstance(watchers, list):
            watchers = set(watchers)

        self._watchers = watchers
        return self

    def after_create(self, obj):
        for watcher in self._watchers:
            obj.add_watcher(watcher.actorid, WATCHER_ROLE)
        return obj


builder_registry.register('resource', ResourceBuilder)


class WatcherBuilder(SqlObjectBuilder):

    mapped_class = Watcher
    id_argument_name = 'watcher_id'


builder_registry.register('watcher', WatcherBuilder)


class SubscriptionBuilder(SqlObjectBuilder):

    mapped_class = Subscription
Ejemplo n.º 26
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder


class PoodleBuilder(ArchetypesBuilder):
    portal_type = 'Poodle'

builder_registry.register('poodle', PoodleBuilder)
Ejemplo n.º 27
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from plone.app.textfield.value import RichTextValue
from plone.namedfile import NamedImage
from z3c.relationfield.relation import create_relation
from ftw.simplelayout.tests import builders


class ContactFolderBuilder(DexterityBuilder):
    portal_type = "ftw.contacts.ContactFolder"


builder_registry.register("contact folder", ContactFolderBuilder)


class ContactBuilder(DexterityBuilder):
    portal_type = "ftw.contacts.Contact"

    def with_image(self):
        self.arguments["image"] = NamedImage("GIF89a;", filename=u"image.gif")
        return self

    def with_minimal_info(self, firstname, lastname):
        """Contact with ontly the required fields filled
        """
        self.arguments.update(lastname=lastname, firstname=firstname)

        return self

    def with_maximal_info(self, firstname, lastname):
        """Contact with all possible information
Ejemplo n.º 28
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder
from ftw.builder.dexterity import DexterityBuilder
import ftw.simplelayout.tests.builders


class ContentPageBuilder(ArchetypesBuilder):

    portal_type = "ContentPage"


builder_registry.register("content page", ContentPageBuilder)


class TextBlockBuilder(ArchetypesBuilder):
    portal_type = "TextBlock"


builder_registry.register("text block", TextBlockBuilder)


class ListingBlockBuilder(ArchetypesBuilder):
    portal_type = "ListingBlock"


builder_registry.register("listing block", ListingBlockBuilder)


class ExampleDxTypeBuilder(DexterityBuilder):
    portal_type = "ExampleDxType"
Ejemplo n.º 29
0
    def __init__(self, session):
        super(DossierBuilder, self).__init__(session)
        self.arguments['retention_period'] = 15

    def as_expired(self):
        """Resolves the dossier and set the end date so that the
        retention period is expired.
        """
        self.in_state('dossier-state-resolved')
        self.arguments['end'] = date.today() - relativedelta(
            years=self.arguments['retention_period'] + 1)

        return self


builder_registry.register('dossier', DossierBuilder)


class MeetingDossierBuilder(DossierBuilder):
    portal_type = 'opengever.meeting.meetingdossier'


builder_registry.register('meeting_dossier', MeetingDossierBuilder)


class TemplateFolderBuilder(TranslatedTitleBuilderMixin, DexterityBuilder):
    portal_type = 'opengever.dossier.templatefolder'


builder_registry.register('templatefolder', TemplateFolderBuilder)
Ejemplo n.º 30
0
    def _create_org_unit(self, user, admin_unit):
        if not self._with_org_unit:
            return None

        if admin_unit:
            self._org_unit_args['admin_unit'] = admin_unit
        builder = (Builder('org_unit').having(
            **self._org_unit_args).with_default_groups())
        if user:
            builder = (builder.as_current_org_unit().assign_users([user]))
        return create(builder)

    def _create_admin_unit(self):
        if not self._with_admin_unit:
            return None

        builder = Builder('admin_unit').having(
            **self._admin_unit_args).as_current_admin_unit()

        return create(builder)

    def _create_hugo_boss(self):
        if not self._with_hugo_boss:
            return None

        return create(Builder('ogds_user').having(**self._hugo_boss_args))


builder_registry.register('fixture', FixtureBuilder)
Ejemplo n.º 31
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from ftw.builder.archetypes import ArchetypesBuilder


class DXFolderBuilder(DexterityBuilder):
    portal_type = 'dxfolder'


class FormFolderBuilder(ArchetypesBuilder):
    portal_type = 'FormFolder'


builder_registry.register('FormFolder', FormFolderBuilder)
Ejemplo n.º 32
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from ftw.simplelayout.tests import builders


class HtmlBlockBuilder(DexterityBuilder):
    portal_type = 'ftw.htmlblock.HtmlBlock'

builder_registry.register('html block', HtmlBlockBuilder)
Ejemplo n.º 33
0
    def __init__(self, session):
        self.session = session
        self.properties = {}
        self.context = getSite()

    def titled(self, title):
        self.properties["name"] = title
        return self

    def having(self, **kwargs):
        self.properties.update(kwargs)
        return self

    def create(self):
        portlet = self.create_portlet()
        self.after_create(portlet)
        return portlet

    def create_portlet(self):
        portlet = navigation.Assignment(**self.properties)
        manager = getUtility(IPortletManager, name=u"plone.leftcolumn", context=self.context)
        assignments = getMultiAdapter((self.context, manager), IPortletAssignmentMapping, context=self.context)
        assignments["navigation"] = portlet

    def after_create(self, portlet):
        if self.session.auto_commit:
            transaction.commit()


builder_registry.register("navigation portlet", NavigationPortlet)
Ejemplo n.º 34
0
        self.session = session
        self.profile_builder = (
            Builder('genericsetup profile')
            .with_file(
                'workflows/{}/specification.txt'.format(
                    EXAMPLE_WORKFLOW_DIR.name),
                EXAMPLE_WF_SPEC.bytes(),
                makedirs=True)
            .with_file(
                'workflows/{}/definition.xml'.format(
                    EXAMPLE_WORKFLOW_DIR.name),
                EXAMPLE_WF_DEF.bytes(),
                makedirs=True))

        self.package_builder = (
            Builder('python package')
            .named('the.package')
            .with_profile(self.profile_builder)
            .with_directory('locales/de/LC_MESSAGES')
            .with_directory('upgrades'))

    def with_layer(self, layer):
        self.package_builder.at_path(layer['temp_directory'])
        return self

    def create(self, **kwargs):
        return self.package_builder.create(**kwargs)


builder_registry.register('package with workflow', PackageWithWorkflowBuilder)
Ejemplo n.º 35
0
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component.hooks import getSite
import transaction


class ShopItemBuilder(ArchetypesBuilder):

    portal_type = 'ShopItem'

    def before_create(self):
        super(ShopItemBuilder, self).before_create()
        if not IShopCategory.providedBy(self.container):
            self.container = create(Builder('shop category'))

builder_registry.register('shop item', ShopItemBuilder)


class ShopCategoryBuilder(ArchetypesBuilder):

    portal_type = 'ShopCategory'

builder_registry.register('shop category', ShopCategoryBuilder)


class ShopSupplierBuilder(ArchetypesBuilder):

    portal_type = 'Supplier'

builder_registry.register('supplier', ShopSupplierBuilder)
Ejemplo n.º 36
0
from opengever.document.checkout.manager import CHECKIN_CHECKOUT_ANNOTATIONS_KEY
from opengever.task.interfaces import ISuccessorTaskController
from opengever.trash.trash import ITrashable
from plone.namedfile.file import NamedBlobFile
from Products.CMFCore.utils import getToolByName
from z3c.relationfield.relation import RelationValue
from zope.annotation.interfaces import IAnnotations
from zope.component import getUtility
from zope.intid.interfaces import IIntIds


class DossierBuilder(DexterityBuilder):
    portal_type = 'opengever.dossier.businesscasedossier'


builder_registry.register('dossier', DossierBuilder)


class TemplateDossierBuilder(DexterityBuilder):
    portal_type = 'opengever.dossier.templatedossier'


builder_registry.register('templatedossier', TemplateDossierBuilder)


class InboxBuilder(DexterityBuilder):
    portal_type = 'opengever.inbox.inbox'


builder_registry.register('inbox', InboxBuilder)
Ejemplo n.º 37
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder


class TaskBuilder(ArchetypesBuilder):
    portal_type = 'Task'


builder_registry.register('task', TaskBuilder)
Ejemplo n.º 38
0
from ftw.builder.dexterity import DexterityBuilder
from ftw.builder import builder_registry
from ftw.simplelayout.tests import builders


class SubsiteBuilder(DexterityBuilder):

    portal_type = 'ftw.subsite.Subsite'

    def with_language(self, language_code):
        if 'title' not in self.arguments:
            return self.having(force_language=language_code,
                               title=language_code)
        else:
            return self.having(force_language=language_code)


builder_registry.register('subsite', SubsiteBuilder)
Ejemplo n.º 39
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from plone.namedfile.file import NamedBlobImage
from StringIO import StringIO


class SliderContainerBuilder(DexterityBuilder):
    portal_type = 'ftw.slider.Container'

builder_registry.register('slider container', SliderContainerBuilder)


class SliderPaneBuilder(DexterityBuilder):
    portal_type = 'ftw.slider.Pane'

    def with_dummy_image(self):
        dummy_image = StringIO(
            'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00'
            '\x00!\xf9\x04\x04\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00'
            '\x01\x00\x00\x02\x02D\x01\x00;')

        self.arguments["image"] = NamedBlobImage(dummy_image.read(),
                                                 filename=u"image.gif")
        return self

builder_registry.register('slider pane', SliderPaneBuilder)
Ejemplo n.º 40
0
    def __init__(self, session):
        super(DossierBuilder, self).__init__(session)
        self.arguments['retention_period'] = 15

    def as_expired(self):
        """Resolves the dossier and set the end date so that the
        retention period is expired.
        """
        self.in_state('dossier-state-resolved')
        self.arguments['end'] = date.today() - relativedelta(
            years=self.arguments['retention_period'] + 1)

        return self


builder_registry.register('dossier', DossierBuilder)


class MeetingDossierBuilder(DossierBuilder):
    portal_type = 'opengever.meeting.meetingdossier'


builder_registry.register('meeting_dossier', MeetingDossierBuilder)


class TemplateFolderBuilder(TranslatedTitleBuilderMixin, DexterityBuilder):
    portal_type = 'opengever.dossier.templatefolder'


builder_registry.register('templatefolder', TemplateFolderBuilder)
Ejemplo n.º 41
0
    def __init__(self, session):
        super(ContenPageBuilder, self).__init__(session)
        self.block_builders = []

    def with_blocks(self, *block_builders):
        self.block_builders.extend(block_builders)
        return self

    def after_create(self, obj):
        if self.block_builders:
            map(create, map(methodcaller('within', obj), self.block_builders))
            synchronize_page_config_with_blocks(obj)
        return super(ContenPageBuilder, self).after_create(obj)

builder_registry.register('sl content page', ContenPageBuilder)


class TextBlockBuilder(DexterityBuilder):
    portal_type = 'ftw.simplelayout.TextBlock'

    def with_dummy_image(self):
        image = Path(__file__).joinpath('..', 'assets', 'fullhd.jpg').abspath()
        self.arguments['image'] = NamedBlobImage(data=image.bytes(),
                                                 filename=u'test.gif')
        return self

    def with_cropped_image(self):
        image = Path(__file__).joinpath('..', 'assets', 'cropped.jpg').abspath()
        self.arguments['cropped_image'] = NamedBlobImage(data=image.bytes(),
                                                         filename=u'cropped.gif')
Ejemplo n.º 42
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder
from plone.uuid.interfaces import IUUID


class ShopItemBlockBuilder(ArchetypesBuilder):
    portal_type = 'ShopItemBlock'

    def with_shop_item(self, shopitem):
        assert shopitem

        self.arguments['item'] = IUUID(shopitem)
        return self


class ShopItemBuilder(ArchetypesBuilder):
    portal_type = 'ShopItem'


class ShopCategoryBuilder(ArchetypesBuilder):
    portal_type = 'ShopCategory'


builder_registry.register('shopitem block', ShopItemBlockBuilder)
builder_registry.register('shopitem', ShopItemBuilder)
builder_registry.register('shop category', ShopCategoryBuilder)
Ejemplo n.º 43
0
        return self

    def as_current_admin_unit(self):
        self._as_current_admin_unit = True
        return self

    def assign_org_units(self, units):
        self.arguments['org_units'] = units
        return self

    def after_create(self, obj):
        if self.org_unit:
            self.org_unit.assign_to_admin_unit(obj)
        return obj

builder_registry.register('admin_unit', AdminUnitBuilder)


class OrgUnitBuilder(SqlObjectBuilder):

    mapped_class = OrgUnit
    id_argument_name = 'unit_id'

    def __init__(self, session):
        super(OrgUnitBuilder, self).__init__(session)
        self.arguments[self.id_argument_name] = u'rr'
        self.arguments['users_group_id'] = 'foo'
        self.arguments['inbox_group_id'] = 'bar'
        self._with_inbox_group = False
        self._with_users_group = False
        self._inbox_users = set()
Ejemplo n.º 44
0
    def titled(self, title):
        self.properties['name'] = title
        return self

    def having(self, **kwargs):
        self.properties.update(kwargs)
        return self

    def create(self):
        portlet = self.create_portlet()
        self.after_create(portlet)
        return portlet

    def create_portlet(self):
        portlet = navigation.Assignment(**self.properties)
        manager = getUtility(IPortletManager,
                             name=u'plone.leftcolumn',
                             context=self.context)
        assignments = getMultiAdapter((self.context, manager),
                                      IPortletAssignmentMapping,
                                      context=self.context)
        assignments['navigation'] = portlet

    def after_create(self, portlet):
        if self.session.auto_commit:
            transaction.commit()


builder_registry.register('navigation portlet', NavigationPortlet)
Ejemplo n.º 45
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder
from plone.namedfile import NamedBlobFile


class MailBuilder(DexterityBuilder):
    portal_type = 'ftw.mail.mail'

    def with_message(self, data, contentType=u'message/rfc822', filename=u'message.eml'):
        if isinstance(data, file):
            data = data.read()
        self.arguments["message"] = NamedBlobFile(
            data=data, contentType=contentType, filename=filename)
        return self


builder_registry.register('mail', MailBuilder)
Ejemplo n.º 46
0
    def _create_upgrade(self):
        name = self.name.replace(' ', '_').replace('\.$', '')
        step_name = '{0}_{1}'.format(self.destination_version,
                                     inflection.underscore(name))
        if self.code is None:
            self.code = scaffold.PYTHON_TEMPLATE.format(
                classname=inflection.camelize(name),
                docstring=inflection.humanize(
                    inflection.underscore(name)))

        self.package.with_file(
            os.path.join(step_name, '__init__.py'),
            '',
            makedirs=True)

        self.package.with_file(
            os.path.join(step_name, 'upgrade.py'),
            self.code)
        return step_name

    def _register_files_and_dirs_in_package_builder(self, step_name):
        for relative_path in self.directories:
            self.package.with_directory(os.path.join(step_name, relative_path))

        for path, contents in self.files:
            self.package.with_file(os.path.join(step_name, path), contents)


builder_registry.register('ftw upgrade step', UpgradeStepBuilder)
Ejemplo n.º 47
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder


class EventBuilder(ArchetypesBuilder):

    portal_type = 'Event'


builder_registry.register('event', EventBuilder)
from ftw.builder.dexterity import DexterityBuilder
from ftw.builder import builder_registry


class DXFolderBuilder(DexterityBuilder):
    portal_type = 'dxfolder'

builder_registry.register('dxfolder', DXFolderBuilder)
Ejemplo n.º 49
0
from ftw.builder import builder_registry
from ftw.builder.content import ATFileBuilder
from path import Path


class CustomFileBuilder(ATFileBuilder):

    def attach_asset(self, filename):
        return self.attach_file_containing(
            self._asset(filename).bytes(), filename)

    def _asset(self, filename):
        path = Path(__file__).dirname().realpath().joinpath('assets', filename)
        return path


builder_registry.register('file', CustomFileBuilder, force=True)
Ejemplo n.º 50
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder


class AddressBlockBuilder(DexterityBuilder):
    portal_type = 'ftw.addressblock.AddressBlock'

builder_registry.register('sl addressblock', AddressBlockBuilder)
Ejemplo n.º 51
0
from ftw.builder import builder_registry
from ftw.builder.dexterity import DexterityBuilder


class DXContainerBuilder(DexterityBuilder):
    portal_type = 'DXContainer'


builder_registry.register('dx container', DXContainerBuilder)
Ejemplo n.º 52
0
        self._as_current_admin_unit = False

    def as_current_admin_unit(self):
        self._as_current_admin_unit = True
        return self

    def after_create(self, obj):
        obj = super(PloneAdminUnitBuilder, self).after_create(obj)

        if self._as_current_admin_unit:
            registry = getUtility(IRegistry)
            proxy = registry.forInterface(IAdminUnitConfiguration)
            proxy.current_unit_id = self.arguments.get(self.id_argument_name)
        return obj

builder_registry.register('admin_unit', PloneAdminUnitBuilder, force=True)


class PloneOrgUnitBuilder(OrgUnitBuilder):
    """Add plone specific functionality to opengever.ogds.models
    OrgUnitBuilder.

    """
    def __init__(self, session):
        super(PloneOrgUnitBuilder, self).__init__(session)
        self._as_current_org_unit = False

    def after_create(self, obj):
        if self._as_current_org_unit:
            get_ou_selector().set_current_unit(obj.id())
        return obj
Ejemplo n.º 53
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder


class MeetingBuilder(ArchetypesBuilder):

    portal_type = 'Meeting'

builder_registry.register('meeting', MeetingBuilder)


class MeetingItemBuilder(ArchetypesBuilder):

    portal_type = 'Meeting Item'

builder_registry.register('meeting item', MeetingItemBuilder)


class TaskBuilder(ArchetypesBuilder):

    portal_type = 'Task'

builder_registry.register('task', TaskBuilder)
Ejemplo n.º 54
0
    def with_layout(self, layout_iface):
        dotted_name = '.'.join((layout_iface.__module__,
                                layout_iface.__name__))
        self.having(latex_layout=dotted_name)
        self.apply_layer = layout_iface
        return self

    def after_create(self, obj):
        provide_request_layer(obj.REQUEST, IWithinBookLayer)
        if self.apply_layer:
            provide_request_layer(obj.REQUEST, self.apply_layer)
        super(BookBuilder, self).after_create(obj)


builder_registry.register('book', BookBuilder)


class ChapterBuilder(ArchetypesBuilder):

    portal_type = 'Chapter'

builder_registry.register('chapter', ChapterBuilder)


class TextBlockBuilder(ArchetypesBuilder):

    portal_type = 'BookTextBlock'

builder_registry.register('book textblock', TextBlockBuilder)
Ejemplo n.º 55
0
                return fp, pathname, description
            else:
                return find_module(dottedname, [pathname])

        try:
            fp, pathname, description = find_module(name)
        except ImportError:
            return True

        else:
            raise ValueError(
                'Invalid package name "{0}": there is already'
                ' a package or module with the same name.'.format(name))


builder_registry.register('python package', PythonPackageBuilder)


class NamespacePackageBuilder(object):
    """The namespace package builder builds a single namespace level.
    """

    def __init__(self, session):
        self.session = session
        self.path = None

    def at_path(self, path):
        self.path = Path(path)
        return self

    def create(self):
Ejemplo n.º 56
0
from ftw.builder import builder_registry
from ftw.builder.archetypes import ArchetypesBuilder


class FormGenBuilder(ArchetypesBuilder):
    portal_type = 'FormFolder'


builder_registry.register('form folder', FormGenBuilder)


class SaveDataBuilder(ArchetypesBuilder):
    portal_type = 'FormSaveDataAdapter'


builder_registry.register('save data adapter', SaveDataBuilder)