Пример #1
0
    def _construct_object(self, container, item):
        portal_type = item['_type']
        fti = self._get_fti(portal_type)
        title_args = self._get_title_args(fti, item)

        with NoDossierReferenceNumbersIssued():
            # Create the object without automatically issuing a
            # reference number - we might want to set it explicitly
            obj = createContentInContainer(container, portal_type,
                                           **title_args)

            if IDossierMarker.providedBy(obj):
                prefix_adapter = IReferenceNumberPrefix(container)
                if not prefix_adapter.get_number(obj):
                    # Set the local reference number part for the
                    # dossier if provided in item, otherwise have
                    # the adapter issue the next one
                    local_refnum = item.get('reference_number')
                    if local_refnum is not None:
                        prefix_adapter.set_number(obj, local_refnum)
                    else:
                        prefix_adapter.set_number(obj)

        self._set_guid(obj, item)
        return obj
Пример #2
0
    def _construct_object(self, container, item):
        portal_type = item['_type']
        fti = self._get_fti(portal_type)
        title_args = self._get_title_args(fti, item)

        with NoDossierReferenceNumbersIssued():
            # Create the object without automatically issuing a
            # reference number - we might want to set it explicitly
            obj = createContentInContainer(
                container, portal_type, **title_args)

            if IDossierMarker.providedBy(obj):
                prefix_adapter = IReferenceNumberPrefix(container)
                if not prefix_adapter.get_number(obj):
                    # Set the local reference number part for the
                    # dossier if provided in item, otherwise have
                    # the adapter issue the next one
                    local_refnum = item.get('reference_number')
                    if local_refnum is not None:
                        prefix_adapter.set_number(obj, local_refnum)
                    else:
                        prefix_adapter.set_number(obj)

        self._set_guid(obj, item)
        return obj
Пример #3
0
def save_reference_number_prefix(obj, event):
    if IDontIssueDossierReferenceNumber.providedBy(obj.REQUEST):
        return

    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool('portal_catalog')
    tasks = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.task.task.ITask',
        'depth': -1
    })
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    # And also proposals
    proposals = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.meeting.proposal.IProposal',
        'depth': -1
    })
    for proposal in proposals:
        ProposalSqlSyncer(proposal.getObject(), None).sync()

    obj.reindexObject(idxs=['reference'])
Пример #4
0
def save_reference_number_prefix(obj, event):
    if IDontIssueDossierReferenceNumber.providedBy(obj.REQUEST):
        return

    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool('portal_catalog')
    tasks = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.task.task.ITask',
        'depth': -1})
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    # And also proposals
    proposals = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.meeting.proposal.IProposal',
        'depth': -1})
    for proposal in proposals:
        ProposalSqlSyncer(proposal.getObject(), None).sync()

    obj.reindexObject(idxs=['reference'])
Пример #5
0
def regenerate_and_reindex_reference_number(obj):
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)

    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=['reference'])

    for child in obj.objectValues():
        if IDexterityContent.providedBy(child):
            regenerate_and_reindex_reference_number(child)
Пример #6
0
def regenerate_and_reindex_reference_number(obj):
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)

    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=['reference'])

    for child in obj.objectValues():
        if IDexterityContent.providedBy(child):
            regenerate_and_reindex_reference_number(child)
    def _put_in_parent_mappings(self, repo_folder):
        changed = False
        parent = aq_parent(aq_inner(repo_folder))
        child = repo_folder
        child_number = IReferenceNumber(child).get_local_number()
        child_intid = self.intids.getId(child)
        ref = IReferenceNumberPrefix(parent)

        is_in_intid_mapping = child_intid in ref.get_prefix_mapping(child)
        if not is_in_intid_mapping:
            ref.set_number(child, number=child_number)
            changed = True

        return changed
Пример #8
0
def save_reference_number_prefix(obj, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool("portal_catalog")
    tasks = catalog(
        {"path": "/".join(obj.getPhysicalPath()), "object_provides": "opengever.task.task.ITask", "depth": -1}
    )
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    obj.reindexObject(idxs=["reference"])
Пример #9
0
def set_former_reference_after_moving(obj, event):
    """ Use the (hopefully) stored former reference number
    as the real new former reference number. This has to
    be done after the dossier was moved.

    """
    # make sure obj wasn't just created or deleted
    if not event.oldParent or not event.newParent:
        return

    repr = IDossier(obj)
    former_ref_no = repr.temporary_former_reference_number
    IDossier['former_reference_number'].set(repr, former_ref_no)
    # reset temporary former reference number
    IDossier['temporary_former_reference_number'].set(repr, '')

    # setting the new number
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=['reference'])
Пример #10
0
def set_former_reference_after_moving(obj, event):
    """ Use the (hopefully) stored former reference number
    as the real new former reference number. This has to
    be done after the dossier was moved.

    """
    # make sure obj wasn't just created or deleted
    if not event.oldParent or not event.newParent:
        return

    repr = IDossier(obj)
    former_ref_no = repr.temporary_former_reference_number
    IDossier["former_reference_number"].set(repr, former_ref_no)
    # reset temporary former reference number
    IDossier["temporary_former_reference_number"].set(repr, "")

    # setting the new number
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=["reference"])
class TestReferencePrefixAdapter(IntegrationTestCase):

    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()
        self.login(self.regular_user)
        self.adapter = IReferenceNumberPrefix(self.leaf_repofolder)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.empty_repofolder))
        adapter = IReferenceNumberPrefix(self.empty_repofolder)

        self.assertEquals(u'1', adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.adapter.set_number(self.leaf_repofolder, 9)
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        self.assertEquals(u'42',
                          self.adapter.set_number(self.leaf_repofolder, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_set_number_recycles_old_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'42')

        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.set_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_assigned_numbers_are_invalid(self):
        self.adapter.set_number(self.leaf_repofolder, u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))
        self.assertFalse(self.adapter.is_valid_number(u'3'))

    def test_with_object_the_assigned_number_is_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertTrue(self.adapter.is_valid_number(u'A9', self.leaf_repofolder))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertFalse(self.adapter.is_valid_number(u'A9', self.empty_repofolder))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.adapter.set_number(self.leaf_repofolder, u'234')

        repository = create(Builder('repository').within(self.leaf_repofolder))
        dossier = create(Builder('dossier').within(self.leaf_repofolder))

        self.assertEquals(u'235', self.adapter.get_next_number(repository))
        self.assertEquals(u'14', self.adapter.get_next_number(dossier))
class TestReferencePrefixAdapter(FunctionalTestCase):

    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()

        self.repository = create(Builder('repository').titled(u'Position'))
        self.adapter = IReferenceNumberPrefix(self.repository)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.repository))
        self.assertEquals(
            u'1',
            self.adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.set_numbering_base(u'9')
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.set_numbering_base(u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        item = self.create_item()
        self.assertEquals(u'42', self.adapter.set_number(item, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(item))

    def test_set_number_recycles_old_numbers(self):
        item = self.create_item()
        self.assertEquals(u'1', self.adapter.get_number(item))
        self.assertEquals(u'1', self.adapter.set_number(item))
        self.assertEquals(u'1', self.adapter.get_number(item))

    def test_non_assigned_numbers_are_valid(self):
        self.create_numbered_item(u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))

    def test_assigned_numbers_are_invalid(self):
        self.create_numbered_item(u'2')

        self.assertFalse(self.adapter.is_valid_number(u'2'))

    def test_with_object_the_assigned_number_is_valid(self):
        item = self.create_numbered_item(u'A9')

        self.assertTrue(self.adapter.is_valid_number(u'A9', item))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        item = self.create_numbered_item(u'A9')
        self.create_numbered_item(u'A10')

        self.assertFalse(self.adapter.is_valid_number(u'A10', item))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.create_numbered_item(5)

        dossier = create(Builder('dossier').within(self.repository))
        repository = create(Builder('repository').within(self.repository))

        self.assertEquals(u'1', self.adapter.get_number(dossier))
        self.assertEquals(u'6', self.adapter.get_number(repository))

    def set_numbering_base(self, base):
        self.create_numbered_item(base)

    def create_numbered_item(self, number):
        item = self.create_item()
        self.adapter.set_number(item, number)
        return item

    def create_item(self):
        return create(Builder('repository').within(self.repository))
Пример #13
0
class TestReferencePrefixAdapter(FunctionalTestCase):
    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()

        self.repository = create(Builder('repository').titled(u'Position'))
        self.adapter = IReferenceNumberPrefix(self.repository)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.repository))
        self.assertEquals(u'1', self.adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.set_numbering_base(u'9')
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.set_numbering_base(u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        item = self.create_item()
        self.assertEquals(u'42', self.adapter.set_number(item, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(item))

    def test_set_number_recycles_old_numbers(self):
        item = self.create_item()
        self.assertEquals(u'1', self.adapter.get_number(item))
        self.assertEquals(u'1', self.adapter.set_number(item))
        self.assertEquals(u'1', self.adapter.get_number(item))

    def test_non_assigned_numbers_are_valid(self):
        self.create_numbered_item(u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))

    def test_assigned_numbers_are_invalid(self):
        self.create_numbered_item(u'2')

        self.assertFalse(self.adapter.is_valid_number(u'2'))

    def test_with_object_the_assigned_number_is_valid(self):
        item = self.create_numbered_item(u'A9')

        self.assertTrue(self.adapter.is_valid_number(u'A9', item))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        item = self.create_numbered_item(u'A9')
        self.create_numbered_item(u'A10')

        self.assertFalse(self.adapter.is_valid_number(u'A10', item))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.create_numbered_item(5)

        dossier = create(Builder('dossier').within(self.repository))
        repository = create(Builder('repository').within(self.repository))

        self.assertEquals(u'1', self.adapter.get_number(dossier))
        self.assertEquals(u'6', self.adapter.get_number(repository))

    def set_numbering_base(self, base):
        self.create_numbered_item(base)

    def create_numbered_item(self, number):
        item = self.create_item()
        self.adapter.set_number(item, number)
        return item

    def create_item(self):
        return create(Builder('repository').within(self.repository))
Пример #14
0
def saveReferenceNumberPrefix(obj, event):
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)
    obj.reindexObject(idxs=['reference'])
class TestReferencePrefixAdapter(IntegrationTestCase):

    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()
        self.login(self.regular_user)
        self.adapter = IReferenceNumberPrefix(self.leaf_repofolder)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.empty_repofolder))
        adapter = IReferenceNumberPrefix(self.empty_repofolder)

        self.assertEquals(u'1', adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.adapter.set_number(self.leaf_repofolder, 9)
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        self.assertEquals(u'42',
                          self.adapter.set_number(self.leaf_repofolder, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_set_number_recycles_old_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'42')

        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.set_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_assigned_numbers_are_invalid(self):
        self.adapter.set_number(self.leaf_repofolder, u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))
        self.assertFalse(self.adapter.is_valid_number(u'3'))

    def test_with_object_the_assigned_number_is_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertTrue(self.adapter.is_valid_number(u'A9', self.leaf_repofolder))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertFalse(self.adapter.is_valid_number(u'A9', self.empty_repofolder))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.adapter.set_number(self.leaf_repofolder, u'234')

        repository = create(Builder('repository').within(self.leaf_repofolder))
        dossier = create(Builder('dossier').within(self.leaf_repofolder))

        self.assertEquals(u'235', self.adapter.get_next_number(repository))
        self.assertEquals(u'15', self.adapter.get_next_number(dossier))