Ejemplo n.º 1
0
class FixedRowsDemoType(atapi.BaseContent):
    """ Demostrate fixed rows usage

    This class is used in unit testing
    """
    security = ClassSecurityInfo()

    schema = atapi.BaseSchema + atapi.Schema((
        DataGridField('DemoField',
                      widget=DataGridWidget(),
                      columns=('column1', 'column2', 'The third'),
                      fixed_rows=[
                          FixedRow(keyColumn="column1",
                                   initialData={
                                       "column1": "must-exist-1",
                                       "column2": "bbb"
                                   }),
                          FixedRow(keyColumn="column2",
                                   initialData={
                                       "column1": "ddd",
                                       "column2": "must-exist-2"
                                   }),
                      ]),
        DataGridField(
            'RestrictedField',
            widget=DataGridWidget(),
            columns=('column1', 'column2', 'The third'),
            allow_insert=False,
            allow_delete=False,
            allow_reorder=False,
        ),
        DataGridField(
            'predefinedSkills',
            searchable=True,
            columns=('skill', 'level'),
            fixed_rows="getPredefinedSkillsData",
            allow_delete=False,
            allow_insert=False,
            allow_reorder=False,
            widget=DataGridWidget(
                label="Skills",
                label_msgid='DataGridDemoType_label_Skills',
                description=
                "Language/technology/tool/method for which employer has special interest",
                description_msgid='DataGridDemoType_help_Skills',
                i18n_domain='datagridfield',
                columns={
                    "skill": FixedColumn(_(u"Skill")),
                    "level": RadioColumn(_(u"Level"),
                                         vocabulary="getSkillLevels")
                }),
        ),
    ))

    meta_type = portal_type = archetype_name = 'FixedRowsDemoType'

    def getSkillLevels(self):
        return atapi.DisplayList((
            (
                "bad",
                _(u"Bad"),
            ),
            (
                "good",
                _(u"Good"),
            ),
        ))

    def getPredefinedSkillsData(self):
        """ Generate fixed row key information """
        skills = ["Python", "Perl", "XML", "Java", "Plone"]
        rows = []
        for skill in skills:
            rows.append(
                FixedRow(keyColumn="skill",
                         initialData={
                             "skill": skill,
                             "level": "bad"
                         }))

        return rows