Exemplo n.º 1
0
    def __call__(self, context):
        # Just an example list of content for our vocabulary,
        # this can be any static or dynamic data, a catalog result for example.
        items = [
            VocabItem(u'fine-art', _(u'Fine Art College')),
            VocabItem(u'design', _(u'College of Design')),
            VocabItem(u'comm', _(u'College of Communications')),
            VocabItem(u'performing', _(u'College of Performing Art')),
            VocabItem(u'human', _(u'College of Humanities')),
        ]

        # Fix context if you are using the vocabulary in DataGridField.
        # See https://github.com/collective/collective.z3cform.datagridfield/issues/31:  # NOQA: 501
        if not IDexterityContent.providedBy(context):
            req = getRequest()
            context = req.PARENTS[0]

        # create a list of SimpleTerm items:
        terms = []
        for item in items:
            terms.append(
                SimpleTerm(
                    value=item.token,
                    token=str(item.token),
                    title=item.value,
                ))
        # Create a SimpleVocabulary from the terms list and return it:
        return SimpleVocabulary(terms)
Exemplo n.º 2
0
class AddForm(base.AddForm):
    schema = IRelatedlinkPortlet
    form_fields = field.Fields(IRelatedlinkPortlet)
    label = _(u'Related Links')

    def create(self, data):
        return Assignment(
            portlet_title=data.get('portlet_title', 'portlet title'),
        )
Exemplo n.º 3
0
    def test_vocab_college(self):
        vocab_name = 'isrc.content.College'
        factory = getUtility(IVocabularyFactory, vocab_name)
        self.assertTrue(IVocabularyFactory.providedBy(factory))

        vocabulary = factory(self.portal)
        self.assertTrue(IVocabularyTokenized.providedBy(vocabulary))
        self.assertEqual(
            vocabulary.getTerm('sony-a7r-iii').title,
            _(u'Sony Aplha 7R III'),
        )
Exemplo n.º 4
0
class EditForm(base.EditForm):
    schema = IRelatedlinkPortlet
    form_fields = field.Fields(IRelatedlinkPortlet)
    label = _(u'Related Links')
Exemplo n.º 5
0
 def title(self):
     return _(u'Related Links')
Exemplo n.º 6
0
class IRelatedlinkPortlet(IPortletDataProvider):

    portlet_title = schema.TextLine(
        title=_(u'Title'),
        required=True,
    )
Exemplo n.º 7
0
    def __call__(self):

        request = self.request
        portal = api.portal.get()
        alsoProvides(request, IDisableCSRFProtection)

        self.obj = None
        if request.form.get(
                'uid') and not request.form.has_key('submit'):  # 要顯示學生資訊
            self.obj = api.content.get(UID=request.form.get('uid'))
            return self.template()

        elif request.form.has_key('submit'):  # 有submit, 新增或更新
            data = {
                'title': '',
                'student_id': '',
                'person_id': '',
                'college': '',
                'department': '',
                'day_or_night': '',
                'method_1': '',
                'method_2': '',
                'years': '',
                'cate': '',
                'birthday': '',
                'phone': '',
                'email': '',
                'facebook': '',
                'line': '',
                'field_1': '',
                'field_1_other': '',
                'field_2': '',
                'field_3': '',
                'field_4': '',
                'field_4_reason': '',
                'field_5': '',
                'field_6': '',
                'field_7': '',
                'field_8': '',
                'field_9': '',
                'field_10': '',
                'field_11': '',
                'field_12': '',
                'field_13': ''
            }
            for item in request.form.items():
                if item[0] in data.keys():
                    data[item[0]] = item[1]

            if data['field_6'] == '1':
                data['field_6'] = True
            else:
                data['field_6'] = False
            data['field_8'] = json.dumps(data['field_8'])

            if request.form.get('uid'):  # update
                obj = api.content.get(UID=request.form.get('uid'))
                api.portal.show_message(
                    message=_(u'Update student information is ok.'),
                    request=request,
                    type='info')
            else:  # add
                try:
                    obj = api.content.create(
                        container=portal['source']['student'],
                        type='StudentInfo',
                        id=data['person_id'])
                    api.portal.show_message(
                        message=_(u'Add student information is ok.'),
                        request=request,
                        type='info')
                except:
                    api.portal.show_message(
                        message=_(u'This student already exist.'),
                        request=request,
                        type='error')
                    request.response.redirect(request.getURL())
                    return
            for item in data.items():
                setattr(obj, item[0], item[1])
            obj.reindexObject()

            request.response.redirect(
                '%s/@@student_listing' %
                portal['source']['student'].absolute_url())
            return self.template()

        return self.template()  # 顯示空白表單
Exemplo n.º 8
0
class IStudentInfo(model.Schema):
    """ Marker interface and Dexterity Python Schema for StudentInfo
    """
    title = schema.TextLine(
        title=_(u'Student Name'),
        required=True,
    )

    student_id = schema.TextLine(
        title=_(u'Student Id'),
        required=True,
    )

    person_id = schema.TextLine(
        title=_(u'Person Id'),
        required=True,
    )

    college = schema.TextLine(
        title=_(u'College'),
        required=True,
    )

    department = schema.TextLine(
        title=_(u'Department'),
        required=True,
    )

    day_or_night = schema.TextLine(
        title=_(u'Day or Night'),
        required=True,
    )

    method_1 = schema.TextLine(
        title=_(u'Method 1'),
        required=True,
    )

    method_2 = schema.TextLine(
        title=_(u'Method 2'),
        required=True,
    )

    years = schema.TextLine(
        title=_(u'years'),
        required=True,
    )

    cate = schema.TextLine(
        title=_(u'categories'),
        required=False,
    )

    birthday = schema.TextLine(
        title=_(u'birthday'),
        required=False,
    )

    phone = schema.TextLine(
        title=_(u'phone'),
        required=False,
    )

    email = schema.TextLine(
        title=_(u'email'),
        required=False,
    )

    facebook = schema.TextLine(
        title=_(u'facebook'),
        required=False,
    )

    line = schema.TextLine(
        title=_(u'line'),
        required=False,
    )

    field_1 = schema.TextLine(
        title=_(u'field 1'),
        required=False,
    )

    field_1_other = schema.Text(
        title=_(u'field 1 other'),
        required=False,
    )

    field_2 = schema.Text(
        title=_(u'field 2'),
        required=False,
    )

    field_3 = schema.Text(
        title=_(u'field 3'),
        required=False,
    )

    field_4 = schema.TextLine(
        title=_(u'field 4'),
        required=False,
    )

    field_4_reason = schema.Text(
        title=_(u'field 4 reason'),
        required=False,
    )

    field_5 = schema.Text(
        title=_(u'field 5'),
        required=False,
    )

    field_6 = schema.Bool(
        title=_(u'field 6'),
        default=False,
        required=False,
    )

    field_7 = schema.Text(
        title=_(u'field 7'),
        required=False,
    )

    field_8 = schema.Text(
        title=_(u'field 8'),
        default=u'[]',
        required=True,
    )

    field_9 = schema.Text(
        title=_(u'field 9'),
        required=False,
    )

    field_10 = schema.Text(
        title=_(u'field 10'),
        required=False,
    )

    field_11 = schema.Text(
        title=_(u'field 11'),
        required=False,
    )

    field_12 = schema.Text(
        title=_(u'field 12'),
        required=False,
    )

    field_13 = schema.Text(
        title=_(u'field 13'),
        required=False,
    )