Exemplo n.º 1
0
    def testCopyBlobs(self):
        from zope.copy import copy
        file = NamedBlobFile()
        file.data = u'hello, world'
        image = NamedBlobImage()
        image.data = 'some image bytes'
        transaction.commit()

        file_copy = copy(file)
        self.assertEqual(file_copy.data, file.data)

        image_copy = copy(image)
        self.assertEqual(image_copy.data, image.data)
Exemplo n.º 2
0
    def testCopyBlobs(self):
        from zope.copy import copy
        file = NamedBlobFile()
        file.data = u'hello, world'
        image = NamedBlobImage()
        image.data = 'some image bytes'
        transaction.commit()

        file_copy = copy(file)
        self.assertEqual(file_copy.data, file.data)

        image_copy = copy(image)
        self.assertEqual(image_copy.data, image.data)
Exemplo n.º 3
0
    def getDefaultForFieldType(self, field):

        # default string
        default_value = self.placeholder

        # Field Class
        field_klass = field.__class__.__name__

        # Handle different value_type attributes of the field.
        value_type = getattr(field, 'value_type', None)

        if value_type:
            # If we're a data grid field
            if isinstance(value_type, DictRow):
                kwargs = {}

                s = getattr(value_type, 'schema', None)

                if s:
                    for (_name,
                         _field) in getAllSchemaFieldsAndDescriptions(s):
                        if not isinstance(field, Method):
                            kwargs[_name] = self.getDefaultForFieldType(_field)

                return [
                    kwargs,
                ]
            elif isinstance(value_type, (schema.TextLine, )):
                pass
            elif isinstance(value_type, (schema.Choice, )):
                vocabulary_name = getattr(value_type, 'vocabularyName', None)
                vocabulary = getattr(value_type, 'vocabulary', None)

                if vocabulary_name:
                    vocabulary_factory = getUtility(IVocabularyFactory,
                                                    vocabulary_name)
                    vocabulary = vocabulary_factory(self.context)

                if vocabulary:
                    if isinstance(vocabulary, SimpleVocabulary):
                        try:
                            default_value = vocabulary.by_value.keys()[0]
                        except:
                            pass
                    else:
                        pass

        # Return nothing for methods
        if field_klass in [
                'Method',
        ]:
            return None

        # Define dummy fields

        rich_text = RichTextValue(raw='<p>%s</p>' % self.placeholder,
                                  mimeType=u'text/html',
                                  outputMimeType='text/x-html-safe')

        named_blob_file = NamedBlobFile(filename=u'sample.pdf',
                                        contentType='application/pdf')

        named_blob_file.data = self.placeholder.encode('utf-8')

        named_blob_image = NamedBlobImage(filename=u'sample.png',
                                          contentType='image/png')

        named_blob_image.data = self.placeholder.encode('utf-8')

        # Simple field defaults

        defaults = {
            'Int': 10,
            'Text': "\n".join(3 * [self.placeholder]),
            'List': [
                default_value,
            ],
            'Tuple': (default_value, ),
            'TextLine': default_value,
            'Bool': True,
            'Datetime': datetime.now(),
            'RichText': rich_text,
            'NamedBlobFile': named_blob_file,
            'NamedBlobImage': named_blob_image,
            'Choice': default_value,
        }

        # If a default, return that.  Otherwise, return the placeholder.
        return defaults.get(field_klass, self.placeholder)