Example #1
0
    def test_text_field_invalid_data(self):
        """Setting TextField data to something to a number should raise InvalidField"""

        testfield = TextField('Title')

        try:
            testfield.validate(6)
            self.fail('Setting TextField data to a number should raise InvalidField')
        except InvalidField:
            pass
Example #2
0
class MagazinePoem(Template):
    id = 'magazine-poem'
    name = 'Magazine - Poem'

    byline = TextField('Byline')
    byline_2 = TextField('Byline 2')
    top_color = CharField('Top Color')
    bottom_color = CharField('Bottom Color')
    text_color_a = CharField('Text Color A')
    text_color_b = CharField('Text Color B')
    offset = CharField('Top Offset')
Example #3
0
class Magazine(Template):
    id = 'magazine'
    name = 'Magazine - Article'

    COLOR_OPTIONS = (('green', 'Green'), ('pink', 'Pink'), ('blue', 'Blue'))

    DISPLAY_OPTIONS = (('default', 'Default'), ('basic', 'Basic'))

    byline = TextField('Byline')
    byline_2 = TextField('Byline 2')
    description = TextField('Description')
    color = SelectField('Accent Color', options=COLOR_OPTIONS)
    display = SelectField('Display type', options=DISPLAY_OPTIONS)
Example #4
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)
Example #5
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('')
Example #6
0
class Guide(Template):
    id = 'guide-to-ubc'
    name = 'Guide to UBC'

    subheading = CharField('Sub-heading')
    intro = TextField('Intro text')
    next_a = CharField('Up next A')
    next_b = CharField('Up next B')
Example #7
0
class OneYearLater(Template):
    id = 'one-year-later'
    name = 'Feature: One Year Later'

    title = CharField('Title')
    subtitle = CharField('Subtitle')
    snippet = TextField('Snippet')
    video_src = CharField('Video Source File')
    next_article = ArticleField('Preview Article')
    next_title = CharField('Preview Title')
    next_snippet = TextField('Preview Snippet')

    article_then = ArticleField('Then Article')
    article_now = ArticleField('Now Article')
    article_next = ArticleField('Next Article')

    about = TextField('About')
Example #8
0
class LatestPodcastWidget(Widget):
    id = 'latest-podcast'
    name = 'Latest Podcast'
    template = 'components/latest-podcast.html'

    zones = (LatestPodcast, )

    podcast = PodcastField('Podcast')
    link = CharField('Link')
    embed = TextField('Embed')
Example #9
0
class SoccerNationals(Template):
    id = 'soccer-nationals'
    name = 'Soccer Nationals'

    instruction = (
        '<p>json object to be added inside a code block. gallery with alternating team, player in same order as json object to be included at end of article<p>.'
    )
    INSTRUCTIONS = (('instruction', instruction))

    instructions = InstructionField('Instructions', options=INSTRUCTIONS)
    description = TextField('Description', required=True)
Example #10
0
class TestWidget2(Widget):
    id = 'test-widget-2'
    name = 'Test widget 2'
    template = 'widgets/test-widget.html'

    zones = [TestZone]

    title = CharField('Title 2')
    description = TextField('Description 2')
    article = ArticleField('Featured article 2')
    image = ImageField('Featured image 2')
    widget = WidgetField('Featured Widget 2', [TestWidgetSub])
Example #11
0
class TestWidgetR(Widget):
    id = 'test-widget-r'
    name = 'Test Widget R'
    template = 'widget/test-widget.html'

    zones = [TestZone]

    title = CharField('Title', required=True)
    description = TextField('Description', required=True)
    article = ArticleField('Featured article', required=True)
    image = ImageField('Featured image', required=True)
    widget = WidgetField('Featured Widget', [TestWidgetSub], required=True)
Example #12
0
class FullWidth(Template):
    id = 'fw-story'
    name = 'Full width story'

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

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

    description = TextField('Description')
    image_size = SelectField('Image Size', options=IMAGE_SIZE_OPTIONS)
    header_layout = SelectField('Header Layout', options=HEADER_LAYOUT_OPTIONS)
Example #13
0
class TestWidget(Widget):
    id = 'test-widget'
    name = 'Test widget'
    template = 'widgets/test-widget.html'

    accepted_keywords = ('extra', )

    zones = [TestZone]

    title = CharField('Title')
    description = TextField('Description')
    article = ArticleField('Featured article')
    image = ImageField('Featured image')
Example #14
0
class FoodInsecurity(Template):
    id = 'food-insecurity'
    name = 'Feature: Food Insecurity'

    title = CharField('Title')
    subtitle = CharField('Subtitle')
    snippet = TextField('Snippet')
    video_src = CharField('Video Source File')
    next_article = ArticleField('Preview Article')
    next_title = CharField('Preview Title')
    next_snippet = TextField('Preview Snippet')

    article_first = ArticleField('First Article')
    article_first_preview = CharField('First Article Preview')

    article_second = ArticleField('Second Article')
    article_second_preview = CharField('Second Article Preview')

    article_third = ArticleField('Third Article')
    article_third_preview = CharField('Third Article Preview')

    about = TextField('About')
Example #15
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)
Example #16
0
    def test_text_field(self):
        """Should be able to initialize charfield and set data"""

        testfield = TextField('Title')

        data = 'This is a longer sentence than the one further up\nthis file'

        try:
            testfield.validate(data)
        except InvalidField:
            self.fail('Field data is valid, exception should not have been thrown')

        self.assertEqual(testfield.to_json(data), 'This is a longer sentence than the one further up\nthis file')
        self.assertEqual(testfield.prepare_data(data), 'This is a longer sentence than the one further up\nthis file')
Example #17
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)