예제 #1
0
    def get_content_diff(self):
        """ Create a content diff for the last item change

        :return: list of diff lines
        """
        if self.action in [
                DESTROY_REV,
                DESTROY_ALL,
        ]:
            contenttype = self.meta[CONTENTTYPE]
            oldfile, newfile = self.content, BytesIO("")
        elif self.action == ACTION_TRASH:
            contenttype = self.meta[CONTENTTYPE]
            oldfile, newfile = self.revs[0].data, BytesIO("")
        else:
            # if user does not have permission to read object,
            # get_item_last_revisions() returns an empty list to self.revs
            if len(self.revs) > 0:
                newfile = self.revs[0].data
                if len(self.revs) == 1:
                    contenttype = self.revs[0].meta[CONTENTTYPE]
                    oldfile = BytesIO("")
                else:
                    from MoinMoin.apps.frontend.views import _common_type
                    contenttype = _common_type(self.revs[0].meta[CONTENTTYPE],
                                               self.revs[1].meta[CONTENTTYPE])
                    oldfile = self.revs[1].data
            else:
                abort(403)
        content = Content.create(contenttype)
        return content._get_data_diff_text(oldfile, newfile)
예제 #2
0
    def get_content_diff(self):
        """ Create a content diff for the last item change

        :return: list of diff lines
        """
        if self.action in [DESTROY_REV, DESTROY_ALL, ]:
            contenttype = self.meta[CONTENTTYPE]
            oldfile, newfile = self.content, BytesIO("")
        elif self.action == ACTION_TRASH:
            contenttype = self.meta[CONTENTTYPE]
            oldfile, newfile = self.revs[0].data, BytesIO("")
        else:
            # if user does not have permission to read object,
            # get_item_last_revisions() returns an empty list to self.revs
            if len(self.revs) > 0:
                newfile = self.revs[0].data
                if len(self.revs) == 1:
                    contenttype = self.revs[0].meta[CONTENTTYPE]
                    oldfile = BytesIO("")
                else:
                    from MoinMoin.apps.frontend.views import _common_type
                    contenttype = _common_type(self.revs[0].meta[CONTENTTYPE], self.revs[1].meta[CONTENTTYPE])
                    oldfile = self.revs[1].data
            else:
                abort(403)
        content = Content.create(contenttype)
        return content._get_data_diff_text(oldfile, newfile)
예제 #3
0
 def testClassFinder(self):
     for contenttype, ExpectedClass in [
             (u'application/x-foobar', Binary),
             (u'text/plain', Text),
             (u'text/plain;charset=utf-8', Text),
             (u'image/tiff', Image),
             (u'image/png', TransformableBitmapImage),
     ]:
         content = Content.create(contenttype)
         assert isinstance(content, ExpectedClass)
예제 #4
0
 def testClassFinder(self):
     for contenttype, ExpectedClass in [
             (u'application/x-foobar', Binary),
             (u'text/plain', Text),
             (u'text/plain;charset=utf-8', Text),
             (u'image/tiff', Image),
             (u'image/png', TransformableBitmapImage),
     ]:
         content = Content.create(contenttype)
         assert isinstance(content, ExpectedClass)
예제 #5
0
    def get_content_diff(self):
        """ Create a content diff for the last item change

        :return: list of diff lines
        """
        if self.action in [DESTROY_REV, DESTROY_ALL, ]:
            contenttype = self.meta[CONTENTTYPE]
            oldfile, newfile = self.content, BytesIO("")
        elif self.action == ACTION_TRASH:
            contenttype = self.meta[CONTENTTYPE]
            oldfile, newfile = self.revs[0].data, BytesIO("")
        else:
            newfile = self.revs[0].data
            if len(self.revs) == 1:
                contenttype = self.revs[0].meta[CONTENTTYPE]
                oldfile = BytesIO("")
            else:
                from MoinMoin.apps.frontend.views import _common_type
                contenttype = _common_type(self.revs[0].meta[CONTENTTYPE], self.revs[1].meta[CONTENTTYPE])
                oldfile = self.revs[1].data
        content = Content.create(contenttype)
        return content._get_data_diff_text(oldfile, newfile)