def create(self, cls, record, user='<STR_LIT>'):
self.validate_record(cls, record)<EOL>record[CREATION_DATE] = record[UPDATE_DATE] = self.nowstr()<EOL>record[CREATOR] = record[UPDATER] = user<EOL>try:<EOL><INDENT>return self.db.insert(cls, record)<EOL><DEDENT>except (psycopg2.IntegrityError, psycopg2.ProgrammingError,<EOL>psycopg2.DataError) as error:<EOL><INDENT>logging.warning("<STR_LIT>".format(<EOL>error.__class__.__name__,<EOL>psycopg2.errorcodes.lookup(error.pgcode), error.pgerror))<EOL>if error.pgcode == psycopg2.errorcodes.UNIQUE_VIOLATION:<EOL><INDENT>raise KeyError('<STR_LIT>'.format(<EOL>cls, record[ID]))<EOL><DEDENT>elif error.pgcode == psycopg2.errorcodes.UNDEFINED_COLUMN:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(<EOL>psycopg2.errorcodes.lookup(error.pgcode)))<EOL><DEDENT><DEDENT>
Persist new record

        >>> s = teststore()
        >>> s.create('tstoretest', {'id': '1', 'name': 'Toto'})
        >>> s.create('tstoretest', {'id': '2', 'name': 'Tata'}, user='jane')
        >>> r = s.get('tstoretest', '2')
        >>> r[CREATOR]
        'jane'
        >>> s.create('badcls', {'id': '1', 'name': 'Toto'})
        Traceback (most recent call last):
            ...
        ValueError: Unsupported record type "badcls"
        >>> s.create('tstoretest', {'id': '1', 'name': 'Joe'})
        Traceback (most recent call last):
            ...
        KeyError: 'There is already a record for tstoretest/1'
        >>> s.create('tstoretest', {'id': '2', 'badfield': 'Joe'})
        Traceback (most recent call last):
            ...
        ValueError: Undefined field
        >>> s.create('tstoretest', {'id': '2', 'age': 'bad'})
        Traceback (most recent call last):
            ...
        ValueError: Bad record (INVALID_TEXT_REPRESENTATION)