コード例 #1
0
ファイル: forms.py プロジェクト: plumi/criticalcommons.skin
    def validate_registration(self, action, data):
        """
        """

        #import pdb; pdb.set_trace()
        errors = super(MyRegistrationForm, self).validate_registration(action, data)

        form_field_names = [f.field.getName() for f in self.form_fields]

        if not ('accept' in data.keys() and data.get('accept', '')):
            err_str = _(u'Please check if you agree with the terms')
            errors.append(WidgetInputError('accept', u'label_accept', err_str))
            self.widgets['accept'].error = err_str

        if not ('fullname' in data.keys() and data.get('fullname', '')):
            err_str = _(u'Please fill in the full name')
            errors.append(WidgetInputError('fullname', u'label_fullname', err_str))
            self.widgets['fullname'].error = err_str

        if data['usertype'] == u'Advanced User':
            if not ('user_title' in data.keys() and data.get('user_title', '')):
                err_str = _(u'Please fill in the title')
                errors.append(WidgetInputError('user_title', u'label_user_title', err_str))
                self.widgets['user_title'].error = err_str
            if not ('institution' in data.keys() and data.get('institution', '')):
                err_str = _(u'Please fill in the institution')
                errors.append(WidgetInputError('institution', u'label_institution', err_str))
                self.widgets['institution'].error = err_str
            if not ('description' in data.keys() and data.get('description', '')):
                err_str = _(u'Please fill in the Biography')
                errors.append(WidgetInputError('description', u'label_description', err_str))
                self.widgets['description'].error = err_str
            if not ('home_page' in data.keys() and data.get('home_page', '')):
                err_str = _(u'Please fill in the Home Page')
                errors.append(WidgetInputError('home_page', u'label_home_page', err_str))
                self.widgets['home_page'].error = err_str

        return errors
コード例 #2
0
    def handleApply(self, action):
#        import rpdb; rpdb.set_trace()
        pm = getToolByName(self.context, 'portal_membership')
        home = pm.getHomeFolder()
        if not home: 
            return
        title = unicode(strip_tags(self.request['form.widgets.title']))[:200]
        body = self.request['form.widgets.body']
        existing = [i for i in self.context.getRelatedItems() if i.portal_type=='Commentary']
        dupes = [d for d in existing if d.Title() == title]
        if len(dupes):
            self.status = _(u"The commentary has been created")
            return
        normalizer = getUtility(IIDNormalizer)
        try:
            target_folder = home.commentaries
            new_id = target_folder.invokeFactory(id=str(DateTime.DateTime().millis()), type_name='Commentary', title=title)
            obj = target_folder[new_id]
            obj.textCommentary = RichTextValue(unicode(strip_tags(body))[:20000], 'text/plain', 'text/plain', 'utf-8')
            RelatedItems = self.context.getRelatedItems()
            RelatedItems.append(obj)
            self.context.setRelatedItems(RelatedItems)
            #used to save the related items
            #also add the video to the commentary's related items, to be used on the subscribers for when deleting a commentary
            self.context.reindexObject()
            wft = getToolByName(obj, 'portal_workflow')
            for state in ['submit','show','process','publish']:
                try:
                    wft.doActionFor(obj, state)
                except:
                    pass
            try:
#                import rpdb; rpdb.set_trace()
                intid = getUtility(IIntIds).getId(self.context)
                relatedVids = [RelationValue(intid)]
                obj.relatedItems = relatedVids
            except KeyError:
                to_id = getUtility(IIntIds).register(self.context)
                relatedVids = [RelationValue(to_id)]
                obj.relatedItems = relatedVids
        except Exception as e:
            self.status = _(u"Failed to publish commentary")
            return

        wft = getToolByName(self.context, 'portal_workflow')
        state = wft.getInfoFor(self.context, 'review_state')
        try:
            if state == "private":
                try:
                    wft.doActionFor(self.context, 'show')
                except:
                    pass
                try:
                    wft.doActionFor(self.context, 'submit')
                except:
                    pass
                try:
                    wft.doActionFor(self.context, 'publish')
                except:
                    pass
        except: 
            pass