Ejemplo n.º 1
0
    def test_datetimefield(self):
        """DateTimeField should correctly parse at least ISO format"""
        testfield = DateTimeField('Test')

        date = datetime.today()
        date_sz = date.isoformat()

        testfield.validate(date_sz)

        self.assertEqual(testfield.prepare_data(date_sz), date)
Ejemplo n.º 2
0
    def test_datetimefield_invalid_data(self):
        """DateTimeField should throw InvalidField when it is given an unparsable string"""
        testfield = DateTimeField('Test')
        date_sz = 'garbage'

        try:
            testfield.validate(date_sz)
            self.fail('Field date is invalid, exception should have been thrown')
        except InvalidField:
            pass
Ejemplo n.º 3
0
class Timeline(Template):
    id = 'timeline'
    name = 'Timeline'

    instruction = (
        '<p>To add this article to a timeline, you must include the relevant timeline'
        '<b style="font-weight: bold;">Tag</b> in the <b style="font-weight: bold;">Basic fields</b> tab. </p>'
        '<p>If creating a new timeline, timeline tags must be prefixed with <b style="font-weight: bold;">"timeline-"</b>'
        'and followed by the timeline title with each word separated by hyphen e.g. '
        '<b style="font-weight: bold;">"timeline-The-Galloway-Case"</b>.</p>')
    INSTRUCTIONS = (('instruction', instruction))

    IMAGE_SIZE_OPTIONS = (('default', 'Default'), ('full', 'Full'))

    HEADER_LAYOUT_OPTIONS = (('right-image', 'Right Image'),
                             ('top-image', 'Top Image'), ('banner-image',
                                                          'Banner Image'))

    instructions = InstructionField('Instructions', options=INSTRUCTIONS)
    image_size = SelectField('Image Size', options=IMAGE_SIZE_OPTIONS)
    header_layout = SelectField('Header Layout',
                                options=HEADER_LAYOUT_OPTIONS,
                                required=True)
    description = TextField('Description', required=True)
    timeline_date = DateTimeField('Timeline Date', required=True)
Ejemplo n.º 4
0
    def test_fields_required_empty(self):
        """Test fields with the required prop and ensure they raise an error
        when given empty data
        """

        testfield = CharField('Test', required=True)
        with self.assertRaises(InvalidField):
            testfield.validate(None)
        with self.assertRaises(InvalidField):
            testfield.validate('')

        testfield = TextField('Test', required=True)
        with self.assertRaises(InvalidField):
            testfield.validate(None)
        with self.assertRaises(InvalidField):
            testfield.validate('')

        testfield = DateTimeField('Test', required=True)
        with self.assertRaises(InvalidField):
            testfield.validate(None)
        with self.assertRaises(InvalidField):
            testfield.validate('')

        testfield = IntegerField('Test', required=True)
        with self.assertRaises(InvalidField):
            testfield.validate(None)
        with self.assertRaises(InvalidField):
            testfield.validate('')
Ejemplo n.º 5
0
class AlertBanner(Widget):
    id = 'alert-banner'
    name = 'Alert Banner'
    template = 'widgets/alert-banner.html'
    zones = (SiteBanner, )

    text = CharField('Text')
    url = CharField('URL')

    start_time = DateTimeField('Start Time')
    end_time = DateTimeField('End Time')

    def context(self, result):

        result['do_show'] = in_date_range(result['start_time'],
                                          result['end_time'])
        return result
Ejemplo n.º 6
0
class FacebookVideoBig(Widget):
    id = 'facebook-video-big'
    name = 'Facebook Video Big'
    template = 'widgets/frontpage/facebook-video-big.html'
    zones = (FrontPage, )

    title = CharField('Title')
    description = CharField('Description')
    host = CharField('Video Host (will display as author)')
    video_url = CharField('Video URL')
    show_comments = BoolField('Show Comment Box')

    start_time = DateTimeField('Start Time')
    end_time = DateTimeField('End Time')

    def context(self, result):
        result['do_show'] = in_date_range(result['start_time'],
                                          result['end_time'])
        return result
Ejemplo n.º 7
0
    def test_fields_notrequired_empty(self):
        """Not required fields should accept empty values"""

        testfield = CharField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), '')

        testfield = TextField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), '')

        testfield = DateTimeField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), None)

        testfield = IntegerField('Test')
        testfield.validate('')
        self.assertEqual(testfield.prepare_data(''), None)
Ejemplo n.º 8
0
    def test_fields_required(self):
        """Test fields with the required prop and ensure they validate"""

        testfield = CharField('Test', required=True)
        testfield.validate('test')
        self.assertEqual(testfield.prepare_data('test'), 'test')

        testfield = TextField('Test', required=True)
        testfield.validate('test')
        self.assertEqual(testfield.prepare_data('test'), 'test')

        testfield = DateTimeField('Test', required=True)
        date = datetime.today()
        date_sz = date.isoformat()
        testfield.validate(date_sz)
        self.assertEqual(testfield.prepare_data(date_sz), date)

        testfield = IntegerField('Test', required=True)
        testfield.validate('5')
        self.assertEqual(testfield.prepare_data('5'), 5)
Ejemplo n.º 9
0
class UpcomingEventsWidget(Widget):
    id = 'upcoming-events'
    name = 'Upcoming Events'
    template = 'widgets/upcoming-events.html'
    zones = (HomePageSidebarBottom, )

    featured_events = EventField('Featured Event(s)', many=True)
    featured_event_until = DateTimeField('Featured Event Time Limit')
    number_of_events = IntegerField('Number of Upcoming Events', min_value=0)

    def context(self, result):
        """Override context to add the next N events occuring to the context"""

        num_events = result['number_of_events']
        if num_events is None:
            num_events = 5

        if result['featured_event_until']:
            today = datetime.today()
            if today > result['featured_event_until'].replace(tzinfo=None):
                result['featured_events'] = None

        if result['featured_events']:
            exclusions = map(lambda e: e.pk, result['featured_events'])
        else:
            exclusions = []

        events = Event.objects \
            .filter(is_submission=False) \
            .filter(is_published=True) \
            .filter(start_time__gt=datetime.today()) \
            .exclude(pk__in=exclusions) \
            .order_by('start_time')[:num_events]

        result['upcoming'] = events

        return result