Add UUID to each congregation and group in the database by creating a UUID getter/setter attribute with associated methods
Add UUID to each congregation & group in database by creating a UUID getter/setter attribute with associated methods.
The getter can be simple--just get the value out of the UUID column in the database. The setter needs to be more complex - either create a new UUID, or if the data seems similar enough to an existing congregations or group, either invalidate the data, abort the write operation, and notify the user that this appears to be a duplicate, or trust the user after the user states it is not a duplicate, and go ahead and create a new record in the database.
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- Diana Graham
- Definition:
- New
- Series goal:
- Accepted for trunk
- Implementation:
- Implemented
- Milestone target:
- 0.3.5
- Started by
- Douglas Huston
- Completed by
- Douglas Huston
Related branches
Related bugs
Sprints
Whiteboard
Here is the standard way to define getters & setters in SQLAlchemy model objects: http://
Use the rest of the comments below as supplementary documentation to the example code given above.
-------
This is somewhat advanced Python programming--using getters and setters assumes you understand the simpler "normal" way to get and set the value of an attribute in Python. E.g.,
# this gets the value of x.a into x.b, and sets the value of x.b equal to the value of x.a
x.b = x.a
For more see:
http://
http://
http://
Here's how to create a custom getter & setter as a Python object property:
I prefer this way of doing it, because both its definition & usage are simpler:
class D(object):
x = 2
y = 3
z = 4
def __setattr__(self, name, val):
if name != 'x':
else:
print "%s is read only" % (name)
BUT, probably __setattr__() is already defined in the base class which the model classes extend named DeclarativeBase. If that is the case, we might not be able to overwrite __setattr__() with a new method definition and still be able to use the model classes. In that case we should use this way of doing it, which is probably better anyway since we'll have to deal with each property/column's data differently:
class C(object):
def __init__(self):
self._x = None
def getx(self):
return self._x
def setx(self, value):
self._x = value
def delx(self):
del self._x
x = property(getx, setx, delx, "I'm the 'x' property.")
It may be a challenge figuring out how to use this pattern in the context of a SQLAlchemy declarative table class, but there might be some examples out there of how to do it: maybe google "sqlalchemy declarative python properties". Here's some help on how to use getters & setters in SQLAlchemy: http://
Also, it looks like there is a simpler syntax using function decorators that has been accepted into Python 2.6, but I don't know how to use it yet: http://