コード例 #1
0
    def test_implementsInterfaces(self):
        """Test if an ATEvent object implements all relevant interfaces.

        """
        self.assertTrue(IEvent.providedBy(self.obj))
        self.assertTrue(IEventRecurrence.providedBy(self.obj))
        self.assertTrue(IATEvent.providedBy(self.obj))
        self.assertTrue(IATEventRecurrence.providedBy(self.obj))

        self.assertTrue(IATEvent_ATCT.providedBy(self.obj))
        self.assertTrue(verifyObject(IATEvent_ATCT, self.obj))
コード例 #2
0
    def populate_archetype(self, obj):
        request = self.request
        fields = obj.Schema().fields()

        for field in fields:
            name = field.__name__
            if name in ['title', 'id']:
                continue

            if shasattr(field, 'vocabulary') and IVocabulary.providedBy(
                    field.vocabulary):
                vocab = field.vocabulary.getVocabularyDict(obj)
                value = vocab.keys()[random.randint(0, len(vocab.keys()) - 1)]

            elif atfield.IStringField.providedBy(field):
                validators = [v[0].name for v in field.validators]
                if 'isURL' in validators:
                    value = 'http://en.wikipedia.com/wiki/Lorem_ipsum'
                elif 'isEmail' in validators:
                    value = '*****@*****.**'
                else:
                    value = self.get_text_line()

            elif atfield.ITextField.providedBy(field):
                widget = field.widget
                if isinstance(widget, RichWidget):
                    value = self.get_rich_text()
                else:
                    value = self.get_text_paragraph()

            elif atfield.IBooleanField.providedBy(field):
                value = random.randint(0, 1) and True or False
            else:
                continue

            field.set(obj, value)

        if IATEvent.providedBy(obj):
            days = random.random() * 20 * (random.randint(-1, 1) or 1)
            value = DateTime() + days
            obj.setStartDate(value)
            obj.setEndDate(value + random.random() * 3)
コード例 #3
0
    def __cmp__(self, other):
        """Compare method

        If other is based on ATEvent, compare start, duration and title.
        #If other is a number, compare duration and number
        If other is a DateTime instance, compare start date with date
        In all other cases there is no specific order
        """
        # Please note that we can not use self.Title() here: the generated
        # edit accessor uses getToolByName, which ends up in
        # five.localsitemanager looking for a parent using a comparison
        # on this object -> infinite recursion.
        if IATEvent.providedBy(other):
            return cmp((self.start_date, self.duration, self.title),
                       (other.start_date, other.duration, other.title))
        elif isinstance(other, DateTime):
            return cmp(self.start(), other)
        else:
            # TODO come up with a nice cmp for types
            return cmp(self.title, other)
コード例 #4
0
    def __cmp__(self, other):
        """Compare method

        If other is based on ATEvent, compare start, duration and title.
        #If other is a number, compare duration and number
        If other is a DateTime instance, compare start date with date
        In all other cases there is no specific order
        """
        # Please note that we can not use self.Title() here: the generated
        # edit accessor uses getToolByName, which ends up in
        # five.localsitemanager looking for a parent using a comparison
        # on this object -> infinite recursion.
        if IATEvent.providedBy(other):
            return cmp((self.start_date, self.duration, self.title),
                       (other.start_date, other.duration, other.title))
        elif isinstance(other, DateTime):
            return cmp(self.start(), other)
        else:
            # TODO come up with a nice cmp for types
            return cmp(self.title, other)
コード例 #5
0
    def populate_archetype(self, obj):
        request = self.request
        fields = obj.Schema().fields()

        for field in fields:
            name = field.__name__
            if name in ['title', 'id']:
                continue

            if shasattr(field, 'vocabulary') and IVocabulary.providedBy(field.vocabulary):
                vocab = field.vocabulary.getVocabularyDict(obj)
                value = vocab.keys()[random.randint(0, len(vocab.keys())-1)]
                
            elif atfield.IStringField.providedBy(field):
                validators = [v[0].name for v in field.validators]
                if 'isURL' in validators:
                    value = 'http://en.wikipedia.com/wiki/Lorem_ipsum'
                elif 'isEmail' in validators:
                    value = '*****@*****.**'
                else:
                    value = self.get_text_line()

            elif atfield.ITextField.providedBy(field):
                widget = field.widget
                if isinstance(widget, RichWidget):
                   value = self.get_rich_text() 
                else:
                   value = self.get_text_paragraph() 

            elif atfield.IBooleanField.providedBy(field):
                value = random.randint(0,1) and True or False
            else:
                continue

            field.set(obj, value)

        if IATEvent.providedBy(obj):
            days = random.random()*20 * (random.randint(-1,1) or 1)
            value = DateTime() + days
            obj.setStartDate(value)
            obj.setEndDate(value+random.random()*3)
コード例 #6
0
def populate_archetype(obj, data):
    fields = obj.Schema().fields()
    for field in fields:
        name = field.__name__
        if name in ['id']:
            continue

        if name == 'title':
            value = data['title']

        elif shasattr(field, 'vocabulary') and \
                IVocabulary.providedBy(field.vocabulary):

            vocab = field.vocabulary.getVocabularyDict(obj)
            value = vocab.keys()[random.randint(0, len(vocab.keys()) - 1)]

        elif atfield.IStringField.providedBy(field):
            validators = [v[0].name for v in field.validators]
            if 'isURL' in validators:
                value = 'http://en.wikipedia.com/wiki/Lorem_ipsum'
            elif 'isEmail' in validators:
                value = '*****@*****.**'
            else:
                value = get_text_line()

        elif atfield.ITextField.providedBy(field):
            widget = field.widget
            if isinstance(widget, RichWidget):
                value = get_rich_text(data)
            else:
                value = get_text_paragraph()

        elif atfield.IBooleanField.providedBy(field):
            if 'Folder' == obj.portal_type:
                value = random.choice((0, 0, 0, 0, 1))
            else:
                value = random.randint(0, 1) and True or False
        else:
            continue

        field.set(obj, value)

    # subject
    subject = obj.getField('subject')
    if subject and data.get('subjects'):
        subjects = data.get('subjects', '').splitlines() or get_subjects()
        random.shuffle(subjects)
        subject.set(obj, subjects[:4])

    if IATEvent.providedBy(obj):
        days = random.random() * 20 * (random.randint(-1, 1) or 1)
        value = DateTime() + days
        obj.setStartDate(value)
        obj.setEndDate(value + random.random() * 3)

    # Set Images
    generate_image = data.get('generate_images') or obj.portal_type == 'Image'
    if obj.getField('image') and generate_image:
        field = obj.getField('image')
        name = data.get('generate_images_service')
        params = data.get('generate_images_params')
        getter = component.getUtility(IFakeImageGetter, name=name)
        title = get_text_line()
        img_content = getter.get(params=params, text=title)
        if img_content:
            field.set(obj, img_content)
            log.info('[%s] got dummy image for %s'
                     % (getter.name, '/'.join(obj.getPhysicalPath())))
コード例 #7
0
 def getFields(self):
     # Don't add fields for events
     if IATEvent.providedBy(self.context):
         return []
     return self.fields
コード例 #8
0
 def test_implementsATEvent(self):
     self.assertTrue(IATEvent.providedBy(self.obj))
     self.assertTrue(verifyObject(IATEvent, self.obj))
コード例 #9
0
def populate_archetype(obj, data):
    fields = obj.Schema().fields()
    for field in fields:
        name = field.__name__
        if name in ['id']:
            continue

        if name == 'title':
            value = data['title']

        elif shasattr(field, 'vocabulary') and \
                IVocabulary.providedBy(field.vocabulary):

            vocab = field.vocabulary.getVocabularyDict(obj)
            value = vocab.keys()[random.randint(0, len(vocab.keys())-1)]

        elif atfield.IStringField.providedBy(field):
            validators = [v[0].name for v in field.validators]
            if 'isURL' in validators:
                value = 'http://en.wikipedia.com/wiki/Lorem_ipsum'
            elif 'isEmail' in validators:
                value = '*****@*****.**'
            else:
                value = get_text_line()

        elif atfield.ITextField.providedBy(field):
            widget = field.widget
            if isinstance(widget, RichWidget):
                value = get_rich_text(data)
            else:
                value = get_text_paragraph()

        elif atfield.IBooleanField.providedBy(field):
            value = random.randint(0, 1) and True or False
        else:
            continue

        field.set(obj, value)

    # subject
    subject = obj.getField('subject')
    if subject and data.get('subjects'):
        subjects = data.get('subjects', '').splitlines() or get_subjects()
        random.shuffle(subjects)
        subject.set(obj, subjects[:4])

    if IATEvent.providedBy(obj):
        days = random.random()*20 * (random.randint(-1, 1) or 1)
        value = DateTime() + days
        obj.setStartDate(value)
        obj.setEndDate(value+random.random()*3)

    # Set Images
    generate_image = data.get('generate_images') or obj.portal_type == 'Image'
    if obj.getField('image') and generate_image:
        field = obj.getField('image')
        name = data.get('generate_images_service')
        params = data.get('generate_images_params')
        getter = component.getUtility(IFakeImageGetter, name=name)
        title = get_text_line()
        img_content = getter.get(params=params, text=title)
        if img_content:
            field.set(obj, img_content)
            log.info('[%s] got dummy image for %s'
                     % (getter.name, '/'.join(obj.getPhysicalPath())))
コード例 #10
0
 def getFields(self):
     # Don't add fields for events
     if IATEvent.providedBy(self.context):
         return []
     return self.fields