def prep(r): mission_date = s3db.deploy_mission.created_on from s3 import S3DateTime mission_date.represent = lambda d: \ S3DateTime.date_represent(d, utc=True) if r.record: table = r.resource.table table.mission_id.writable = False table.human_resource_id.writable = False if r.representation == "popup": r.resource.configure(insertable=False) return True
def get_family_members(self, person, include_ids=False): """ Get infos for all family members of person @param person: the person (Row) @param include_ids: include the person record IDs @returns: array with family member infos, format: [{i: the person record ID (if requested) l: pe_label, n: fullname, d: dob_formatted, p: picture_URL, r: { event_code: { m: message, e: earliest_date_ISO } }, ... ] """ db = current.db s3db = current.s3db ptable = s3db.pr_person itable = s3db.pr_image gtable = s3db.pr_group mtable = s3db.pr_group_membership ctable = s3db.dvr_case stable = s3db.dvr_case_status # Get all case groups this person belongs to person_id = person.id query = ((mtable.person_id == person_id) & \ (mtable.deleted != True) & \ (gtable.id == mtable.group_id) & \ (gtable.group_type == 7)) rows = db(query).select(gtable.id) group_ids = set(row.id for row in rows) members = {} if group_ids: join = [ptable.on(ptable.id == mtable.person_id), ctable.on((ctable.person_id == ptable.id) & \ (ctable.archived == False) & \ (ctable.deleted == False)), ] left = [stable.on(stable.id == ctable.status_id), itable.on((itable.pe_id == ptable.pe_id) & \ (itable.profile == True) & \ (itable.deleted == False)), ] query = (mtable.group_id.belongs(group_ids)) & \ (mtable.deleted != True) & \ (stable.is_closed != True) rows = db(query).select( ptable.id, ptable.pe_label, ptable.first_name, ptable.last_name, ptable.date_of_birth, itable.image, join=join, left=left, ) for row in rows: member_id = row.pr_person.id if member_id not in members: members[member_id] = row output = [] if members: # All event types and blocking rules event_types = self.get_event_types() intervals = self.get_interval_rules(set(members.keys())) for member_id, data in members.items(): member = data.pr_person picture = data.pr_image # Person data data = { "l": member.pe_label, "n": s3_fullname(member), "d": S3DateTime.date_represent(member.date_of_birth), } # Record ID? if include_ids: data["id"] = member_id # Profile picture URL if picture.image: data["p"] = URL( c="default", f="download", args=picture.image, ) # Blocking rules event_rules = intervals.get(member_id) if event_rules: rules = {} for event_type_id, rule in event_rules.items(): code = event_types.get(event_type_id).code rules[code] = ( s3_str(rule[0]), "%sZ" % s3_encode_iso_datetime(rule[1]), ) data["r"] = rules # Add info to output output.append(data) return output
def customise_req_organisation_needs_resource(r, tablename): s3db = current.s3db table = current.s3db.req_organisation_needs CASH = T("Cash Donations needed") if r.tablename == "req_organisation_needs": from s3 import IS_ONE_OF, S3DateTime # Allow only organisations which do not have a needs record # yet (single component): field = table.organisation_id dbset = current.db(table.id == None) left = table.on(table.organisation_id == current.s3db.org_organisation.id) field.requires = IS_ONE_OF(dbset, "org_organisation.id", field.represent, left = left, orderby = "org_organisation.name", sort = True, ) # Format modified_on as date field = table.modified_on field.represent = lambda d: S3DateTime.date_represent(d, utc=True) if r.representation in ("html", "aadata", "iframe"): # Structured lists for interactive views from gluon import Field table.needs_skills = Field.Method(lambda row: \ organisation_needs(row, need_type="skills")) table.needs_items = Field.Method(lambda row: \ organisation_needs(row, need_type="items")) current.response.s3.stylesheets.append("../themes/RW/needs.css") needs_skills = (T("Volunteers needed"), "needs_skills") needs_items = (T("Supplies needed"), "needs_items") # Filter widgets from s3 import S3LocationFilter, S3OptionsFilter, S3TextFilter filter_widgets = [#S3TextFilter(["organisation_id$name", # ], # label = T("Search"), # ), S3OptionsFilter("organisation_id"), S3OptionsFilter("organisation_needs_skill.skill_id", label = T("Skills sought"), ), S3OptionsFilter("organisation_needs_item.item_id", label = T("Supplies sought"), ), S3LocationFilter("organisation_id$active_service_location.site_id$location_id", ), ] # CRUD form from s3 import S3SQLCustomForm, S3SQLInlineComponent crud_form = S3SQLCustomForm( "organisation_id", S3SQLInlineComponent("organisation_needs_skill", label = T("Volunteers needed"), fields = ["skill_id", "demand", "comments", ], ), S3SQLInlineComponent("organisation_needs_item", label = T("Supplies needed"), fields = ["item_id", "demand", "comments", ], ), (CASH, "money"), "money_details", #"vol", #"vol_details", ) next_page = r.url(method="") \ if r.tablename == "req_organisation_needs" else None s3db.configure("req_organisation_needs", crud_form = crud_form, filter_widgets = filter_widgets, create_next = next_page, update_next = next_page, ) else: # Simple fields for exports needs_skills = (T("Volunteers needed"), "organisation_needs_skill.skill_id") needs_items = (T("Supplies needed"), "organisation_needs_item.item_id") # List fields (all formats) list_fields = ["organisation_id", needs_skills, needs_items, (CASH, "money"), (T("Cash Donation Details"), "money_details"), (T("Last Update"), "modified_on"), ] s3db.configure("req_organisation_needs", list_fields = list_fields, )
def customise_req_organisation_needs_resource(r, tablename): s3db = current.s3db table = current.s3db.req_organisation_needs CASH = T("Cash Donations needed") if r.tablename == "req_organisation_needs": from s3 import IS_ONE_OF, S3DateTime # Allow only organisations which do not have a needs record # yet (single component): field = table.organisation_id dbset = current.db(table.id == None) left = table.on( table.organisation_id == current.s3db.org_organisation.id) field.requires = IS_ONE_OF( dbset, "org_organisation.id", field.represent, left=left, orderby="org_organisation.name", sort=True, ) # Format modified_on as date field = table.modified_on field.represent = lambda d: S3DateTime.date_represent(d, utc=True) if r.representation in ("html", "aadata", "iframe"): # Structured lists for interactive views from gluon import Field table.needs_skills = Field.Method(lambda row: \ organisation_needs(row, need_type="skills")) table.needs_items = Field.Method(lambda row: \ organisation_needs(row, need_type="items")) current.response.s3.stylesheets.append("../themes/RW/needs.css") needs_skills = (T("Volunteers needed"), "needs_skills") needs_items = (T("Supplies needed"), "needs_items") # Filter widgets from s3 import S3LocationFilter, S3OptionsFilter, S3TextFilter filter_widgets = [ #S3TextFilter(["organisation_id$name", # ], # label = T("Search"), # ), S3OptionsFilter("organisation_id"), S3OptionsFilter( "organisation_needs_skill.skill_id", label=T("Skills sought"), ), S3OptionsFilter( "organisation_needs_item.item_id", label=T("Supplies sought"), ), S3LocationFilter( "organisation_id$active_service_location.site_id$location_id", ), ] # CRUD form from s3 import S3SQLCustomForm, S3SQLInlineComponent crud_form = S3SQLCustomForm( "organisation_id", S3SQLInlineComponent( "organisation_needs_skill", label=T("Volunteers needed"), fields=[ "skill_id", "demand", "comments", ], ), S3SQLInlineComponent( "organisation_needs_item", label=T("Supplies needed"), fields=[ "item_id", "demand", "comments", ], ), (CASH, "money"), "money_details", #"vol", #"vol_details", ) next_page = r.url(method="") \ if r.tablename == "req_organisation_needs" else None s3db.configure( "req_organisation_needs", crud_form=crud_form, filter_widgets=filter_widgets, create_next=next_page, update_next=next_page, ) else: # Simple fields for exports needs_skills = (T("Volunteers needed"), "organisation_needs_skill.skill_id") needs_items = (T("Supplies needed"), "organisation_needs_item.item_id") # List fields (all formats) list_fields = [ "organisation_id", needs_skills, needs_items, (CASH, "money"), (T("Cash Donation Details"), "money_details"), (T("Last Update"), "modified_on"), ] s3db.configure( "req_organisation_needs", list_fields=list_fields, )
def get_family_members(self, person, include_ids=False): """ Get infos for all family members of person @param person: the person (Row) @param include_ids: include the person record IDs @returns: array with family member infos, format: [{i: the person record ID (if requested) l: pe_label, n: fullname, d: dob_formatted, p: picture_URL, r: { event_code: { m: message, e: earliest_date_ISO } }, ... ] """ db = current.db s3db = current.s3db ptable = s3db.pr_person itable = s3db.pr_image gtable = s3db.pr_group mtable = s3db.pr_group_membership ctable = s3db.dvr_case stable = s3db.dvr_case_status # Get all case groups this person belongs to person_id = person.id query = ((mtable.person_id == person_id) & \ (mtable.deleted != True) & \ (gtable.id == mtable.group_id) & \ (gtable.group_type == 7)) rows = db(query).select(gtable.id) group_ids = set(row.id for row in rows) members = {} if group_ids: join = [ptable.on(ptable.id == mtable.person_id), ctable.on((ctable.person_id == ptable.id) & \ (ctable.archived == False) & \ (ctable.deleted == False)), ] left = [stable.on(stable.id == ctable.status_id), itable.on((itable.pe_id == ptable.pe_id) & \ (itable.profile == True) & \ (itable.deleted == False)), ] query = (mtable.group_id.belongs(group_ids)) & \ (mtable.deleted != True) & \ (stable.is_closed != True) rows = db(query).select(ptable.id, ptable.pe_label, ptable.first_name, ptable.last_name, ptable.date_of_birth, itable.image, join = join, left = left, ) for row in rows: member_id = row.pr_person.id if member_id not in members: members[member_id] = row output = [] if members: # All event types and blocking rules event_types = self.get_event_types() intervals = self.get_interval_rules(set(members.keys())) for member_id, data in members.items(): member = data.pr_person picture = data.pr_image # Person data data = {"l": member.pe_label, "n": s3_fullname(member), "d": S3DateTime.date_represent(member.date_of_birth), } # Record ID? if include_ids: data["id"] = member_id # Profile picture URL if picture.image: data["p"] = URL(c = "default", f = "download", args = picture.image, ) # Blocking rules event_rules = intervals.get(member_id) if event_rules: rules = {} for event_type_id, rule in event_rules.items(): code = event_types.get(event_type_id).code rules[code] = (s3_str(rule[0]), "%sZ" % s3_encode_iso_datetime(rule[1]), ) data["r"] = rules # Add info to output output.append(data) return output