Database API¶
JanuaDB¶
- class
janua.db.connection.JanuaDB(januadb_file)[source]¶Janua database instance
__init__(januadb_file)[source]¶Initialize connection to database and create it if it doesn’t exists
Parameters: januadb_file – janua sqlite database file
engine= None¶Sqlalchemy engine
session= None¶Thread-safe sqlalchemy session
commands= None¶Commands database object (
CommandsDB)
contact_notify= None¶Contact notify action database object (
ContactNotifyDB)
contact_group= None¶Contact group database object (
ContactGroupDB)
Authorized group action database object (
AuthorizedGroupDB)
add_entry(obj)[source]¶Add an object entry
Parameters: obj – entry object to add Returns: True if entry was added, False otherwise
ObjectDB¶
ContactDB¶
- class
janua.db.connection.ContactDB(db)[source]¶
add(name, firstname, phone)[source]¶Add a contact
Parameters:
- name – contact name
- firstname – contact firstname
- phone_number – contact phone number
Returns: True if entry was added or False if wasn’t
delete(id)[source]¶Delete a contact
Parameters: id – id primary key Returns: True if entry was deleted or False if wasn’t
get_by_phone(phone)[source]¶Get a Contact entry corresponding to phone number
Returns: a Contact entry object
get_by_group_id(group_id)[source]¶Get all contact entries corresponding to group id
Parameters: group_ids – group_id list Returns: Contact entries object
GroupDB¶
ContactGroupDB¶
AdminDB¶
- class
janua.db.connection.AdminDB(db)[source]¶
has_super_admin()[source]¶Check if there a superadmin entry in database
Returns: True if yes or False if not
get_by_phone(phone_number)[source]¶Get an admin entry by phone number
Parameters: phone_number – admin phone number Returns: an Admin entry object
get_by_login(login)[source]¶Get an admin entry by login
Parameters: phone_number – admin login Returns: an Admin entry object
get_by_mail(mail)[source]¶Get an admin entry by mail
Parameters: phone_number – admin mail Returns: an Admin entry object
add(firstname, name, phone_number, password, email, level, login)[source]¶Add an admin/supervisor
Parameters:
- name – admin name
- firstname – admin firstname
- phone_number – admin phone number
- password – hashed sha password
- email – admin/supervisor email
- level – 1 for admin, 2 for supervisor
- login – user login
Returns: True if entry was added or False if wasn’t
CommandsDB¶
Config¶
- class
janua.db.connection.ConfigDB(db)[source]¶Config database API
add(key, value)[source]¶Add a Config entry object
Parameters:
- key – configuration
- value – configuration value
Returns: True if entry was added or False if wasn’t
ActionDB¶
- class
janua.db.connection.ActionDB(db)[source]¶
add(name, module, description, authentication, enabled, janua_id)[source]¶Add an action
Parameters:
- name – action name
- module – python module namespace of action
- description – action description
- authentication – is action require authentication
- janua_id – action internal id
Returns: True if added, False otherwise
get_by_janua_id(id)[source]¶Get action entry by janua action id
Parameters: id – janua internal id (janua_id) Returns: Action entry object
Get all authorized supervisor action
Parameters: admin_id – admin id Returns: Action entries object
ContactNotifyDB¶
AuthorizedGroupDB¶
SmsDB¶
- class
janua.db.connection.SmsDB(db)[source]¶
add(date, sender, recipient, message, authorized, admin_id, phone_number, status=3, reference=None, slices=1)[source]¶Add a sms log entry
Parameters:
- date – date time
- sender – sender address, name or ip address
- recipient – recipient address or name
- message – message in raw format (mainly for debug purpose)
- authorized – is sender authorized to send SMS to server
- admin_id – admin send message, for received message default to super admin
- phone_number – recipient phone number
- status – sms status
- reference – reference for delivery report
- slices – number of slices (for multi-part SMS)
Returns: True if entry was added or False if wasn’t
get_by_admin(admin_id, startdate=None, enddate=None)[source]¶Get sms log entries by admin
Parameters:
- startdate – get entries from date (datetime argument)
- enddate – get entries to date (datetime argument)
- admin_id – admin identifier
Returns: all Log entry object
get_by_date(startdate=None, enddate=None)[source]¶Get sms log entries
Parameters:
- startdate – get entries from date (datetime argument)
- enddate – get entries to date (datetime argument)
Returns: all Log entry object
get_by_ref_and_phone(ref, phone_number)[source]¶Get sms log entry by recipient phone number and sms reference
Parameters:
- ref – sms reference
- phone_number – recipient phone number
Returns: corresponding sms log entry object
delete(startdate, enddate)[source]¶Delete sms log entries in a date interval
Parameters:
- startdate – delete entries from date (datetime argument)
- enddate – delete entries to date (datetime argument)
Returns: all Log entry object