Exemplo n.º 1
0
class OfficerPageSerializer(SlugPageSerializer):
    triangle_description = RichTextField(fake_value=[
        'The corners of the triangle show the percentile score for this officer in each of three types of data: '
        'complaints from civilians, complaints from other officers, and self-reported uses of force.'
    ],
                                         source='fields')
    triangle_sub_description = RichTextField(fake_value=[
        'If one corner of the black inner triangle is close to reaching the outer triangle, '
        'then this officer is named in a relatively high rate of incidents of that '
        'type compared with other officers.'
    ],
                                             source='fields')
    scale_description = RichTextField(fake_value=[
        'If an officer\'s percentile rank for civilian complaints is 99% then this means that '
        'they were accused in more civilian complaints per year than 99% of other officers.'
    ],
                                      source='fields')
    scale_sub_description = RichTextField(fake_value=[
        'Civilian and internal complaint percentiles are based on data '
        'that is only available since 2000, use of force data is only available since 2004. '
        'The overall allegation count percentiles displayed on '
        'the officer profile page are calculated using data that reaches back to 1988.'
    ],
                                          source='fields')
    no_data_explain_text = RichTextField(fake_value=[
        'There is not enough data to construct',
        'a radar graph for this officer.'
    ],
                                         source='fields')

    class Meta:
        slug = 'officer-page'
        model = SlugPage
Exemplo n.º 2
0
    def test_fake_value(self, patch_faker):
        expect(self.field.fake_value('some text')).to.eq(['some text'])
        expect(self.field.fake_value(9)).to.eq(9)

        patch_faker.return_value = Mock(
            **{'sentence': Mock(return_value='some sentence')})
        field = RichTextField()
        expect(field.fake_value()).to.eq(['some sentence'])
        expect(self.field.fake_value()).to.eq(['abc', 'xyz'])
Exemplo n.º 3
0
class TRRPageSerializer(SlugPageSerializer):
    document_request_instruction = RichTextField(
        fake_value=['We’ll notify you when the document is made available.'],
        source='fields')
    no_attachment_text = RichTextField(
        fake_value=['There are no documents that have been made public yet.'],
        source='fields')

    class Meta:
        slug = 'trr-page'
        model = SlugPage
class TestingPageSerializer(SlugPageSerializer):
    first_field = RichTextField(
        fake_value=['This is the initial value for first_field'],
        source='fields')
    second_field = RichTextField(
        fake_value=['This is the initial value for second_field'],
        source='fields')

    class Meta:
        slug = 'testing-page'
        model = SlugPage
Exemplo n.º 5
0
class PinboardPageSerializer(SlugPageSerializer):
    empty_pinboard_title = RichTextField(fake_value=['Get started'],
                                         source='fields')
    empty_pinboard_description = RichTextField(fake_value=[
        'Use search to find officers and individual complaint records and press the plus button to add cards to '
        'your pinboard.', '',
        'Come back to the pinboard to give it a title and see a network map or discover relevant documents.'
    ],
                                               source='fields')

    class Meta:
        slug = 'pinboard-page'
        model = SlugPage
Exemplo n.º 6
0
class PeoplePage(HelpBasePage):
    intro_paragraph = RichTextField(
        blank=True,
        help_text=_(
            "Text at the top of the page. Supports standard markdown."),
        validators=[validators.ProhibitNullCharactersValidator()],
    )

    template = "cms/people_page.html"

    admin_fields = HelpBasePage.admin_fields + ("intro_paragraph", )

    class Meta:
        manager_inheritance_from_future = True
Exemplo n.º 7
0
class HelpPage(HelpBasePage):
    body = RichTextField(
        help_text=_("Markdown text, support the TOC extension."),
        validators=[validators.ProhibitNullCharactersValidator()],
        allow_tags=HELP_PAGE_TAGS,
        safe_attrs=HELP_PAGE_ATTRS,
        extensions=HELP_PAGE_EXTENSIONS,
    )

    template = "cms/help_page.html"

    admin_fields = HelpBasePage.admin_fields + ("body", )

    class Meta:
        manager_inheritance_from_future = True
Exemplo n.º 8
0
class PersonInfo(models.Model):
    page = models.ForeignKey(PeoplePage, related_name="people", editable=False)
    ordinal = models.IntegerField(null=True, blank=True, editable=False)
    name = models.CharField(
        max_length=255,
        validators=[validators.ProhibitNullCharactersValidator()])
    body = RichTextField(
        validators=[validators.ProhibitNullCharactersValidator()])
    image = models.ForeignKey(
        "cms.Image",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )

    class Meta:
        ordering = ["ordinal"]
Exemplo n.º 9
0
 def setUp(self):
     self.field = RichTextField(fake_value=['abc', 'xyz'])
     self.field.field_name = 'about_content'
     self.maxDiff = None
Exemplo n.º 10
0
class RichTextFieldTestCase(SimpleTestCase):
    _type = 'rich_text'

    def setUp(self):
        self.field = RichTextField(fake_value=['abc', 'xyz'])
        self.field.field_name = 'about_content'
        self.maxDiff = None

    def test_to_representation(self):
        self.assertDictEqual(
            self.field.to_representation({'about_content_value': {
                'a': 'b'
            }}), {
                'name': 'about_content',
                'type': self._type,
                'value': {
                    'a': 'b'
                }
            })

    def test_fake_data(self):
        with patch('cms.fields.generate_draft_block_key', return_value='1'):
            self.assertDictEqual(
                self.field.fake_data(), {
                    'name': 'about_content',
                    'type': self._type,
                    'value': {
                        'blocks': [{
                            'data': {},
                            'depth': 0,
                            'entityRanges': [],
                            'inlineStyleRanges': [],
                            'key': '1',
                            'text': 'abc',
                            'type': 'unstyled'
                        }, {
                            'data': {},
                            'depth': 0,
                            'entityRanges': [],
                            'inlineStyleRanges': [],
                            'key': '1',
                            'text': 'xyz',
                            'type': 'unstyled'
                        }],
                        'entityMap': {}
                    }
                })

    @patch('cms.fields.Faker')
    def test_fake_value(self, patch_faker):
        expect(self.field.fake_value('some text')).to.eq(['some text'])
        expect(self.field.fake_value(9)).to.eq(9)

        patch_faker.return_value = Mock(
            **{'sentence': Mock(return_value='some sentence')})
        field = RichTextField()
        expect(field.fake_value()).to.eq(['some sentence'])
        expect(self.field.fake_value()).to.eq(['abc', 'xyz'])

    def test_to_internal_value(self):
        self.assertDictEqual(
            self.field.to_internal_value({
                'blocks': 'c',
                'entityMap': 'd'
            }), {
                'about_content_type': self._type,
                'about_content_value': {
                    'blocks': 'c',
                    'entityMap': 'd'
                }
            })

    def test_raise_validation_error(self):
        with self.assertRaises(serializers.ValidationError) as context_manager:
            self.field.to_internal_value('abc')

        self.assertEqual(
            context_manager.exception.detail,
            {'about_content': 'Value must be in raw content state format'})

    def test_fake_data_with_value_object(self):
        value = {
            'blocks': ['abc'],
            'entities':
            [LinkEntityFactory(url='url', length=1, offset=0, block_index=0)]
        }
        with patch('cms.fields.generate_draft_block_key', return_value='1'):
            self.assertDictEqual(
                self.field.fake_data(value), {
                    'name': 'about_content',
                    'type': self._type,
                    'value': {
                        'blocks':
                        [{
                            'data': {},
                            'depth': 0,
                            'entityRanges': [{
                                'length': 1,
                                'key': 0,
                                'offset': 0
                            }],
                            'inlineStyleRanges': [],
                            'key': '1',
                            'text': 'abc',
                            'type': 'unstyled'
                        }],
                        'entityMap': {
                            0: {
                                'data': {
                                    'url': 'url'
                                },
                                'type': 'LINK',
                                'mutability': 'MUTABLE'
                            }
                        }
                    }
                })
Exemplo n.º 11
0
class LandingPageSerializer(SlugPageSerializer):
    navbar_title = RichTextField(fake_value=['Citizens Police Data Project'],
                                 source='fields')
    navbar_subtitle = RichTextField(fake_value=[
        'collects and information', 'about police misconduct in Chicago.'
    ],
                                    source='fields')
    carousel_complaint_title = RichTextField(
        fake_value=['Complaint Summaries'], source='fields')
    carousel_complaint_desc = RichTextField(fake_value=[
        'These records contain summary information of the incident of the alleged complaint.'
    ],
                                            source='fields')
    carousel_allegation_title = RichTextField(
        fake_value=['Officers by Allegation'], source='fields')
    carousel_allegation_desc = RichTextField(fake_value=[
        'These are the officers with the most allegations of misconduct in Chicago.'
    ],
                                             source='fields')
    carousel_document_title = RichTextField(fake_value=['New Document'],
                                            source='fields')
    carousel_document_desc = RichTextField(fake_value=[
        'We often update our complaint records as we recieve more information from the City.',
        'Here are some of the recent updates.'
    ],
                                           source='fields')
    carousel_activity_title = RichTextField(fake_value=['Recent Activity'],
                                            source='fields')
    carousel_activity_desc = RichTextField(fake_value=[
        'The officers, pairings, and units we display here are based on what other guests are searching '
        'on cpdp in addition to officers who are mentioned in conversation with our twitter bot,@cpdpbot'
    ],
                                           source='fields')
    demo_video_text = RichTextField(fake_value=['What is CPDP?'],
                                    source='fields')

    class Meta:
        slug = 'landing-page'
        model = SlugPage