desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Ensure Job Titles are not Org-specific unless configured to be so'
@staticmethod def hrm_job_title_onvalidation(form):
if (not current.deployment_settings.get_hrm_org_dependent_job_titles()): form.vars['organisation_id'] = None
'Record creation post-processing If the job title is the main, set the human_resource.job_title_id accordingly'
@staticmethod def hrm_job_title_human_resource_onaccept(form):
vars = form.vars if vars.main: db = current.db ltable = db.hrm_job_title_human_resource record = db((ltable.id == vars.id)).select(ltable.human_resource_id, ltable.job_title_id, limitby=(0, 1)).first() htable = db.hrm_human_resource db((htable.id == record.human_resource_...
'JSON search method for S3HumanResourceAutocompleteWidget and S3AddPersonWidget2 - full name search - include Organisation & Job Role in the output'
@staticmethod def hrm_search_ac(r, **attr):
resource = r.resource response = current.response resource.add_filter(response.s3.filter) _vars = current.request.get_vars value = (_vars.term or _vars.value or _vars.q or None) if (not value): output = current.xml.json_message(False, 400, 'No value provided!') raise HTTP(4...
'JSON lookup method for S3AddPersonWidget2'
@staticmethod def hrm_lookup(r, **attr):
id = r.id if (not id): output = current.xml.json_message(False, 400, 'No id provided!') raise HTTP(400, body=output) db = current.db s3db = current.s3db settings = current.deployment_settings request_dob = settings.get_pr_request_dob() request_gender = settings.get_pr_r...
'On-delete routine for HR records'
@staticmethod def hrm_human_resource_ondelete(row):
db = current.db htable = db.hrm_human_resource if (row and ('id' in row)): record = db((htable.id == row.id)).select(htable.deleted, htable.deleted_fk, htable.person_id, limitby=(0, 1)).first() else: return if record.deleted: try: fk = json.loads(record.deleted_fk...
'Update the Human Resource record with the site_id'
@staticmethod def hrm_human_resource_site_onaccept(form):
try: form_vars = form.vars except: _id = form.id delete = True else: _id = form_vars.id delete = False db = current.db ltable = db.hrm_human_resource_site table = db.hrm_human_resource if delete: record = db((ltable.id == _id)).select(ltable.de...
'Constructor'
def __init__(self, lookup=None):
if (lookup is None): raise SyntaxError('must specify a lookup table') fields = ('name', 'organisation_id') super(hrm_OrgSpecificTypeRepresent, self).__init__(lookup=lookup, fields=fields)
'Custom rows lookup @param key: the key Field @param values: the values @param fields: unused (retained for API compatibility)'
def lookup_rows(self, key, values, fields=[]):
s3db = current.s3db table = self.table otable = s3db.org_organisation left = otable.on((otable.id == table.organisation_id)) if (len(values) == 1): query = (key == values[0]) else: query = key.belongs(values) rows = current.db(query).select(table.id, table.name, otable.id, ot...
'Represent a row @param row: the Row'
def represent_row(self, row):
try: name = row[self.tablename].name except AttributeError: return row.name try: organisation = row['org_organisation'] except AttributeError: return name if organisation.acronym: return ('%s (%s)' % (name, organisation.acronym)) elif organisation.name:...
'Return safe defaults in case the model has been deactivated.'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) dummy_listref = S3ReusableField('dummy_id', 'list:reference', readable=False, writable=False) return dict(hrm_course_id=(lambda **attr: dummy('course_id')), hrm_skill_id=(lambda **attr: dummy('skill_id')), hrm_multi_skill_id=(lam...
'Lookup the default skill_type'
@staticmethod def skill_type_default():
if current.deployment_settings.get_hrm_skill_types(): default = None else: db = current.db table = db.hrm_skill_type skill_type = db((table.deleted == False)).select(table.id, limitby=(0, 1)).first() try: default = skill_type.id except: def...
'Define the comment for the HRM Competency Rating widget'
@staticmethod def competency_rating_comment():
T = current.T s3 = current.response.s3 if (current.request.controller == 'vol'): controller = 'vol' else: controller = 'hrm' if current.auth.s3_has_role(current.session.s3.system_roles.ADMIN): label_create = s3.crud_strings['hrm_competency_rating'].label_create commen...
'Ensure that there is a Certificate created for each Course - only called when create_certificates_from_courses == True'
@staticmethod def hrm_course_onaccept(form):
form_vars = form.vars course_id = form_vars.id db = current.db s3db = current.s3db ltable = s3db.hrm_course_certificate exists = db((ltable.course_id == course_id)).select(ltable.id, limitby=(0, 1)) if (not exists): name = form_vars.get('name') if (not name): tabl...
'Ensure that Skills are Populated from Certifications - called both onaccept & ondelete'
@staticmethod def hrm_certification_onaccept(record):
try: certification_id = record.vars.id except: certification_id = record.id db = current.db table = db.hrm_certification data = table((table.id == certification_id)) try: if data.deleted: deleted_fk = json.loads(record.deleted_fk) person_id = delet...
'This callback will be called when importing records it will look to see if the record being imported is a duplicate. @param item: An S3ImportItem object which includes all the details of the record being imported If the record is a duplicate then it will set the item method to update Rules for finding a duplicate: - L...
@staticmethod def hrm_competency_rating_duplicate(item):
name = item.data.get('name') skill = False for citem in item.components: if (citem.tablename == 'hrm_skill_type'): cdata = citem.data if ('name' in cdata): skill = cdata.name if (skill == False): return table = item.table stable = current.s...
'File representation'
@staticmethod def hrm_training_file_represent(file):
if file: try: filename = current.db.hrm_training.file.retrieve(file)[0] except IOError: return current.T('File not found') else: return A(filename, _href=URL(c='default', f='download', args=[file])) else: return current.messages['NONE']
'Set the training_event realm entity to the root Org of the Site'
@staticmethod def hrm_training_event_realm_entity(table, record):
db = current.db stable = db.org_site query = (stable.site_id == record.site_id) if current.deployment_settings.get_org_branches(): site = db(query).select(stable.organisation_id, limitby=(0, 1)).first() if site: org_id = site.organisation_id root_org = current.cac...
'Link Appraisal to Assignment'
@staticmethod def hrm_appraisal_create_onaccept(form):
mission_id = current.request.get_vars.get('mission_id', None) if (not mission_id): return id = form.vars.id db = current.db s3db = current.s3db atable = s3db.deploy_assignment hatable = db.hrm_appraisal hrtable = db.hrm_human_resource query = ((((hatable.id == id) & (hrtable....
'Set the doc_id to that of the HRM, so that it also appears there'
@staticmethod def hrm_appraisal_document_onaccept(form):
db = current.db s3db = current.s3db atable = db.hrm_appraisal ltable = db.hrm_appraisal_document htable = s3db.hrm_human_resource query = ((((ltable.id == form.vars.id) & (ltable.appraisal_id == atable.id)) & (atable.person_id == htable.person_id)) & (htable.deleted != False)) row = db(query...
'@param component: the Component in which to create records @param types: a list of types to pick from: Staff, Volunteers, Deployables @param next_tab: the component/method to redirect to after assigning'
def __init__(self, component, next_tab='human_resource', types=None):
self.component = component self.next_tab = next_tab self.types = types
'Apply method. @param r: the S3Request @param attr: controller options for this request'
def apply_method(self, r, **attr):
component = self.component components = r.resource.components for c in components: if (c == component): component = components[c] break try: if component.link: component = component.link except: current.log.error('Invalid Component!') ...
'Constructor @param show_link: whether to add a URL to representations'
def __init__(self, show_link=False):
super(hrm_HumanResourceRepresent, self).__init__(lookup='hrm_human_resource', show_link=show_link) self.job_title_represent = S3Represent(lookup='hrm_job_title') self.types = {}
'Represent a (key, value) as hypertext link @param k: the key (hrm_human_resource.id) @param v: the representation of the key @param row: the row with this key (unused here)'
def link(self, k, v, row=None):
types = self.types if (types.get(k) == 1): url = URL(c='hrm', f='staff', args=[k]) else: url = URL(c='vol', f='volunteer', args=[k]) return A(v, _href=url)
'Custom rows lookup @param key: the key Field @param values: the values @param fields: unused (retained for API compatibility)'
def lookup_rows(self, key, values, fields=[]):
s3db = current.s3db htable = s3db.hrm_human_resource ptable = s3db.pr_person left = ptable.on((ptable.id == htable.person_id)) count = len(values) if (count == 1): query = (key == values[0]) else: query = key.belongs(values) rows = current.db(query).select(htable.id, htab...
'Represent a row @param row: the Row'
def represent_row(self, row):
representation = [s3_str(s3_fullname(row.pr_person))] append = representation.append hr = row.hrm_human_resource if hr.job_title_id: append(self.job_title_represent(hr.job_title_id, show_link=False)) if (hr.organisation_id and current.deployment_settings.get_hrm_show_organisation()): ...
'Constructor'
def __init__(self):
super(hrm_TrainingRepresent, self).__init__(lookup='hrm_training')
'Custom rows lookup @param key: the key Field @param values: the values @param fields: unused (retained for API compatibility)'
def lookup_rows(self, key, values, fields=[]):
ttable = self.table ctable = current.s3db.hrm_course left = [ctable.on((ctable.id == ttable.course_id))] if (len(values) == 1): query = (key == values[0]) else: query = key.belongs(values) rows = current.db(query).select(ttable.id, ctable.name, left=left) self.queries += 1 ...
'Constructor'
def __init__(self):
super(hrm_TrainingEventRepresent, self).__init__(lookup='hrm_training_event')
'Custom rows lookup @param key: the key Field @param values: the values @param fields: unused (retained for API compatibility) @param pe_id: whether to include pe_id in the output rows (True when called from pr_PersonEntityRepresent)'
def lookup_rows(self, key, values, fields=[], pe_id=False):
s3db = current.s3db etable = self.table ctable = s3db.hrm_course stable = s3db.org_site left = [ctable.on((ctable.id == etable.course_id)), stable.on((stable.site_id == etable.site_id))] if (len(values) == 1): query = (key == values[0]) else: query = key.belongs(values) f...
'Represent a row NB This needs to be machine-parseable by training.xsl @param row: the Row'
def represent_row(self, row):
course = row.get('hrm_course') if (not course): return current.messages.UNKNOWN_OPT name = course.get('name') if (not name): name = current.messages.UNKNOWN_OPT representation = [('%s --' % name)] append = representation.append code = course.get('code') if code: ...
'Constructor @param form: widget config to inject at the top of the CV, or a callable to produce such a widget config'
def __init__(self, form=None):
self.form = form
'Entry point for REST API @param r: the S3Request @param attr: controller arguments'
def apply_method(self, r, **attr):
if ((r.name == 'person') and r.id and (not r.component) and (r.representation in ('html', 'aadata'))): T = current.T s3db = current.s3db get_config = s3db.get_config settings = current.deployment_settings tablename = r.tablename if (r.controller == 'vol'): ...
'Constructor @param salary: show a Salary widget @param awards: show an Awards History widget @param disciplinary_record: show a Disciplinary Record widget @param org_experience: show widget with Professional Experience within registered organisations, can be a dict with overrides for widget defaults @param other_exper...
def __init__(self, salary=False, awards=False, disciplinary_record=False, org_experience=False, other_experience=False):
self.salary = salary self.awards = awards self.disciplinary_record = disciplinary_record self.org_experience = org_experience self.other_experience = other_experience
'Entry point for REST API @param r: the S3Request @param attr: controller arguments'
def apply_method(self, r, **attr):
r.customise_resource('hrm_human_resource') if ((r.name == 'person') and r.id and (not r.component) and (r.representation in ('html', 'aadata'))): T = current.T s3db = current.s3db settings = current.deployment_settings tablename = r.tablename if (r.controller == 'vol'): ...
'Return safe defaults in case the model has been deactivated.'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return dict(scenario_scenario_id=(lambda **attr: dummy('scenario_id')))
'Represent a Procurement Plan'
@staticmethod def proc_plan_represent(id, row=None):
if row: table = current.db.proc_plan elif (not id): return current.messages['NONE'] else: db = current.db table = db.proc_plan row = db((table.id == id)).select(table.site_id, table.order_date, limitby=(0, 1)).first() try: return ('%s (%s)' % (table.sit...
'Check CSV file before upload'
@staticmethod def translate_language_onvalidation(form):
import csv T = current.T try: csvfile = form.vars.file.file except: form.errors['file'] = T('No file uploaded.') return try: dialect = csv.Sniffer().sniff(csvfile.read(1024)) except csv.Error: error = T('Error reading file (invalid format...
'Merge the uploaded CSV file with existing language file & mark translation percentages as dirty'
@staticmethod def translate_language_onaccept(form):
import csv import os from ..s3.s3translate import Strings form_vars = form.vars lang_code = form_vars.code csvfilename = os.path.join(current.request.folder, 'uploads', form_vars.file) S = Strings() try: S.write_w2p([csvfilename], lang_code, 'm') except (csv.Error, SyntaxErro...
'Return safe defaults for names in case the model is disabled'
@staticmethod def defaults():
supply_item_id = S3ReusableField('item_id', 'integer', writable=False, readable=False) supply_item_category_id = S3ReusableField('item_category_id', 'integer', writable=False, readable=False) item_id = S3ReusableField('item_entity_id', 'integer', writable=False, readable=False)() item_pack_id = S3Reusab...
'Checks that either a Code OR a Name are entered'
@staticmethod def supply_item_category_onvalidate(form):
if (not (form.vars.code or form.vars.name)): errors = form.errors errors.code = errors.name = current.T('An Item Category must have a Code OR a Name.')
'Adds item quantities together, accounting for different pack quantities. Returned quantity according to pack_quantity_1 Used by controllers/inv.py & modules/s3db/inv.py'
@staticmethod def supply_item_add(quantity_1, pack_quantity_1, quantity_2, pack_quantity_2):
if (pack_quantity_1 == pack_quantity_2): quantity = (quantity_1 + quantity_2) else: quantity = (((quantity_1 * pack_quantity_1) + (quantity_2 * pack_quantity_2)) / pack_quantity_1) return quantity
'Represent an item entity in option fields or list views - unused, we use VirtualField instead @ToDo: Migrate to S3Represent'
@staticmethod def item_represent(id):
if (not id): return current.messages['NONE'] db = current.db if (isinstance(id, Row) and ('instance_type' in id)): item = id instance_type = item.instance_type else: item_table = db.supply_item_entity item = db((item_table._id == id)).select(item_table.instance_ty...
'Callback function used to look for duplicates during the import process @param item: the S3ImportItem to check'
@staticmethod def supply_item_duplicate(item):
data = item.data code = data.get('code') if code: table = item.table query = ((table.deleted != True) & (table.code.lower() == code.lower())) duplicate = current.db(query).select(table.id, limitby=(0, 1)).first() if duplicate: item.id = duplicate.id it...
'Callback function used to look for duplicates during the import process @param item: the S3ImportItem to check'
@staticmethod def supply_item_category_duplicate(item):
data = item.data table = item.table query = (table.deleted != True) name = data.get('name') if name: query &= (table.name.lower() == name.lower()) code = data.get('code') if code: query &= (table.code.lower() == code.lower()) catalog_id = data.get('catalog_id') if cat...
'Callback function used to look for duplicates during the import process @param item: the S3ImportItem to check'
@staticmethod def supply_catalog_item_duplicate(item):
data = item.data table = item.table query = (table.deleted != True) item_id = data.get('item_id') if item_id: query &= (table.item_id == item_id) catalog_id = data.get('catalog_id') if catalog_id: query &= (table.catalog_id == catalog_id) item_category_id = data.get('item...
'Callback function used to look for duplicates during the import process @param item: the S3ImportItem to check'
@staticmethod def supply_item_pack_duplicate(item):
data = item.data table = item.table query = (table.deleted != True) name = data.get('name') if name: query &= (table.name.lower() == name.lower()) item_id = data.get('item_id') if item_id: query &= (table.item_id == item_id) quantity = data.get('quantity') if quantity...
'Create a catalog_item for this item Update the UM (Unit of Measure) in the supply_item_pack table'
@staticmethod def supply_item_onaccept(form):
db = current.db vars = form.vars item_id = vars.id catalog_id = vars.catalog_id catalog_item_id = None citable = db.supply_catalog_item query = ((citable.item_id == item_id) & (citable.deleted == False)) rows = db(citable).select(citable.id) if (not len(rows)): catalog_item_i...
'Safe defaults for names in case the module is disabled'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return {'supply_distribution_id': (lambda name='distribution_id', **attr: dummy(name, **attr))}
'Update supply_distribution_item name from supply_item_id'
@staticmethod def supply_distribution_item_onaccept(form):
db = current.db dtable = db.supply_distribution_item ltable = db.supply_item record_id = form.vars.id query = ((dtable.id == record_id) & (ltable.id == dtable.item_id)) item = db(query).select(dtable.name, ltable.name, limitby=(0, 1)).first() if (item and (not item[dtable.name])): db...
'Set supply_distribution location, start_date and end_date from activity This is for when the data is created after the project_activity - CSV imports into project_activity - Inline forms in project_activity'
@staticmethod def supply_distribution_onaccept(form):
db = current.db dtable = db.supply_distribution record_id = form.vars.id record = db((dtable.id == record_id)).select(dtable.activity_id, dtable.location_id, dtable.date, dtable.end_date, limitby=(0, 1)).first() try: location_id = record.location_id start_date = record.date e...
'Virtual field for the supply_distribution table'
@staticmethod def supply_distribution_year(row):
if hasattr(row, 'supply_distribution'): row = row.supply_distribution try: date = row.date except AttributeError: date = None try: end_date = row.end_date except AttributeError: end_date = None if ((not date) and (not end_date)): return [] elif...
'Custom lookup method for item rows, does a left join with the brand. Parameters key and fields are not used, but are kept for API compatibility reasons. @param values: the supply_item IDs'
def custom_lookup_rows(self, key, values, fields=[]):
db = current.db itable = current.s3db.supply_item btable = db.supply_brand left = btable.on((btable.id == itable.brand_id)) qty = len(values) if (qty == 1): query = (itable.id == values[0]) limitby = (0, 1) else: query = itable.id.belongs(values) limitby = (0,...
'Represent a single Row @param row: the supply_item Row'
def represent_row(self, row):
name = row['supply_item.name'] model = row['supply_item.model'] brand = row['supply_brand.name'] fields = [] if name: fields.append(name) if model: fields.append(model) if brand: fields.append(brand) name = ' - '.join(fields) if self.show_um: um ...
'Custom lookup method for item_pack rows, does a left join with the item. @param key: the primary key of the lookup table @param values: the supply_item_pack IDs @param fields: the fields to lookup (unused in this class, retained for API compatibility)'
def lookup_rows(self, key, values, fields=[]):
db = current.db table = self.table itable = db.supply_item qty = len(values) if (qty == 1): query = (key == values[0]) else: query = key.belongs(values) left = itable.on((table.item_id == itable.id)) rows = db(query).select(table.id, table.name, table.quantity, itable.um,...
'Represent a single Row @param row: the Row (usually joined supply_item_pack/supply_item) @todo: implement translate option'
def represent_row(self, row):
try: item = row.supply_item pack = row.supply_item_pack except AttributeError: item = {'um': 'Piece'} pack = row name = pack.get('name') if (not name): return current.messages.UNKNOWN_OPT quantity = pack.get('quantity') if ((quantity == 1) or (quantity is ...
'Custom lookup method for item category rows, does a left join with the parent category. Parameters key and fields are not used, but are kept for API compatibility reasons. @param values: the supply_item_category IDs'
def custom_lookup_rows(self, key, values, fields=[]):
db = current.db table = current.s3db.supply_item_category ctable = db.supply_catalog ptable = db.supply_item_category.with_alias('supply_parent_item_category') gtable = db.supply_item_category.with_alias('supply_grandparent_item_category') left = [ctable.on((ctable.id == table.catalog_id)), ptab...
'Represent a single Row @param row: the supply_item_category Row'
def represent_row(self, row):
use_code = self.use_code name = row['supply_item_category.name'] code = row['supply_item_category.code'] catalog = row['supply_catalog.name'] parent = row['supply_parent_item_category.name'] if use_code: name = code elif (not name): name = code if parent: if use_c...
'Custom lookup method for Patient names @param key: Key for patient table @param values: Patient IDs'
def lookup_rows(self, key, values, fields=[]):
table = self.table ptable = current.s3db.pr_person count = len(values) if (count == 1): query = (key == values[0]) else: query = key.belongs(values) left = ptable.on((table.person_id == ptable.id)) db = current.db rows = db(query).select(patient_patient.id, pr_person.firs...
'Represent a row for a particular patient @param row: patient_patient Row'
def represent_row(self, row):
try: return s3_fullname(row) except: return current.messages.UNKNOWN_OPT
'Return safe defaults for names in case the model is disabled'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return dict(vehicle_vehicle_id=(lambda **attr: dummy('vehicle_id')))
'Safe defaults if module is disabled'
def defaults(self):
return {}
'Safe defaults if module is disabled'
def defaults(self):
return {}
'On-accept routine for dashboard configurations - make sure there is at most one active config for the same controller/function'
@staticmethod def dashboard_onaccept(form):
db = current.db try: record_id = form.vars.id except AttributeError: return table = current.s3db.s3_dashboard query = (table.id == record_id) row = db(query).select(table.id, table.controller, table.function, table.active, limitby=(0, 1)).first() if (not row): return ...
'Generate a random name @return: an 8-character random name'
@staticmethod def random_name():
alpha = 'abcdefghijklmnopqrstuvwxyz' return ''.join((random.choice(alpha) for _ in range(8)))
'Make sure default table names are used only once (even if multiple records are written during the same request cycle, e.g. schema imports) @param name: the name currently being written'
@classmethod def s3_table_name_filter_in(cls, name):
table = current.s3db.s3_table field = table.name if (not name): return field.default elif (name == field.default): field.default = ('%s_%s' % (DYNAMIC_PREFIX, cls.random_name())) return name
'Return a representation function for dynamic table names, renders the table name as a link to the table controller @param c: the controller prefix @param f: the function name @returns: function'
@staticmethod def s3_table_name_represent(c='default', f='table'):
def represent(value): if (value and ('_' in value)): suffix = value.split('_', 1)[1] return A(value, _href=URL(c=c, f=f, args=[suffix])) else: return value return represent
'On-validation routine for s3_fields: - field name must be unique within the table - @ToDo: Check for Reserved Words'
@staticmethod def s3_field_onvalidation(form):
db = current.db table = db.s3_field form_vars = form.vars if ('id' in form_vars): record_id = form_vars.id elif hasattr(form, 'record_id'): record_id = form.record_id else: record_id = None record = (form.record if hasattr(form, 'record') else None) if record_id: ...
'On-accept routine for s3_field: - set master table name for component keys (from field type)'
@staticmethod def s3_field_onaccept(form):
form_vars = form.vars try: record_id = form_vars.id except AttributeError: return db = current.db table = db.s3_field row = db((table.id == record_id)).select(table.id, table.component_key, table.field_type, limitby=(0, 1)).first() master = None if (row and row.component_...
'Return safe defaults for names in case the model is disabled'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return dict(asset_asset_id=(lambda **attr: dummy('asset_id')))
'After DB I/O'
@staticmethod def asset_onaccept(form):
if current.response.s3.bulk: return db = current.db atable = db.asset_asset form_vars = form.vars kit = form_vars.get('kit', None) site_id = form_vars.get('site_id', None) if site_id: stable = db.org_site asset_id = form_vars.id location_id = db((stable.site_i...
'After DB I/O'
@staticmethod def asset_log_onaccept(form):
request = current.request get_vars = request.get_vars status = get_vars.get('status', None) if (not status): if (not current.response.s3.asset_import): return db = current.db form_vars = form.vars asset_id = form_vars.asset_id status = int(form_vars.st...
'Custom lookup method for organisation rows, does a left join with the parent organisation. Parameters key and fields are not used, but are kept for API compatibility reasons. @param values: the organisation IDs'
def custom_lookup_rows(self, key, values, fields=[]):
db = current.db s3db = current.s3db table = s3db.asset_asset itable = db.supply_item btable = db.supply_brand qty = len(values) if (qty == 1): query = (table.id == values[0]) limitby = (0, 1) else: query = table.id.belongs(values) limitby = (0, qty) qu...
'Represent a single Row @param row: the asset_asset Row'
def represent_row(self, row):
number = row['asset_asset.number'] item = row['supply_item.name'] brand = row.get('supply_brand.name', None) if (not number): return self.default represent = ('%s (%s' % (number, item)) if brand: represent = ('%s, %s)' % (represent, brand)) else: represent = ('%...
'Represent a (key, value) as hypertext link. @param k: the key (site_id) @param v: the representation of the key @param row: the row with this key'
def link(self, k, v, row=None):
if row: type = row.get('asset_asset.type', None) if (type == 1): return A(v, _href=URL(c='vehicle', f='vehicle', args=[k], extension='')) k = s3_unicode(k) return A(v, _href=self.linkto.replace('[id]', k).replace('%5Bid%5D', k))
'Safe defaults for model-global names if module is disabled'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return dict(project_project_id=(lambda **attr: dummy('project_id')))
'Summary of Current Indicator Status @ToDo: Make this configurable'
@staticmethod def project_current_indicator_status(row):
if hasattr(row, 'project_project'): row = row.project_project if hasattr(row, 'id'): project_id = row['id'] else: return current.messages['NONE'] table = current.s3db.project_indicator_data query = ((table.deleted != True) & (table.project_id == project_id)) rows = curren...
'Total of all annual budgets for project'
@staticmethod def project_total_annual_budget(row):
if (not current.deployment_settings.get_project_multiple_budgets()): return 0 if ('project_project' in row): project_id = row['project_project.id'] elif ('id' in row): project_id = row['id'] else: return 0 table = current.s3db.project_annual_budget query = ((table...
'Total of project_organisation amounts for project'
@staticmethod def project_total_organisation_amount(row):
if (not current.deployment_settings.get_project_multiple_organisations()): return 0 if ('project_project' in row): project_id = row['project_project.id'] elif ('id' in row): project_id = row['id'] else: return 0 table = current.s3db.project_organisation query = ((...
'After DB I/O tasks for Project records'
@staticmethod def project_project_onaccept(form):
settings = current.deployment_settings if settings.get_project_multiple_organisations(): form_vars = form.vars id = form_vars.id organisation_id = (form_vars.organisation_id or current.request.post_vars.organisation_id) if organisation_id: lead_role = settings.get_pro...
'Import item de-duplication'
@staticmethod def project_project_deduplicate(item):
data = item.data code = data.get('code') if code: table = item.table query = (table.code.lower() == code.lower()) else: name = data.get('name') if name: table = item.table query = (table.name.lower() == name.lower()) else: retur...
'Display a filterable set of Projects on a Map - assumes mode_3w - currently assumes that theme_percentages=True @ToDo: Browse by Year'
@staticmethod def project_map(r, **attr):
if ((r.representation == 'html') and (r.name == 'project')): T = current.T db = current.db s3db = current.s3db response = current.response ptable = s3db.project_project ttable = s3db.project_theme tptable = s3db.project_theme_project ltable = s3db.gis_...
'Export Projects as GeoJSON Polygons to view on the map - currently assumes that theme_percentages=True @ToDo: complete'
@staticmethod def project_polygons(r, **attr):
db = current.db s3db = current.s3db ptable = s3db.project_project ttable = s3db.project_theme tptable = s3db.project_theme_project pltable = s3db.project_location ltable = s3db.gis_location themes = db((ttable.deleted == False)).select(ttable.id, ttable.name, orderby=ttable.name) cou...
'Display the project on a Simile Timeline http://www.simile-widgets.org/wiki/Reference_Documentation_for_Timeline Currently this just displays a Google Calendar @ToDo: Add Milestones @ToDo: Filters for different \'layers\' @ToDo: export milestones/tasks as .ics'
@staticmethod def project_timeline(r, **attr):
if ((r.representation == 'html') and (r.name == 'project')): appname = current.request.application response = current.response s3 = response.s3 calendar = r.record.calendar s3.scripts.append(('/%s/static/scripts/simile/timeline/timeline-api.js' % appname)) s3.js_globa...
'Safe defaults for model-global names if module is disabled'
@staticmethod def defaults():
dummy = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return dict(project_activity_id=(lambda **attr: dummy('activity_id')))
'Virtual field for the project_activity table @ToDo: Deprecate: replace with computed field'
@staticmethod def project_activity_year(row):
if hasattr(row, 'project_activity'): row = row.project_activity try: activity_id = row.id except AttributeError: return [] if hasattr(row, 'date'): start_date = row.date else: start_date = False if hasattr(row, 'end_date'): end_date = row.end_date ...
'Ensure the Activity Location is a Project Location with the Activity\'s Activity Types in (as a minimum). @ToDo: deployment_setting to allow project Locations to be read-only & have data editable only at the Activity level'
@staticmethod def project_activity_activity_type_onaccept(form):
db = current.db form_vars_get = form.vars.get activity_id = form_vars_get('activity_id') atable = db.project_activity activity = db((atable.id == activity_id)).select(atable.project_id, atable.location_id, limitby=(0, 1)).first() try: project_id = activity.project_id location_id ...
'Set the realm entity to the project\'s realm entity'
@staticmethod def project_activity_realm_entity(table, record):
activity_id = record.id db = current.db table = db.project_activity ptable = db.project_project query = ((table.id == activity_id) & (table.project_id == ptable.id)) project = db(query).select(ptable.realm_entity, limitby=(0, 1)).first() try: return project.realm_entity except: ...
'FK representation @ToDo: Bulk inc Translation'
@staticmethod def project_beneficiary_represent(id, row=None):
if row: return row.type if (not id): return current.messages['NONE'] db = current.db table = db.project_beneficiary ttable = db.project_beneficiary_type query = ((table.id == id) & (table.parameter_id == ttable.id)) r = db(query).select(table.value, ttable.name, limitby=(0, 1...
'Update project_beneficiary project & location from project_location_id'
@staticmethod def project_beneficiary_onaccept(form):
db = current.db btable = db.project_beneficiary ltable = db.project_location record_id = form.vars.id query = ((btable.id == record_id) & (ltable.id == btable.project_location_id)) project_location = db(query).select(ltable.project_id, ltable.location_id, limitby=(0, 1)).first() if project_l...
'Prevent the same human_resource record being added more than once'
@staticmethod def project_human_resource_onvalidation(form):
hr = current.s3db.project_human_resource_project form_vars = form.request_vars query = (((hr.human_resource_id == form_vars.human_resource_id) & (hr.project_id == form_vars.project_id)) & (hr.id != form_vars.id)) row = current.db(query).select(hr.id, limitby=(0, 1)).first() if row: form.erro...
'Safe defaults for model-global names if module is disabled'
@staticmethod def defaults():
project_location_id = S3ReusableField('dummy_id', 'integer', readable=False, writable=False) return dict(project_location_id=(lambda **attr: dummy('project_location_id')), project_location_represent=(lambda v, row=None: ''))
'Calculate the \'name\' field used by Map popups'
@staticmethod def project_location_onaccept(form):
form_vars = form.vars id = form_vars.get('id') if (form_vars.get('location_id') and form_vars.get('project_id')): name = current.s3db.project_location_represent(None, form_vars) elif id: name = current.s3db.project_location_represent(id) else: return None if (len(name) > ...
'If the Contact has no Realm, then set it to that of this record'
@staticmethod def project_location_contact_onaccept(form):
db = current.db form_vars = form.vars person_id = form_vars.get('person_id') realm_entity = form_vars.get('realm_entity') if ((not person_id) or (not realm_entity)): table = db.project_location_contact record = db((table.id == form_vars.get('id'))).select(table.person_id, table.realm...
'Form validation'
@staticmethod def project_organisation_onvalidation(form, lead_role=None):
if (lead_role is None): lead_role = current.deployment_settings.get_project_organisation_lead_role() form_vars = form.vars project_id = form_vars.project_id organisation_id = form_vars.organisation_id if ((str(form_vars.role) == str(lead_role)) and project_id): db = current.db ...
'Record creation post-processing If the added organisation is the lead role, set the project.organisation to point to the same organisation & update the realm_entity.'
@staticmethod def project_organisation_onaccept(form):
vars = form.vars if (str(vars.role) == str(current.deployment_settings.get_project_organisation_lead_role())): db = current.db ltable = db.project_organisation record = db((ltable.id == vars.id)).select(ltable.project_id, ltable.organisation_id, limitby=(0, 1)).first() organisati...
'Executed when a project organisation record is deleted. If the deleted organisation is the lead role on this project, set the project organisation to None.'
@staticmethod def project_organisation_ondelete(row):
db = current.db potable = db.project_organisation ptable = db.project_project query = (potable.id == row.get('id')) deleted_row = db(query).select(potable.deleted_fk, potable.role, limitby=(0, 1)).first() if (str(deleted_row.role) == str(current.deployment_settings.get_project_organisation_lead_...
'Set the realm entity to the project\'s realm entity'
@staticmethod def project_organisation_realm_entity(table, record):
po_id = record.id db = current.db table = db.project_organisation ptable = db.project_project query = ((table.id == po_id) & (table.project_id == ptable.id)) project = db(query).select(ptable.realm_entity, limitby=(0, 1)).first() try: return project.realm_entity except: r...
'Update the status fields of the different Project levels Fired onaccept of: project_activity_criteria (if status_from_activities) project_indicator_criteria (if status_from_activities: weightings may have changed) project_indicator_data project_indicator (weightings may have changed) project_output (weightings may hav...
@staticmethod def project_planning_status_update(project_id):
db = current.db s3db = current.s3db if current.deployment_settings.get_project_status_from_activities(): now = current.request.utcnow atable = s3db.project_activity table = s3db.project_criteria_activity ltable = s3db.project_criteria_activity_activity query = (((((((...
'Import item de-duplication'
@staticmethod def project_goal_deduplicate(item):
data = item.data name = data.get('name') if name: table = item.table query = (table.name == name) project_id = data.get('project_id') if project_id: query &= ((table.project_id == project_id) | (table.project_id == None)) duplicate = current.db(query).sele...
'Default all weightings to an even spread'
def project_goal_create_onaccept(self, form):
db = current.db record_id = form.vars.id table = current.s3db.project_goal record = db((table.id == record_id)).select(table.project_id, limitby=(0, 1)).first() try: project_id = record.project_id except: current.log.error('Cannot find Project Goal record (no re...