Esempio n. 1
0
class OfficialDocumentPageOfficialDocument(Orderable):
    page = ParentalKey(OfficialDocumentPage, related_name='official_documents')
    date = models.DateField(verbose_name="Document date", null=True)
    title = models.CharField(verbose_name="Document title",
                             max_length=DEFAULT_MAX_LENGTH)
    authoring_office = models.CharField(
        verbose_name="Authoring office of document",
        max_length=DEFAULT_MAX_LENGTH)
    summary = models.TextField(verbose_name="Document summary")
    name = models.CharField(verbose_name="Name of Document",
                            max_length=DEFAULT_MAX_LENGTH)
    document = models.ForeignKey(Document,
                                 null=True,
                                 blank=False,
                                 on_delete=models.SET_NULL,
                                 related_name='+')

    panels = [
        FieldPanel('date'),
        FieldPanel('title', widget=countMe),
        FieldPanel('authoring_office', widget=countMe),
        FieldPanel('summary',
                   widget=widgets.CountableWidget(
                       attrs={
                           'data-count': 'characters',
                           'data-max-count': AUTHOR_LIMITS['document_summary'],
                           'data-count-direction': 'down'
                       })),
        FieldPanel('name', widget=countMe),
        DocumentChooserPanel('document')
    ]

    class Meta:
        indexes = [models.Index(fields=['-date'])]
Esempio n. 2
0
class DepartmentPage(JanisBasePage):
    janis_url_page_type = "department"

    def __str__(self):
        return self.title_en

    what_we_do = RichTextField(features=WYSIWYG_GENERAL,
                               verbose_name='What we do',
                               blank=True)

    image = models.ForeignKey(TranslatedImage,
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL,
                              related_name='+')
    mission = models.TextField(verbose_name='Mission', blank=True)

    job_listings = models.URLField(
        verbose_name='Job listings url',
        help_text='Link to a page with job listings.',
        blank=True)

    base_form_class = DepartmentPageForm

    content_panels = [
        FieldPanel('title_en', widget=countMe),
        FieldPanel('title_es', widget=countMe),
        FieldPanel('title_ar'),
        FieldPanel('title_vi'),
        FieldPanel('what_we_do'),
        ImageChooserPanel('image'),
        FieldPanel('mission',
                   widget=widgets.CountableWidget(
                       attrs={
                           'data-count': 'characters',
                           'data-max-count': AUTHOR_LIMITS['mission'],
                           'data-count-direction': 'down'
                       })),
        InlinePanel('contacts', label='Contacts'),
        InlinePanel('department_directors', label="Department Directors"),
        FieldPanel('job_listings'),
        InlinePanel(
            'top_pages',
            heading='Links to top services',
            label='top link',
            help_text=
            'Add links to 1-4 top service pages or guides (4 maximum allowed).',
            min_num=None,
            max_num=4),
        InlinePanel(
            'related_pages',
            heading='Links to related pages',
            label='related page',
            help_text=
            'Add links to 1-4 related information pages or guides (4 maximum allowed).',
            min_num=None,
            max_num=4)
    ]
Esempio n. 3
0
 def test_invalid_limits(self):
     widget = widgets.CountableWidget()
     result = widget.render('countable',
                            None,
                            attrs={
                                'data-min-count': 'blue',
                                'data-max-count': 50.9
                            })
     self.assertTrue(str(result).__contains__('data-min-count="false"'))
     self.assertTrue(str(result).__contains__('data-max-count="false"'))
Esempio n. 4
0
 def test_both_limits(self):
     widget = widgets.CountableWidget()
     result = widget.render('countable',
                            None,
                            attrs={
                                'data-min-count': 30,
                                'data-max-count': 80
                            })
     self.assertTrue(str(result).__contains__('data-min-count="30"'))
     self.assertTrue(str(result).__contains__('data-max-count="80"'))
Esempio n. 5
0
class DepartmentPageDirector(Orderable):
    page = ParentalKey(DepartmentPage, related_name='department_directors')
    name = models.CharField(max_length=DEFAULT_MAX_LENGTH)
    title = models.CharField(max_length=DEFAULT_MAX_LENGTH, default='Director')
    photo = models.ForeignKey(TranslatedImage,
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL,
                              related_name='+')
    about = models.TextField(blank=True)

    panels = [
        FieldPanel('name'),
        FieldPanel('title'),
        ImageChooserPanel('photo'),
        FieldPanel('about',
                   widget=widgets.CountableWidget(
                       attrs={
                           'data-count': 'characters',
                           'data-max-count': AUTHOR_LIMITS['about_director'],
                           'data-count-direction': 'down'
                       }))
    ]
Esempio n. 6
0
 def test_no_limits(self):
     widget = widgets.CountableWidget()
     result = widget.render('countable', None)
     self.assertTrue(str(result).__contains__('data-min-count="false"'))
     self.assertTrue(str(result).__contains__('data-max-count="false"'))
Esempio n. 7
0
 def test_upper_limit(self):
     widget = widgets.CountableWidget()
     result = widget.render('countable', None, attrs={'data-max-count': 70})
     self.assertTrue(str(result).__contains__('data-min-count="false"'))
     self.assertTrue(str(result).__contains__('data-max-count="70"'))
Esempio n. 8
0
(Those limits may be greater)
This allows for spillover/going negative on the character count and also helps keep tables consistent
These limits are more about content than about data schema or performance
"""


GENERIC_TITLE_LIMIT = 58
GENERIC_DESCRIPTION_LIMIT = 254

AUTHOR_LIMITS = {

    "title": GENERIC_TITLE_LIMIT,
    "description": 254,
    "additional_content": 5000,
    "document_title": GENERIC_TITLE_LIMIT,
    "authoring_office": GENERIC_TITLE_LIMIT,
    "document_summary": 600,
    "document_name": GENERIC_TITLE_LIMIT,
    "mission": 400,
    "about_director": 600,

}

countConfig = {'data-count': 'characters',
               'data-max-count': 58, 'data-count-direction': 'down'}

countConfigTextArea = {'data-count': 'characters',
                       'data-max-count': 254, 'data-count-direction': 'down'}
countMe = widgets.CountableTextInputWidget(attrs=countConfig)
countMeTextArea = widgets.CountableWidget(attrs=countConfigTextArea)