コード例 #1
0
ファイル: fields.py プロジェクト: techiev2/mongo-monkey
 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})
コード例 #2
0
ファイル: fields.py プロジェクト: techiev2/mongo-monkey
 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})
コード例 #3
0
ファイル: fields.py プロジェクト: xonatius/mongo-monkey
 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
                 })
コード例 #4
0
ファイル: fields.py プロジェクト: xonatius/mongo-monkey
 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
             })
コード例 #5
0
ファイル: fields.py プロジェクト: techiev2/mongo-monkey
    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
コード例 #6
0
ファイル: fields.py プロジェクト: xonatius/mongo-monkey
    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
コード例 #7
0
ファイル: model.py プロジェクト: techiev2/mongo-monkey
 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}
コード例 #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))
コード例 #9
0
ファイル: data.py プロジェクト: xonatius/mongo-monkey
 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)
コード例 #10
0
ファイル: data.py プロジェクト: techiev2/mongo-monkey
 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)