当前位置: 首页>>代码示例>>Python>>正文


Python public.ObjectField类代码示例

本文整理汇总了Python中Products.Archetypes.public.ObjectField的典型用法代码示例。如果您正苦于以下问题:Python ObjectField类的具体用法?Python ObjectField怎么用?Python ObjectField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ObjectField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set

    def set(self, instance, value, **kwargs):
        """
        """
        if value is None:
            ObjectField.set(self, instance, value, **kwargs)
            return

        if self.multiValued and not isinstance(value, (list, tuple)):
            value = value,
        elif not self.multiValued and isinstance(value, (list, tuple)):
            if len(value) > 1:
                raise ValueError(
                    "Multiple values given for single valued field %r" % self)
            value = value[0]

        intid_tool = getUtility(IIntIds)

        #convert objects to intids if necessary
        if self.multiValued:
            result = []
            for v in value:
                if isinstance(v, (basestring, int)):
                    result.append(RelationValue(int(v)))
                else:
                    result.append(RelationValue(intid_tool.getId(v)))
        else:
            if isinstance(value, (basestring, int)):
                result = RelationValue(int(value))
            else:
                result = RelationValue(intid_tool.getId(value))

        ObjectField.set(self, instance, result, **kwargs)
开发者ID:dbrenneman,项目名称:archetypes.z3crelationfield,代码行数:32,代码来源:field.py

示例2: set

 def set(self, instance, value, **kwargs):
     if not isinstance(value, PythonScript):
         s = self._seperator
         body = "%s\n%s%s\n%s%s" % (self.header, s, value, s, self.footer)
         script = PythonScript(self.getName())
         script.ZPythonScript_edit('**options', body)
         value = script
     ObjectField.set(self, instance, value, **kwargs)
开发者ID:dtgit,项目名称:dtedu,代码行数:8,代码来源:_field.py

示例3: get

 def get(self, instance, **kwargs):
     value = ObjectField.get(self, instance, **kwargs)
     if type(value) in types.StringTypes:
         # migration from TextField
         zpt = ZopePageTemplate(self.getName())
         ObjectField.set(self, instance, zpt, **kwargs)
         value = ObjectField.get(self, instance, **kwargs)
     return value.pt_render(extra_context={'options': kwargs})
开发者ID:dtgit,项目名称:dtedu,代码行数:8,代码来源:_field.py

示例4: set

 def set(self, instance, value, **kwargs):
     """ test"""
     #log("Set: value = %s, specific=%s" % (value, kwargs.get('specific','wer')))
     if value == 'specific':
         if kwargs.has_key('specific'):
             value = kwargs['specific']
         else:
             value = 'latest'
     ObjectField.set(self, instance, value, **kwargs)
开发者ID:Rhaptos,项目名称:Products.RhaptosCollection,代码行数:9,代码来源:Field.py

示例5: _render_output_html

 def _render_output_html(self):
     """ Return rendered newsletter
         with header+body+footer (raw html).
     """
     enl = self.getNewsletter()
     # get out_template from ENL object and render it in context of issue
     out_template_pt_field = enl.getField('out_template_pt')
     ObjectField.set(out_template_pt_field, self, ZopePageTemplate(
         out_template_pt_field.getName(),
         enl.getRawOut_template_pt()))
     output_html = safe_portal_encoding(self.out_template_pt.pt_render())
     output_html = compactify(output_html, filter_tags=False)
     return output_html
开发者ID:zopyx,项目名称:Products.EasyNewsletter,代码行数:13,代码来源:ENLIssue.py

示例6: get

 def get(self, instance, **kwargs):
     value = ObjectField.get(self, instance, **kwargs)
     if type(value) in types.StringTypes:
         # migration from TextField
         zpt = ZopePageTemplate(self.getName())
         ObjectField.set(self, instance, zpt, **kwargs)
         value = ObjectField.get(self, instance, **kwargs)
     if config.CATCH_RENDER_ERRORS:
         try:
             return value.pt_render(extra_context={'options': kwargs})
         except Exception, e:
             return _(u"zpt_field_render_error",
                      default=u'<div class="error">An error occured while rendering this field</div>')
开发者ID:Vinsurya,项目名称:Plone,代码行数:13,代码来源:_field.py

示例7: _render_output_html

 def _render_output_html(self):
     """ Return rendered newsletter
         with header+body+footer (raw html).
     """
     enl = self.getNewsletter()
     props = getToolByName(self, "portal_properties").site_properties
     charset = props.getProperty("default_charset")
     # get out_template from ENL object and render it in context of issue
     out_template_pt_field = enl.getField('out_template_pt')
     ObjectField.set(out_template_pt_field, self, ZopePageTemplate(
         out_template_pt_field.getName(),
         enl.getRawOut_template_pt()))
     output_html = safe_portal_encoding(self.out_template_pt.pt_render())
     return output_html
开发者ID:simahawk,项目名称:Products.EasyNewsletter,代码行数:14,代码来源:ENLIssue.py

示例8: set

    def set(self, instance, value, **kwargs):
        """
        Check if value is an actual FixedPoint value. If not, attempt to
        convert it to one; Raise an error if value is a float. Assign
        all properties passed as kwargs to object.

        field.set( FixedPoint(10))
        field.set( FixedPointInstance)

        """
        assert type(value) != type(0.00)

        if not value is None and not isinstance(value, FixedPoint):
            value = FixedPoint(value)

        ObjectField.set(self, instance, value, **kwargs)
开发者ID:rochecompaan,项目名称:Products.FinanceFields,代码行数:16,代码来源:FixedPointField.py

示例9: set

 def set(self, instance, value, **kwargs):
     """
     Tests if all elements in value are numbers and save them as minutes.
     
     @see ObjectField.set
     """
     result = []
     
     for item in value:
         if self.required or item:
             m = re.match('^(\d\d)[.:]?(\d\d)$', item.strip())
             result.append((int(m.group(1)) * 60 ) + int(m.group(2)))
         else:
             result = []
             break
     
     ObjectField.set(self, instance, result, **kwargs)
开发者ID:collective,项目名称:ECLecture,代码行数:17,代码来源:TimePeriodField.py

示例10: getRaw

 def getRaw(self, instance, **kwargs):
     body = ObjectField.get(self, instance, **kwargs).body()
     p1 = body.find(self._seperator)
     if p1 == -1:
         # no seperator: we return the whole body
         return body
     else:
         p1 = p1 + len(self._seperator)
         p2 = body.find(self._seperator, p1)
         return body[p1:p2]
开发者ID:dtgit,项目名称:dtedu,代码行数:10,代码来源:_field.py

示例11: validate_required

    def validate_required(self, instance, value, errors):
        """
        Tests if all elements in value are not None. If one is None a 
        error message will be returned.
        
        @see ObjectField.validate_required
        """
        result = True
        
        for item in value:
            if not item:
                result = False
                break

        return ObjectField.validate_required(self, instance, result, errors)
开发者ID:collective,项目名称:ECLecture,代码行数:15,代码来源:TimePeriodField.py

示例12: set

    def set(self, instance, value, **kwargs):
        """
        Check if value is an actual Money value. If not, attempt
        to convert it to one; otherwise, set to None. Assign all
        properties passed as kwargs to object.

        field.set( Money(10, 'ZAR') )
        field.set( money_instance )

        """
        if value is not None:
            if type(value) in STRING_TYPES:
                cur, value = parseString(decode(value, instance))
                if self.use_global_currency:
                    cur = self.getGlobalCurrency()
                else:
                    if cur is None:
                        cur = self.getDefaultCurrency(instance)
                value = Money(value, cur)

            assert isinstance(value, Money), (
                'value must be Money instance. value == %s' % value)

        ObjectField.set(self, instance, value, **kwargs)
开发者ID:rochecompaan,项目名称:Products.FinanceFields,代码行数:24,代码来源:MoneyField.py

示例13: getRaw

    def getRaw(self, instance, aslist=False, **kwargs):
        """Return the list of UIDs referenced under this fields
        relationship
        """
        objects = []
        uids = ObjectField.get(self, instance, **kwargs)

        if uids is None:
            uids = []

        if not self.multiValued and not aslist:
            if uids:
                uids = uids[0]
            else:
                uids = None
        return uids
开发者ID:rochecompaan,项目名称:upfront.simplereferencefield,代码行数:16,代码来源:simplereferencefield.py

示例14: get

    def get(self, instance, aslist=False, **kwargs):
        """
        """
        res = ObjectField.get(self, instance, **kwargs)
        if res is None:
            return res

        if self.multiValued:
            resolved = []
            for rel in res:
                resolved.append(rel.to_object)
        else:
            resolved = res.to_object
            if aslist:
                resolved = [resolved]

        return resolved
开发者ID:dbrenneman,项目名称:archetypes.z3crelationfield,代码行数:17,代码来源:field.py

示例15: get

    def get(self, instance, aslist=False, **kwargs):
        objects = []
        rc = getToolByName(instance, REFERENCE_CATALOG)
        uids = ObjectField.get(self, instance, **kwargs)

        if uids is None:
            uids = []

        for uid in uids:
            if uid:
                objects.append(rc.lookupObject(uid))

        if objects:
            if not self.multiValued:
                return objects[0]
            else:
                return objects

        return []
开发者ID:rochecompaan,项目名称:upfront.simplereferencefield,代码行数:19,代码来源:simplereferencefield.py


注:本文中的Products.Archetypes.public.ObjectField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。