PaferaPy Async 0.1
ASGI framework focused on simplicity and efficiency
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
pafera.modelbase.ModelBase Class Reference

Base class for all database models. More...

Inheritance diagram for pafera.modelbase.ModelBase:
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 pafera.db.system_acl pafera.db.system_changelog pafera.db.system_config pafera.db.system_objtype pafera.db.system_tag system.file.system_file system.group.system_group system.loginattempt.system_loginattempt system.newuser.system_newuser system.page.system_page system.page.system_pagefragment system.session.system_session system.session.system_useragent system.user.system_user

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

def pafera.modelbase.ModelBase.__init__ (   self)

Member Function Documentation

◆ __cmp__()

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.

◆ __eq__()

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.

◆ __hash__()

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.

◆ __repr__()

def pafera.modelbase.ModelBase.__repr__ (   self)

Simply outputs the toJSON() function with the model name.

Definition at line 86 of file modelbase.py.

◆ __str__()

def pafera.modelbase.ModelBase.__str__ (   self)

Simply calls the toJSON() function.

Definition at line 80 of file modelbase.py.

◆ CheckPassword()

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.

◆ GetACL()

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.

◆ HasSameValues()

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.

◆ OffsetTime()

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.

◆ Set()

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.

◆ SetAccess()

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.

◆ SetACL()

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.

◆ SetGroup()

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.

◆ SetOwner()

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.

◆ SetPassword()

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.

◆ ToJSON()

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.

◆ UpdateFields()

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.

Member Data Documentation

◆ d

pafera.modelbase.ModelBase.d

Definition at line 209 of file modelbase.py.

◆ dbaccess

pafera.modelbase.ModelBase.dbaccess

Definition at line 286 of file modelbase.py.

◆ dbacl

pafera.modelbase.ModelBase.dbacl

Definition at line 299 of file modelbase.py.

◆ dbaclid

pafera.modelbase.ModelBase.dbaclid

Definition at line 313 of file modelbase.py.

◆ dbgroup

pafera.modelbase.ModelBase.dbgroup

Definition at line 279 of file modelbase.py.

◆ dbowner

pafera.modelbase.ModelBase.dbowner

Definition at line 272 of file modelbase.py.

◆ id

pafera.modelbase.ModelBase.id

Definition at line 70 of file modelbase.py.

◆ SECURE_FIELDS

list pafera.modelbase.ModelBase.SECURE_FIELDS
static
Initial value:
= [
'dbowner',
'dbaccess',
'dbgroup',
'dbgroupaccess',
'dbaclid',
]

Definition at line 32 of file modelbase.py.


The documentation for this class was generated from the following file: