Example #1
0
 def testRelatedItems(self):
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.doc1, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual([x.Title for x in related], [
                      'Document 2', 'Document 3'])
    def get_related_items(self):
        """
        Como ainda customizamos a visão de nitf, na versão 1.x de
        collective.nitf, tínhamos o atributo relatedItems no tipo nitf. Na
        template customizada, renderizávamos o widget presente em
        collective.z3cform.widgets, pro campo relatedItems (esses são os objetos
        que eram disponibilizados em nitf_custom_view na div newsRelatedItems).

        <NITF at conheca-o-novo-modelo-da-identidade-digital-padrao-do-governo-federal>
        [<z3c.relationfield.relation.RelationValue object at 0x7f15d8575cf8>]
        <brasil.gov.portal.browser.content.nitf_custom_view.View object at 0x7f15d6c72f90>
        {'byline': <TextWidget 'form.widgets.byline'>,
        'subtitle': <TextWidget 'form.widgets.subtitle'>,
        'text': <RichTextWidget 'form.widgets.text'>,
        'section': <SelectWidget 'form.widgets.section'>,
        'relatedItems': <MultiContentSearchWidget 'form.widgets.relatedItems'>,
        'location': <TextWidget 'form.widgets.location'>,
        'genre': <SelectWidget 'form.widgets.genre'>,
        'urgency': <SelectWidget 'form.widgets.urgency'>}

        Acontece que após os commits:

        https://github.com/collective/collective.nitf/commit/a4704e26210cbdf5aadd473503d14947034a613a

        https://github.com/collective/collective.nitf/commit/5a27baa54f728f1de123c6883e02020b481d7d00

        Esse campo foi completamente removido e portanto ao atualizar para 2.x
        dá erro na renderização da template que ainda espera esses atributos.

        Dessa forma, usaremos o método padrão da viewlet do Plone de retornar
        itens relacionados, e montaremos na template com o mesmo html que o
        widgets da versão 1.x montaria mantendo assim o layotu padrão.
        """
        viewlet = ContentRelatedItems(self.context, self.request, None, None)
        return viewlet.related_items()
Example #3
0
 def testRelatedItems(self):
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.doc1, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual([x.Title for x in related],
                      ['Document 2', 'Document 3'])
Example #4
0
 def testDexterityDeletedRelatedItems(self):
     # Deleted related items should not cause problems.
     self.folder._delObject('doc1')
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.dex1, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual([x.id for x in related], ['doc2'])
Example #5
0
 def testDexterityDeletedRelatedItems(self):
     # Deleted related items should not cause problems.
     self.folder._delObject('doc1')
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.dex1, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual([x.id for x in related], ['doc2'])
Example #6
0
    def testDexterityFolderRelatedItems(self):
        """
        Related items viewlet doesn't include related folder's descendants.
        """
        self.assertTrue(
            self.folder.contentValues(), 'Folder is missing descendants')

        intids = getUtility(IIntIds)
        self.folder.dex1.relatedItems = [
            RelationValue(intids.getId(self.folder))]

        request = self.app.REQUEST
        viewlet = ContentRelatedItems(self.folder.dex1, request, None, None)
        viewlet.update()
        related = viewlet.related_items()
        self.assertEqual(len(related), 1)
Example #7
0
    def testDexterityFolderRelatedItems(self):
        """
        Related items viewlet doesn't include related folder's descendants.
        """
        self.assertTrue(
            self.folder.contentValues(), 'Folder is missing descendants')

        intids = getUtility(IIntIds)
        self.folder.dex1.relatedItems = [
            RelationValue(intids.getId(self.folder))]

        request = self.app.REQUEST
        viewlet = ContentRelatedItems(self.folder.dex1, request, None, None)
        viewlet.update()
        related = viewlet.related_items()
        self.assertEqual(len(related), 1)
Example #8
0
 def testDexterityWithoutRelatedItemsBehavior(self):
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.dex2, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual(len(related), 0)
Example #9
0
 def testDexterityRelatedItems(self):
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.dex1, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual([x.id for x in related], ['doc1', 'doc2'])
Example #10
0
 def testDexterityWithoutRelatedItemsBehavior(self):
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.dex2, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual(len(related), 0)
Example #11
0
 def testDexterityRelatedItems(self):
     request = self.app.REQUEST
     viewlet = ContentRelatedItems(self.folder.dex1, request, None, None)
     viewlet.update()
     related = viewlet.related_items()
     self.assertEqual([x.id for x in related], ['doc1', 'doc2'])