def initialise(application): sysinfo = application.predefine.sysinfo sysinfo("public", True, "Allow unregistered users to use the application") sysinfo("name", 'Reformed Application', "Name of the application") database = application.database entity('ticket', database, Text("title", mandatory = True), Text("summary", length = 4000), LookupId("severity", "code", filter_field = "code_type"), LookupId("priority", "code", filter_field = "code_type"), DateTime("complete_by"), Boolean("accepted"), Created("created_date"), CreatedBy("created_by"), title_field = "title", summary_fields = "summary", valid_info_tables = "comment role", ) info_table("comment", database, ## notes for each user Created("created_date"), CreatedBy("created_by"), Text("note", length = 4000), ) relation("involvement", database, LookupId("role", "code", filter_field = "code_type"), Created("created_date"), CreatedBy("created_by"), primary_entities = "ticket", secondary_entities = "user usergroup", table_type = "system", ) info_table("role", database, ## notes for each user Text("name", mandatory = True), Text("desctiption", length = 2000), table_type = "system", ) database.persist()
def initialise(application): sysinfo = application.predefine.sysinfo sysinfo("public", True, "Allow unregistered users to use the application") sysinfo("name", 'Mike Application', "Name of the application") database = application.database entity('volunter', database, Text('name'), Text('notes', length = 2000), title_field = "name" ) database.persist()
def get_db_parse_info(self): parse_banks_select = database.entity(ParseBanks) parse_banks = self.db_manager.select_all(parse_banks_select) parse_banks_dict = {} for parse_bank in parse_banks: parse_components_select = database.entity(ParseComponents) parse_components_select.add_where( ParseComponents.parse_id, parse_bank.get(ParseBanks.parse_id)) parse_components = self.db_manager.select_all( parse_components_select) parse_banks_dict[parse_bank] = parse_components return parse_banks_dict
def initialise(application): sysinfo = application.predefine.sysinfo sysinfo("public", True, "Allow unregistered users to use the application") sysinfo("name", 'Reformed Application', "Name of the application") database = application.database table('search_info', database, Integer('_core_id'), Integer('table'), Integer('field'), Integer('original_id'), Text('value', length = 1000), Index('main_query', "_core_id, table, field, original_id"), modified_date = False, modified_by = False, version = False, ) table('search_pending', database, Integer('_core_id'), Created('created'), modified_date = False, modified_by = False, version = False, ) info_table('summary_info', database, Text('table_name'), Text('name'), Text('display_name'), Integer('original_id'), Text('value', length = 1000)) info_table('note', database, Text('note', length = 1000), ) entity('people', database, Text('name', generator = dict(name = 'full_name')), Text('preferred_name'), Text('alterative_name'), Text('salutation'), LookupId('gender', "code", filter_field = "code_type"), LookupId('source'), Date('dob', generator = dict(name = 'dob')), Created('created'), CreatedBy('created_by'), Thumb('image'), Event('new change', CopyValue('image', 'primary_entity._core_entity.thumb')), Event('new change delete', UpdateSearch(['name']) ), Event('new change delete', UpdateSearch(['dob'], "datetime") ), title_field = 'name', default_node = 'new_person.People', valid_info_tables = "communication summary_info note" ) table("source", database, Text("code", length = 200), Text("code_desc", length = 400), Created('created'), CreatedBy('created_by'), lookup = True, ) info_table('communication', database, Text('communication_type'), DateTime('defaulted_date'), Boolean('active', default = True), Text('description', length = 1000), Index('latest_com', "_core_id, defaulted_date, active"), Created('created'), CreatedBy('created_by'), ) table('telephone', database, Integer("_core_id", mandatory = True), ForeignKey('communication_id', 'communication'), Text('number', generator = dict(name = 'phone')), Event('new', AddCommunication()), Event('new change delete', UpdateCommunicationInfo(['number'])), Event('new change delete', UpdateSearch(['number'], type = 'only_numbers')), table_class = 'communication', ) table('email', database, Integer("_core_id", mandatory = True), ForeignKey('communication_id', 'communication'), Email('email', mandatory = True), Event('new', AddCommunication()), Event('new change delete', UpdateCommunicationInfo(['email'])), Event('new change delete', UpdateSearch(['email'])), table_class = 'communication', ) table('address', database, Integer("_core_id", mandatory = True), ForeignKey('communication_id', 'communication'), Text('address_line_1', generator = dict(name = 'road')), Text('address_line_2'), Text('address_line_3'), Text('address_line_4'), Text('town', generator = dict(name = 'town')), Text('country'), Text('postcode', generator = dict(name = 'postcode')), Boolean('gone_away'), Event('new', AddCommunication()), Event('new change delete', UpdateCommunicationInfo(['address_line_1', 'town', 'postcode'])), Event('new change delete', UpdateSearch(['postcode'], type = "upper_no_space")), table_class = 'communication', ) database.persist()
from web.global_session import global_session d = global_session.database entity("people",d, Text("name", mandatory = True, length = 50), DateTime("dob"), Boolean("active"), Address("supporter_address"), OneToMany("email","email", order_by = "email", eager = True), OneToMany("donkey_sponsorship", "donkey_sponsorship", many_side_not_null = False ), summary_fields = "name,address_line_1,postcode" ) table("email",d, Email("email") ) entity("user",d,
def parse_emails(self): emails = self.get_unread_emails() if len(emails) > 0: email_types_select = database.entity(EmailTypes) email_types = self.db_manager.select_all(email_types_select) db_parse_dict = self.get_db_parse_info() db_accounts = self.get_db_accounts() for email in emails: found_match = False for bank, bank_info in db_parse_dict.items(): email_text = email.text DetailsTable = None transfer_type_id = None for email_type in email_types: if bank.get( ParseBanks.email_type_id) == email_type.get( EmailTypes.email_type_id): if email_type.get(EmailTypes.is_email_html): email_text = email.html transfer_type_id = email_type.get( EmailTypes.transfer_type_id) if email_type.get(EmailTypes.table ) == Transactions.table_name(): DetailsTable = Transactions elif email_type.get( EmailTypes.table) == Balances.table_name(): DetailsTable = Balances elif email_type.get(EmailTypes.table ) == Transfers.table_name(): DetailsTable = Transfers break account = None if bank.get(ParseBanks.identifier) in email_text: found_match = True self.logger.info("Found email matching bank with ID " + str(bank.get(ParseBanks.bank_id)) + ".") if DetailsTable is not None: db_email = database.entity(Emails) for component in bank_info: if component.get( ParseComponents.name ) == Accounts.account_number.value: last_four = self.get_email_component( email_text, component) for db_account in db_accounts: if db_account.get( Accounts.account_number ) == last_four: account = db_account db_email.set( Emails.account_id, db_account.get( Accounts.account_id)) break break modified_date = email.date.split(' -', 1)[0].split( ' +', 1)[0] email_date_time = datetime.datetime.strptime( modified_date, bank.get(ParseBanks.date_format)) if bank.get(ParseBanks.localize_date_time): email_date_time = email_date_time.replace( tzinfo=datetime.timezone.utc).astimezone( tz=None) db_email.set(Emails.date_time, email_date_time) db_email.set(Emails.email_type_id, bank.get(ParseBanks.email_type_id)) db_email_details = database.entity(DetailsTable) if DetailsTable is Transfers: db_email_details.set( Transfers.transfer_type_id, transfer_type_id) limit = None for component in bank_info: if component.get( ParseComponents.name ) == Accounts.credit_limit.value: limit = self.get_email_component( email_text, component) else: for col in DetailsTable: if component.get(ParseComponents.name ) == col.value: val = self.get_email_component( email_text, component) db_email_details.set(col, val) if limit is not None and account is not None: limit += db_email_details.get( DetailsTable.balance) limit = int(round(float(limit))) account.set(Accounts.credit_limit, limit) account.add_where( Accounts.account_id, account.get(Accounts.account_id)) self.db_manager.update(account) parsed = True for col in Emails: if db_email.get( col ) is None and col.value in Emails.not_nulls(): parsed = False for col in DetailsTable: if db_email_details.get(col) is None and \ col.value != Emails.email_id.value and \ col.value in DetailsTable.not_nulls(): parsed = False if parsed: db_email_id = self.db_manager.insert( db_email, False) db_email_details.set(DetailsTable.email_id, db_email_id) self.db_manager.insert(db_email_details) self.email_manager.move_email(email) else: self.email_manager.move_email(email, True) if not found_match: self.email_manager.move_email(email, True) self.db_manager.commit()
def get_db_accounts(self): accounts_select = database.entity(Accounts) accounts = self.db_manager.select_all(accounts_select) return accounts
def initialise(application): database = application.database table("_core", database, Text("type"), ForeignKey("primary_entity_id", "_core_entity", ), ForeignKey("secondary_entity_id", "_core_entity", ), modified_by = False, modified_date = False ) table("_core_entity", database, Text("table"), Text("title"), Text("summary"), Integer("thumb"), ModifiedByNoRelation("modified_by"), table_type = "internal", summary = u'The entity table', lookup = True, modified_by = False ) entity("user",database, Text("name"), Boolean("active", default = True, mandatory = True), Boolean("locked", default = False), Text("login_name", mandatory = True), Text("auto_login", length = 100), Password("password"), Email("email"), DateTime("last_logged_in"), Text("notes", length = 4000), Text("about_me", length = 4000), Created("created_date"), CreatedBy("created_by"), UniqueIndex("login_name_index", "login_name"), title_field = 'name', table_type = "system", default_node = 'user.User', ) entity("user_group",database, Text("groupname"), Text("name", mandatory = True), Text("description", length = 200), Text("notes", length = 4000), Boolean("active", default = True, mandatory = True), Integer("access_level", default = 0), default_node = 'user.UserGroup', table_type = "system", title_field = 'name' ) table("user_group_user",database, LookupId("user_id", "user"), LookupId("user_group_id", "user_group"), table_type = "system" ) table("user_group_permission",database, ##TODO Sort out backref problems LookupId("user_group_id", "user_group"), LookupId("permission_id", "permission"), table_type = "system" ) table("permission",database, Text("permission"), Text("name", length = 200), Text("description", length = 4000), Integer("access_level", default = 0), table_type = "system", title_field = 'name' ) table("bookmarks",database, ForeignKey("_core_id", "_core_entity", ), Integer("user_id"), Text("entity_table"), DateTime("accessed_date"), table_type = "system", ) table("code", database, Text("name", mandatory = True), Text("desctiption", length = 2000), LookupTextValidated("code_type", "code_type.code_type"), Boolean("active", default = True), Created("created_date"), CreatedBy("created_by"), lookup = True, table_type = "system", title_field = "name" ) table("code_type", database, Text("code_type", mandatory = True), Text("name", mandatory = True), Text("desctiption", length = 2000), Created("created_date"), CreatedBy("created_by"), table_type = "system", ) ## application user tables entity("page",database, Text("page", length = 50, mandatory = True), Text("title", length = 200, mandatory = True), Text("body", length = 8000), default_node = 'search.Page', title_field = "title", table_type = "system", ) entity('upload', database, Text("filename", mandatory = True), Text("category"), Text("title"), Text("path"), Text("mimetype"), Integer("size"), Boolean("thumb", default = False), Created("created_date"), CreatedBy("created_by"), title_field = "filename", summary_fields = "filename", table_type = "system", ) database.persist() # permission # add admin user # this is a special case as no other users should be auto created data = dict(name = u"admin", created_by = 1, _modified_by = 1, active = True, auto_login = authenticate.create_auto_login_id(), password = u"admin") application.predefine.add_data("user", "login_name", u"admin", data) # sys admin user_group application.predefine.permission("SysAdmin", u'System Administrators', u'Administer the system.', 2) application.predefine.user_group(u'SysAdmins', u'System Administrators', u'Full system access', permissions = ['SysAdmin'], access_level = 2) # this is a special case too # make admin a sysadmin data = dict(created_by = 1, _modified_by = 1, user_id = 1, user_group_id = 1,) application.predefine.add_data("user_group_user", "user_id", 1, data)