Beispiel #1
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')
Beispiel #2
0
    def test_char_field_invalid_data(self):
        """Setting CharField data to something to a number should raise InvalidField"""

        testfield = CharField('Title')

        try:
            testfield.validate(6)
            self.fail('Setting CharField data to a number should raise InvalidField')
        except InvalidField:
            pass
Beispiel #3
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')
Beispiel #4
0
class TopStoryLive(Widget):
    id = 'top-story-live'
    name = 'Top Story Live'
    template = 'widgets/frontpage/topstory-live.html'
    zones = (FrontPage, )

    title = CharField('Title')
    video_url = CharField('Video URL')
    summary = CharField('Video Summary')

    accepted_keywords = ('articles', )
    zones = (ArticleHorizontal, )
Beispiel #5
0
    def test_char_field_max_data_len(self):
        """Data must be equal to or below 255 charecters if max_len is not set to False"""

        testfield = CharField('Title')

        # 256 charecters
        data = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tempus metus et ultrices vehicula. Phasellus placerat, mi sed posuere elementum, nisl nisi condimentum odio, sit amet facilisis sem sapien et ligula. Phasellus vel sagittis mi. Morbi nullam.'

        try:
            testfield.validate(data)
            self.fail('Should fail with InvalidField')
        except InvalidField:
            pass
Beispiel #6
0
    def test_char_field_invalid_label(self):
        """Initilaizing with invalid data should raise an error"""

        try:
            testfield = CharField(6)
            self.fail('Setting CharField label to a number should raise InvalidField')
        except InvalidField:
            pass
Beispiel #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')
Beispiel #8
0
class TestWidgetB(Widget):
    id = TEST_WIDGET_B_ID
    name = TEST_WIDGET_B_NAME
    template = TEST_WIDGET_B_TEMPLATE

    zones = [TestZoneA, TestZoneB]

    title = CharField('Title')
Beispiel #9
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
Beispiel #10
0
class TestWidget3(Widget):
    id = 'test-widget-3'
    name = 'Test widget 3'
    template = 'widgets/test-widget.html'

    zones = [TestZone]

    title = CharField('Title')
Beispiel #11
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')
Beispiel #12
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
Beispiel #13
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)
Beispiel #14
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])
Beispiel #15
0
class TestWidgetC(TestWidgetB):
    id = TEST_WIDGET_C_ID
    name = TEST_WIDGET_C_NAME
    template = TEST_WIDGET_B_TEMPLATE

    zones = [TestZoneA, TestZoneB]

    title = CharField('Title')

    def before_save(self, data):
        data['title'] += ' TEST'
        return data
Beispiel #16
0
class Election2018(Widget):
    id = 'ams_election_2018'
    name = 'AMS Election 2018'
    template = 'widgets/frontpage/election_2018.html'
    zones = (FrontPage, )
    accepted_keywords = ('articles', )

    video_url = CharField('Facebook Live Video URL')

    top_story = WidgetField('Top Story', [TopStoryDefault, TopStoryLive],
                            required=True)
    sidebar = WidgetField('Sidebar', [TwitterFrontPage], required=True)
Beispiel #17
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')
Beispiel #18
0
    def test_char_field(self):
        """Should be able to initialize charfield and set data"""

        testfield = CharField('Title')

        data = 'This is a sentence'

        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 sentence')
        self.assertEqual(testfield.prepare_data(data), 'This is a sentence')
Beispiel #19
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')
Beispiel #20
0
class TestWidgetSub(Widget):
    id = 'test-widget-sub'
    name = 'Test Widget Sub'
    template = 'widgets/test-widget.html'

    title = CharField('title')
Beispiel #21
0
class VoteCompass(Template):
    id = 'vote-compass'
    name = 'Vote Compass'

    css = CharField('CSS')
    js = CharField('JavaScript')
Beispiel #22
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('')
Beispiel #23
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)
Beispiel #24
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)