code: def _calculate(self, field):
          '''
          We want to avoid trouble, so if the field is not enclosed by any other field,
          we just return 0.
          '''
          encloser = field.enclosing
          if encloser:
              rendered = encloser.get_rendered_fields(RenderContext(self))
              if field not in rendered:
                  value = len(rendered)
              else:
                  value = rendered.index(field)
          else:
              value = 0
          return valuf _calculate(self, field):
          '''
          We want to avoid trouble, so if the field is not enclosed by any other field,
          we just return 0.
          '''
          encloser = field.enclosing
          if encloser:
              rendered = encloser.get_rendered_fields(RenderContext(self))
              if field not in rendered:
                  value = len(rendered)
              else:
                  value = rendered.index(field)
          else:
              value = 0
          return value
docs: We want to avoid trouble, so if the field is not enclosed by any other field,
          we just return 0.