PaferaPy Async 0.1
ASGI framework focused on simplicity and efficiency
|
Base class for all database models. More...
Public Member Functions | |
def | __cmp__ (self, o) |
Comparing means simply subracting the database ids. More... | |
def | __eq__ (self, o) |
Two objects are equivalent if their models are the same and their IDs are the same. More... | |
def | __hash__ (self) |
We take the easy route where the hash for an object is just its database ID. More... | |
def | __init__ (self) |
Initialize all fields at creation like a good programmer should. More... | |
def | __repr__ (self) |
Simply outputs the toJSON() function with the model name. More... | |
def | __str__ (self) |
Simply calls the toJSON() function. More... | |
def | CheckPassword (self, field, password) |
This special function checks to see if the password matches the hash stored in the field. More... | |
def | GetACL (self, db) |
Since we store ACLs as a database lookup, be sure to use these getters and setters if you plan on using ACLs. More... | |
def | HasSameValues (self, o) |
While operator = only checks class and ids, this checks every field to see if two objects or an object and a dict have the same values. More... | |
def | OffsetTime (self, timeoffset) |
Change all datetime fields to the new time offset. More... | |
def | Set (self, **kwargs) |
We use this method instead of direct attribute access in order to keep track of what values have been changed. More... | |
def | SetAccess (self, access) |
Special security functions that are useful only if you have enabled security in _dbflags for the model. More... | |
def | SetACL (self, db, acl) |
ACLs in Pafera are defined as a set of rules similar to cascading style sheets. More... | |
def | SetGroup (self, groupid) |
Special security functions that are useful only if you have enabled security in _dbflags for the model. More... | |
def | SetOwner (self, ownerid) |
Special security functions that are useful only if you have enabled security in _dbflags for the model. More... | |
def | SetPassword (self, field, password) |
This special function hashes the password before saving the field. More... | |
def | ToJSON (self, fields='') |
Converts this object into a format suitable for inclusion in JSON. More... | |
def | UpdateFields (self, fieldnames) |
This is a convenience method to update fields without going through the Set() method. More... | |
Public Attributes | |
d | |
dbaccess | |
dbacl | |
dbaclid | |
dbgroup | |
dbowner | |
id | |
Static Public Attributes | |
list | SECURE_FIELDS |
Base class for all database models.
Derived classes should add
_dbfields List of all model fields _dbindexes List of indexes to add to the database _dblinks List of linked objects for the database model manager _dbdisplay List of default fields to display for the database model manager _dbflags Enable security, tracking changes, and tracking changed values
Definition at line 20 of file modelbase.py.
def pafera.modelbase.ModelBase.__init__ | ( | self | ) |
Initialize all fields at creation like a good programmer should.
Reimplemented in learn.answer.learn_answer, learn.card.learn_card, learn.challenge.learn_challenge, learn.challengeresult.learn_challengeresult, learn.classgrade.learn_classgrade, learn.problem.learn_problem, learn.school.learn_school, learn.schooladministrator.learn_schooladministrator, learn.schoolclass.learn_schoolclass, learn.schoolsystemadministrator.learn_schoolsystemadministrator, learn.student.learn_student, learn.studylist.learn_studylist, learn.teacher.learn_teacher, system.file.system_file, system.group.system_group, system.loginattempt.system_loginattempt, system.newuser.system_newuser, system.page.system_pagefragment, system.page.system_page, system.session.system_useragent, system.session.system_session, and system.user.system_user.
Definition at line 41 of file modelbase.py.
def pafera.modelbase.ModelBase.__cmp__ | ( | self, | |
o | |||
) |
Comparing means simply subracting the database ids.
Of course, this only works if you use integer IDs.
Definition at line 73 of file modelbase.py.
def pafera.modelbase.ModelBase.__eq__ | ( | self, | |
o | |||
) |
Two objects are equivalent if their models are the same and their IDs are the same.
Definition at line 66 of file modelbase.py.
def pafera.modelbase.ModelBase.__hash__ | ( | self | ) |
We take the easy route where the hash for an object is just its database ID.
Definition at line 59 of file modelbase.py.
def pafera.modelbase.ModelBase.__repr__ | ( | self | ) |
Simply outputs the toJSON() function with the model name.
Definition at line 86 of file modelbase.py.
def pafera.modelbase.ModelBase.__str__ | ( | self | ) |
Simply calls the toJSON() function.
Definition at line 80 of file modelbase.py.
def pafera.modelbase.ModelBase.CheckPassword | ( | self, | |
field, | |||
password | |||
) |
This special function checks to see if the password matches the hash stored in the field.
Definition at line 224 of file modelbase.py.
def pafera.modelbase.ModelBase.GetACL | ( | self, | |
db | |||
) |
Since we store ACLs as a database lookup, be sure to use these getters and setters if you plan on using ACLs.
Definition at line 289 of file modelbase.py.
def pafera.modelbase.ModelBase.HasSameValues | ( | self, | |
o | |||
) |
While operator = only checks class and ids, this checks every field to see if two objects or an object and a dict have the same values.
Handy for implementing copy-on-change systems
Definition at line 92 of file modelbase.py.
def pafera.modelbase.ModelBase.OffsetTime | ( | self, | |
timeoffset | |||
) |
Change all datetime fields to the new time offset.
Useful for switching between local and GMT times.
Definition at line 200 of file modelbase.py.
def pafera.modelbase.ModelBase.Set | ( | self, | |
** | kwargs | ||
) |
We use this method instead of direct attribute access in order to keep track of what values have been changed.
Only updated values are saved to the database, increasing efficiency and output.
The special field _updatechanged allows initialization of values without triggering changed fields. It's used by the library itself to turn database rows into initialized objects. Set it to 0 if you want to disable tracking, otherwise the default behavior will be changed.
Definition at line 115 of file modelbase.py.
def pafera.modelbase.ModelBase.SetAccess | ( | self, | |
access | |||
) |
Special security functions that are useful only if you have enabled security in _dbflags for the model.
Definition at line 282 of file modelbase.py.
def pafera.modelbase.ModelBase.SetACL | ( | self, | |
db, | |||
acl | |||
) |
ACLs in Pafera are defined as a set of rules similar to cascading style sheets.
The default access for the model comes first, then is overridden by group access, then overridden by user access.
Note that for group access, if one group has access, then the values for the other groups are ignored.
Definition at line 304 of file modelbase.py.
def pafera.modelbase.ModelBase.SetGroup | ( | self, | |
groupid | |||
) |
Special security functions that are useful only if you have enabled security in _dbflags for the model.
Definition at line 275 of file modelbase.py.
def pafera.modelbase.ModelBase.SetOwner | ( | self, | |
ownerid | |||
) |
Special security functions that are useful only if you have enabled security in _dbflags for the model.
Definition at line 268 of file modelbase.py.
def pafera.modelbase.ModelBase.SetPassword | ( | self, | |
field, | |||
password | |||
) |
This special function hashes the password before saving the field.
You should explicitly call this to avoid situations where you're hashing an existing hash instead of the raw password itself.
Definition at line 212 of file modelbase.py.
def pafera.modelbase.ModelBase.ToJSON | ( | self, | |
fields = '' |
|||
) |
Converts this object into a format suitable for inclusion in JSON.
Definition at line 242 of file modelbase.py.
def pafera.modelbase.ModelBase.UpdateFields | ( | self, | |
fieldnames | |||
) |
This is a convenience method to update fields without going through the Set() method.
Useful for working on mutable collections like lists and dicts.
fieldnames should be a list of fields separated by a comma and space as in 'id, name, business'
Definition at line 186 of file modelbase.py.
pafera.modelbase.ModelBase.d |
Definition at line 209 of file modelbase.py.
pafera.modelbase.ModelBase.dbaccess |
Definition at line 286 of file modelbase.py.
pafera.modelbase.ModelBase.dbacl |
Definition at line 299 of file modelbase.py.
pafera.modelbase.ModelBase.dbaclid |
Definition at line 313 of file modelbase.py.
pafera.modelbase.ModelBase.dbgroup |
Definition at line 279 of file modelbase.py.
pafera.modelbase.ModelBase.dbowner |
Definition at line 272 of file modelbase.py.
pafera.modelbase.ModelBase.id |
Definition at line 70 of file modelbase.py.
|
static |
Definition at line 32 of file modelbase.py.