示例#1
0
文件: document.py 项目: SMAC/smaclib
    def __new__(mcs, name, bases, dct):
        dct['DoesNotExist'] = type('DoesNotExist', (errors.DoesNotExist,),
                                   {})

        # Every document shall have a unique id
        if '_id' not in dct:
            dct['_id'] = fields.ObjectId(required=True)
        elif not isinstance(dct['_id'], fields.Field):
            raise TypeError("Cannot only declare an _id attribute of type " \
                            "mongo.fields.Field.")

        mcs.__collection = None

        collection = dct.get('__collection__')

        if collection is None:
            # Dirty pluralization here
            collection = text.camelcase_to_underscore(name) + 's'

        mcs.__collection__ = collection
        dct['__collection__'] = collection

        return fields.FieldMapper.__new__(mcs, name, bases, dct)
示例#2
0
文件: test_text.py 项目: SMAC/smaclib
 def test_camelcase_to_underscore(self):
     for key, value in self.VALUES:
         self.assertEqual(value, camelcase_to_underscore(key))