Example #1
0
class RecordVersion(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    reference = db.Column(db.String(), unique=True, index=True)
    header = db.Column(db.Text())
    data = db.Column(db.Text())
    api_version = db.Column(db.String())
    version = db.Column(db.Integer())
    previous_version_key = db.Column(db.String())
    previous_version_id = db.Column(db.Integer(),
                                    db.ForeignKey('record_version.id'))
    creation_date = db.Column(db.DateTime(), default=datetime.datetime.utcnow)
    update_date = db.Column(db.DateTime(), default=datetime.datetime.utcnow)
    access_date = db.Column(db.DateTime(), default=datetime.datetime.utcnow)

    record_id = db.Column(db.Integer(),
                          db.ForeignKey('record.id'),
                          nullable=False)

    record = db.relationship('Record',
                             backref=db.backref('record_versions',
                                                order_by=id,
                                                cascade='all,delete'))

    def update(self, someData):
        app.logger.debug(someData)
        recordVersionData = someData['currentRecordVersion']
        self.reference = recordVersionData['reference']
        self.data = recordVersionData['data']
        self.api_version = recordVersionData['version']
        self.version = self.record.version
        self.previous_version_key = recordVersionData['previousVersionKey']
        self.update_date = datetime.datetime.utcnow()

        self.record.update(someData['record'], self)
Example #2
0
class RecordVersion(db.Model):

    """
    Model a RecordVersion.

    RecordVersion store attributes associated with a specific version of a
    record.
    """

    id = db.Column(db.Integer(), primary_key=True)
    reference = db.Column(db.String(255), unique=True, index=True)
    header = db.Column(db.Text())
    data = db.Column(db.Text())
    api_version = db.Column(db.String(255))
    version = db.Column(db.Integer())
    previous_version_key = db.Column(db.String(255))
    previous_version_id = db.Column(db.Integer(),
                                    db.ForeignKey('record_version.id'))
    creation_date = db.Column(db.DateTime())
    update_date = db.Column(db.DateTime())
    access_date = db.Column(db.DateTime())

    record_id = db.Column(db.Integer(),
                          db.ForeignKey('record.id'),
                          nullable=False)

    record = db.relationship('Record',
                             backref=db.backref('record_versions',
                                                order_by=id,
                                                cascade='all,delete'))

    def __init__(self, record=None):
        """Initialize a record version."""
        if record:
            self.record = record
            self.record_id = record.id
        self.creation_date = datetime.datetime.utcnow()

    def update(self, someData):
        """Update a record version."""
        app.logger.debug(someData)
        recordVersionData = someData['currentRecordVersion']
        self.reference = recordVersionData['reference']
        self.data = recordVersionData['data']
        self.api_version = recordVersionData['version']
        self.version = self.record.version
        self.previous_version_key = recordVersionData['previousVersionKey']
        self.update_date = datetime.datetime.utcnow()
        self.access_date = datetime.datetime.utcnow()

        self.record.update(someData['record'], self)

    def access(self):
        self.access_date = datetime.datetime.now()