Ejemplo n.º 1
0
 def __delete__(self, instance):
     """
     Deletter of field (=
     """
     if instance is not None:
         if self._field_name in instance:
             del instance[self._field_name]
         else:
             raise AttributeError("'%(type_name)s' object has no attribute '%(field_name)s'" %
                                  {'type_name': type_name(instance), 'field_name': self._field_name})
Ejemplo n.º 2
0
 def __get__(self, instance, owner):
     """
     Getter of field
     """
     if instance is None:
         return self
     else:
         if self._field_name in instance:
             return instance[self._field_name]
         raise AttributeError("'%(type_name)s' object has no attribute '%(field_name)s'" %
                              {'type_name': type_name(owner), 'field_name': self._field_name})
Ejemplo n.º 3
0
 def __delete__(self, instance):
     """
     Deletter of field (=
     """
     if instance is not None:
         if self._field_name in instance:
             del instance[self._field_name]
         else:
             raise AttributeError(
                 "'%(type_name)s' object has no attribute '%(field_name)s'"
                 % {
                     'type_name': type_name(instance),
                     'field_name': self._field_name
                 })
Ejemplo n.º 4
0
 def __get__(self, instance, owner):
     """
     Getter of field
     """
     if instance is None:
         return self
     else:
         if self._field_name in instance:
             return instance[self._field_name]
         raise AttributeError(
             "'%(type_name)s' object has no attribute '%(field_name)s'" % {
                 'type_name': type_name(owner),
                 'field_name': self._field_name
             })
Ejemplo n.º 5
0
    def __init__(self, field_type=None, field_name=None):
        """
        Construct a new field

        :param field_type: type which field would store. If set to None it could
            store any type.

        :param field_name: name of field in mongo document. If set to None it
            would be the same as field name. Any two field in one model can't
            have the same `field_name`.
        """
        if field_type is not None and not isinstance(field_type, basestring) and \
           not check_mongo_type(field_type):
            raise TypeError("Invalid mongo type %(type)s" % {'type': type_name(field_type)})

        self._field_type = field_type
        self._field_name = field_name
Ejemplo n.º 6
0
    def __init__(self, field_type=None, field_name=None):
        """
        Construct a new field

        :param field_type: type which field would store. If set to None it could
            store any type.

        :param field_name: name of field in mongo document. If set to None it
            would be the same as field name. Any two field in one model can't
            have the same `field_name`.
        """
        if field_type is not None and not isinstance(field_type, basestring) and \
           not check_mongo_type(field_type):
            raise TypeError("Invalid mongo type %(type)s" %
                            {'type': type_name(field_type)})

        self._field_type = field_type
        self._field_name = field_name
Ejemplo n.º 7
0
 def __repr__(self):
     params = u" ".join((key + u"=" + repr(value) for key, value in self.viewitems()))
     return u"<%(class_name)s %(params)s>" % {"class_name": type_name(self), "params": params}
Ejemplo n.º 8
0
 def test_type_name(self):
     self.assertEqual("unicode", utils.type_name(u"some_str"))
     self.assertEqual("unicode", utils.type_name(unicode))
     self.assertEqual("object", utils.type_name(object()))
     self.assertEqual("object", utils.type_name(object))
Ejemplo n.º 9
0
 def cast_to_class(cls, value):
     if not isinstance(value, (list, )):
         raise TypeError("Value should be list, not %(type)s" %
                         {'type': type_name(value)})
     item_generator = (cls.cast_inner_item(item) for item in value)
     return cls(item_generator)
Ejemplo n.º 10
0
 def cast_to_class(cls, value):
     if not isinstance(value, (list, )):
         raise TypeError("Value should be list, not %(type)s" % {'type': type_name(value)})
     item_generator = (cls.cast_inner_item(item) for item in value)
     return cls(item_generator)