示例#1
0
def wacop_event_rheader(r, tabs=[]):
    """ EVENT custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "event_event":

            if not tabs:
                tabs = [
                    (T("Event Details"), None),
                    (T("Incidents"), "incident"),
                    (T("Units"), "group"),
                    (T("Tasks"), "task"),
                    (T("Updates"), "post"),
                ]

            rheader_fields = [
                ["name"],
                ["start_date"],
                ["comments"],
            ]

        elif tablename == "event_incident":

            if not tabs:
                tabs = [
                    (T("Incident Details"), None),
                    (T("Units"), "group"),
                    (T("Tasks"), "task"),
                    (T("Updates"), "post"),
                ]

            rheader_fields = [
                ["name"],
                ["date"],
                ["comments"],
            ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )
    return rheader
示例#2
0
文件: dvi.py 项目: sahana/eden
def morgue():
    """ Morgue Registry """

    morgue_tabs = [
        (T("Morgue Details"), ""),
        (T("Bodies"), "body"),
    ]

    from s3 import S3ResourceHeader
    rheader = S3ResourceHeader(
        [[(T("Morgue"), "name")]],
        tabs=morgue_tabs,
    )

    # Pre-processor
    def prep(r):
        # Function to call for all Site Instance Types
        from s3db.org import org_site_prep
        org_site_prep(r)

        return True

    s3.prep = prep

    return s3_rest_controller(rheader=rheader)
示例#3
0
文件: s3.py 项目: nursix/eden
def s3_table_rheader(r, tabs=None):

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    rheader = None

    record = r.record
    if record:

        T = current.T
        rheader_fields = []

        if r.tablename == "s3_table":

            if not tabs:

                # Use default/tables as native controller for s3_table
                tab_vars = {"native": True}

                tabs = [(T("Table"), None, tab_vars),
                        (T("Fields"), "field", tab_vars),
                        ]

            rheader_fields = [["name"],
                              ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(r,
                                                         table = r.resource.table,
                                                         record = record,
                                                         )

    return rheader
示例#4
0
文件: dvi.py 项目: sahana/eden
def body():
    """ Dead Bodies Registry """

    gender_opts = s3db.pr_gender_opts
    gender_opts[1] = T("unknown")

    ntable = s3db.pr_note
    ntable.status.readable = False
    ntable.status.writable = False

    dvi_tabs = [
        (T("Recovery"), ""),
        (T("Checklist"), "checklist"),
        (T("Images"), "image"),
        (T("Physical Description"), "physical_description"),
        (T("Effects Inventory"), "effects"),
        (T("Journal"), "note"),
        (T("Identification"), "identification"),
    ]

    from s3 import S3ResourceHeader
    rheader = S3ResourceHeader(
        [
            [(T("ID Tag Number"), "pe_label")],
            ["gender"],
            ["age_group"],
        ],
        tabs=dvi_tabs,
    )

    return s3_rest_controller(rheader=rheader)
示例#5
0
文件: rheaders.py 项目: sahana/eden
def rlpcm_profile_rheader(r, tabs=None):
    """ Custom rheader for default/person """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:

        T = current.T

        if tablename == "pr_person":

            tabs = [
                (T("Person Details"), None),
                (T("User Account"), "user_profile"),
                (T("Contact Information"), "contacts"),
            ]
            rheader_fields = []

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )
    return rheader
示例#6
0
def s3_scheduler_rheader(r, tabs=None):

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if not record:
        return None

    if tablename != r.tablename:
        resource = current.s3db.resource(
            tablename,
            id=record.id,
        )
    else:
        resource = r.resource

    if tablename == "scheduler_task":

        if not tabs:
            T = current.T
            tabs = [
                (T("Job Details"), None),
                (T("Runs"), "run"),
            ]

        rheader_fields = [
            [
                "function_name",
            ],
            [
                "status",
            ],
        ]
    else:
        rheader_fields = []

    header = S3ResourceHeader(
        rheader_fields,
        tabs,
        title="task_name",
    )
    rheader = header(
        r,
        table=resource.table,
        record=record,
    )

    return rheader
示例#7
0
文件: rheaders.py 项目: sahana/eden
def rlpcm_org_rheader(r, tabs=None):
    """ ORG custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "org_organisation":

            auth = current.auth
            is_org_group_admin = auth.s3_has_role("ORG_GROUP_ADMIN")

            if not tabs:
                tabs = [
                    (T("Organisation"), None),
                    (T("Offices"), "office"),
                ]
                if auth.s3_has_permission("update",
                                          "org_organisation",
                                          record_id=record.id):
                    tabs.append((T("Staff"), "human_resource"))

            # Check for active user accounts:
            rheader_fields = []
            if is_org_group_admin:

                from templates.RLPPTM.helpers import get_org_accounts
                active = get_org_accounts(record.id)[0]

                active_accounts = lambda row: len(active)
                rheader_fields.append([(T("Active Accounts"), active_accounts)
                                       ])

            rheader_title = "name"

        rheader = S3ResourceHeader(rheader_fields, tabs, title=rheader_title)
        rheader = rheader(r, table=resource.table, record=record)

    return rheader
示例#8
0
def stl_project_rheader(r, tabs=[]):
    """ PROJECT custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, \
                   S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "project_project":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                ]

                rheader_fields = [
                    [
                        (T("Code"), "code"),
                    ],
                    [
                        (T("Name"), "name"),
                    ],
                    [
                        (T("Organisation"), "organisation_id"),
                    ],
                ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )

    return rheader
示例#9
0
def rlp_delegation_rheader(r, tabs=None):
    """ hrm_delegation custom resource header """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "hrm_delegation":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                    (T("Notifications"), "delegation_message"),
                    (T("Notes"), "delegation_note"),
                ]

            rheader_fields = [
                [
                    "organisation_id",
                    "date",
                    "status",
                ],
                [
                    "person_id",
                    "end_date",
                ],
            ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )
    return rheader
示例#10
0
    def project_rheader(r, ert=False):

        if ert:
            # Simple header, no Tabs
            from s3 import S3ResourceHeader
            rheader_fields = [
                ["name"],
                ["code"],
                [(T("Donors"), "donor.organisation_id")],
                [(T("Locations"), "location.location_id")],
                ["start_date"],
                ["end_date"],
            ]
            rheader = S3ResourceHeader(rheader_fields, tabs=[])(r)
            return rheader
        else:
            # @ToDo: Remove Implementing Org, Add Donors
            return current.s3db.project_rheader(r)
示例#11
0
def rlp_org_rheader(r, tabs=None):
    """ ORG custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "org_organisation":

            if not tabs:
                tabs = [
                    (T("Organisation"), None),
                    (T("Administrative Offices"), "office"),
                    (T("Facilities"), "facility"),
                    (T("Staff"), "human_resource"),
                    (T("Volunteer Pools"), "pool"),
                ]

            rheader_fields = [
                [
                    "name",
                ],
            ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )
    return rheader
示例#12
0
文件: rheaders.py 项目: sahana/eden
def rlpptm_project_rheader(r, tabs=None):
    """ PROJECT custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "project_project":

            if not tabs:

                tabs = [
                    (T("Basic Details"), None),
                    (T("Organizations"), "organisation"),
                ]

            rheader_title = "name"

            rheader_fields = [
                [(T("Code"), "code")],
                ["organisation_id"],
            ]
        else:
            return None

        rheader = S3ResourceHeader(rheader_fields, tabs, title=rheader_title)
        rheader = rheader(r, table=resource.table, record=record)

    return rheader
示例#13
0
文件: rheaders.py 项目: sahana/eden
def rlpptm_supply_rheader(r, tabs=None):
    """ SUPPLY custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "supply_item":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                    (T("Packs"), "item_pack"),
                    (T("In Requests"), "req_item"),
                    (T("In Shipments"), "track_item"),
                ]

            rheader_title = "name"

            rheader_fields = [
                ["code"],
                ["um"],
            ]

        rheader = S3ResourceHeader(rheader_fields, tabs, title=rheader_title)
        rheader = rheader(r, table=resource.table, record=record)

    return rheader
示例#14
0
def drk_cr_rheader(r, tabs=None):
    """ CR custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "cr_shelter":

            if not tabs:
                tabs = [(T("Basic Details"), None),
                        ]

            rheader_fields = [["name",
                               ],
                              ["organisation_id",
                               ],
                              ["location_id",
                               ],
                              ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(r,
                                                         table=resource.table,
                                                         record=record,
                                                         )
    return rheader
示例#15
0
文件: rheaders.py 项目: sahana/eden
def rlpptm_req_rheader(r, tabs=None):
    """ REQ custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "req_req":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                    (T("Items"), "req_item"),
                ]

            rheader_title = "site_id"

            rheader_fields = [
                ["req_ref", "transit_status"],
                ["date", "fulfil_status"],
            ]

        rheader = S3ResourceHeader(rheader_fields, tabs, title=rheader_title)
        rheader = rheader(r, table=resource.table, record=record)

    return rheader
示例#16
0
文件: rheaders.py 项目: sahana/eden
def rlpcm_br_rheader(r, tabs=None):
    """ BR Resource Headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:

        T = current.T
        settings = current.deployment_settings

        record_id = record.id

        if tablename == "pr_person":

            if not tabs:

                # Basic Case Documentation
                tabs = [
                    (T("Basic Details"), None),
                ]
                append = tabs.append

                if settings.get_br_case_contacts_tab():
                    append((T("Contact Info"), "contacts"))
                if settings.get_br_case_id_tab():
                    append((T("ID"), "identity"))
                if settings.get_br_case_family_tab():
                    append((T("Family Members"), "group_membership/"))

                activities_tab = settings.get_br_case_activities()
                measures_tab = settings.get_br_manage_assistance() and \
                               settings.get_br_assistance_tab()

                activities_label = T("Needs")
                if activities_tab and measures_tab:
                    measures_label = T("Measures")
                else:
                    measures_label = T("Assistance")

                if activities_tab:
                    append((activities_label, "case_activity"))
                if measures_tab:
                    append((measures_label, "assistance_measure"))

                if settings.get_br_service_contacts():
                    append((T("Service Contacts"), "service_contact"))
                if settings.get_br_case_notes_tab():
                    append((T("Notes"), "br_note"))
                if settings.get_br_case_photos_tab():
                    append((T("Photos"), "image"))
                if settings.get_br_case_documents_tab():
                    append((T("Documents"), "document/"))

            case = resource.select(
                [
                    "first_name",
                    "middle_name",
                    "last_name",
                    "case.status_id",
                    "case.invalid",
                    "case.household_size",
                    "case.organisation_id",
                ],
                represent=True,
                raw_data=True,
            ).rows

            if not case:
                # Target record exists, but doesn't match filters
                return None

            # Extract case data
            case = case[0]

            name = s3_fullname
            case_status = lambda row: case["br_case.status_id"]
            organisation = lambda row: case["br_case.organisation_id"]

            household = settings.get_br_household_size()
            if household:
                if household == "auto":
                    label = T("Size of Family")
                else:
                    label = T("Household Size")
                household_size = (
                    label,
                    lambda row: case["br_case.household_size"],
                )
            else:
                household_size = None

            rheader_fields = [
                [
                    (T("ID"), "pe_label"),
                    (T("Case Status"), case_status),
                    (T("Organisation"), organisation),
                ],
                [
                    household_size,
                ],
            ]

            invalid = case["_row"]["br_case.invalid"]
            if invalid:
                # "Invalid Case" Hint
                hint = lambda record: SPAN(
                    T("Invalid Case"),
                    _class="invalid-case",
                )
                rheader_fields.insert(0, [(None, hint)])

            # Generate rheader XML
            rheader = S3ResourceHeader(rheader_fields, tabs, title=name)(
                r,
                table=resource.table,
                record=record,
            )

            # Add profile picture
            from s3 import s3_avatar_represent
            rheader.insert(
                0,
                A(
                    s3_avatar_represent(
                        record_id,
                        "pr_person",
                        _class="rheader-avatar",
                    ),
                    _href=URL(
                        f="person",
                        args=[record_id, "image"],
                        vars=r.get_vars,
                    ),
                ))
        elif tablename == "br_case_activity":

            if not tabs:
                if r.function in ("case_activity", "offers"):
                    tabs = [
                        (T("Basic Details"), None),
                        (T("Direct Offers"), "offers/"),
                    ]
                elif r.function in ("activities"):
                    tabs = [
                        (T("Basic Details"), None, {
                            "native": True
                        }),
                        (T("Direct Offers"), "direct_offer"),
                    ]

            rheader_fields = [
                ["need_id"],
                ["date"],
            ]
            rheader = S3ResourceHeader(rheader_fields, tabs, title="subject")(
                r,
                table=resource.table,
                record=record,
            )
        elif tablename == "br_assistance_offer":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None, {
                        "native": True
                    }),
                ]
                if r.function == "assistance_offer":
                    tabs.append((T("Direct Offers"), "direct_offer"))
            rheader_fields = [["date"]]
            rheader = S3ResourceHeader(rheader_fields, tabs, title="name")(
                r,
                table=resource.table,
                record=record,
            )
        else:
            rheader = None

    return rheader
示例#17
0
文件: rheaders.py 项目: sahana/eden
def rlpptm_inv_rheader(r, tabs=None):
    """ INV custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        db = current.db
        s3 = current.response.s3

        auth = current.auth
        s3db = current.s3db

        from s3db.inv import SHIP_STATUS_IN_PROCESS, SHIP_STATUS_SENT

        if tablename == "inv_send":
            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                    (T("Items"), "track_item"),
                ]

            rheader_fields = [
                ["req_ref"],  # , "send_ref"],
                ["status"],
                ["date"]
            ]
            rheader_title = "to_site_id"

            rheader = S3ResourceHeader(rheader_fields,
                                       tabs,
                                       title=rheader_title)

            actions = []

            # If the record status is SHIP_STATUS_IN_PROCESS, both sites are active
            # and there is at least one track item linked to it, add the send-button
            from .requests import is_active
            reason = None
            if record.status == SHIP_STATUS_IN_PROCESS:
                if not is_active(record.site_id):
                    reason = T("Distribution center no longer active")
                elif not is_active(record.to_site_id):
                    reason = T("Requesting site no longer active")
                elif auth.s3_has_permission("update",
                                            resource.table,
                                            record_id=record.id):
                    titable = s3db.inv_track_item
                    query = (titable.send_id == record.id) & \
                            (titable.deleted == False)
                    row = db(query).select(titable.id, limitby=(0, 1)).first()
                    if row:
                        actions.append(
                            A(
                                T("Send Shipment"),
                                _href=URL(c="inv",
                                          f="send_process",
                                          args=[record.id]),
                                _id="send_process",
                                _class="action-btn",
                            ))
                        s3.jquery_ready.append('''S3.confirmClick("#send_process","%s")''' \
                                                % T("Do you want to send this shipment?"))
                    else:
                        reason = T("Shipment is empty")
            else:
                reason = T("Shipment already in process")

            if reason:
                actions.append(
                    A(
                        T("Send Shipment"),
                        _id="send_process",
                        _disabled="disabled",
                        _class="action-btn",
                        _title=reason,
                    ))

            rheader = rheader(r,
                              table=resource.table,
                              record=record,
                              actions=actions)

        elif tablename == "inv_recv":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                    (T("Items"), "track_item"),
                ]

            # Get the number of items linked to this delivery
            titable = s3db.inv_track_item
            query = (titable.recv_id == record.id) & \
                    (titable.deleted == False)
            cnt = titable.id.count()
            row = db(query).select(cnt).first()
            num_items = row[cnt] if row else 0

            # Representation of the number of items
            def content(row):
                if num_items == 1:
                    msg = T("This shipment contains one line item")
                elif num_items > 1:
                    msg = T("This shipment contains %s items") % num_items
                else:
                    msg = "-"
                return msg

            rheader_fields = [  #["send_ref", "site_id"],
                ["status", "site_id"],
                ["date", (T("Content"), content)],
            ]
            rheader_title = "req_ref"

            rheader = S3ResourceHeader(rheader_fields,
                                       tabs,
                                       title=rheader_title)

            actions = []

            # If the record is SHIP_STATUS_IN_PROCESS or SHIP_STATUS_SENT
            # and there is at least one track item linked to it, add the receive-button
            if record.status in (SHIP_STATUS_IN_PROCESS, SHIP_STATUS_SENT) and \
               auth.s3_has_permission("update", resource.table, record_id = record.id) and \
               num_items:

                actions.append(
                    A(T("Receive Shipment"),
                      _href=URL(c="inv", f="recv_process", args=[record.id]),
                      _id="recv_process",
                      _class="action-btn"))
                s3.jquery_ready.append('''S3.confirmClick("#recv_process","%s")''' \
                                        % T("Did you receive this shipment?"))

            rheader = rheader(r,
                              table=resource.table,
                              record=record,
                              actions=actions)

        elif tablename == "inv_warehouse":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                ]

            rheader_fields = [
                ["code", "email"],
                ["organisation_id", "phone1"],
                ["location_id", "phone2"],
            ]
            rheader_title = "name"

            rheader = S3ResourceHeader(rheader_fields,
                                       tabs,
                                       title=rheader_title)
            rheader = rheader(r, table=resource.table, record=record)

    return rheader
示例#18
0
def stl_dvr_rheader(r, tabs=[]):
    """ DVR custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, \
                   S3ResourceHeader, \
                   s3_fullname

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "pr_person":

            # "Invalid Case" warning
            hint = lambda record: H3(
                T("Invalid Case"),
                _class="alert label",
            )

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                    (T("Contact"), "contacts"),
                    (T("Household"), "household"),
                    (T("Economy"), "economy"),
                    (T("Activities"), "case_activity"),
                ]

                case = resource.select(
                    [
                        "family_id.value",
                        "dvr_case.status_id",
                        "dvr_case.archived",
                        "dvr_case.organisation_id",
                        "dvr_case.disclosure_consent",
                        "dvr_case.project_id",
                    ],
                    represent=True,
                    raw_data=True,
                ).rows

                if not case:
                    return None

                case = case[0]

                case_status = lambda row: case["dvr_case.status_id"]
                archived = case["_row"]["dvr_case.archived"]
                family_id = lambda row: case["pr_family_id_person_tag.value"]
                organisation_id = lambda row: case["dvr_case.organisation_id"]
                project_id = lambda row: case["dvr_case.project_id"]
                name = lambda row: s3_fullname(row)

                raw = case._row

                # Render disclosure consent flag as colored label
                consent = raw["dvr_case.disclosure_consent"]
                labels = {"Y": "success", "N/A": "warning", "N": "alert"}

                def disclosure(row):
                    _class = labels.get(consent, "secondary")
                    return SPAN(
                        case["dvr_case.disclosure_consent"],
                        _class="%s label" % _class,
                    )

                rheader_fields = [
                    [
                        (T("ID"), "pe_label"),
                        (T("Case Status"), case_status),
                        (T("Data Disclosure"), disclosure),
                    ],
                    [
                        (T("Family ID"), family_id),
                        (T("Organisation"), organisation_id),
                    ],
                    [
                        (T("Name"), name),
                        (T("Project Code"), project_id),
                    ],
                    [
                        "date_of_birth",
                    ],
                ]

                if archived:
                    rheader_fields.insert(0, [(None, hint)])

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )

    return rheader
示例#19
0
def drk_org_rheader(r, tabs=None):
    """ ORG custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, s3_rheader_tabs, S3ResourceHeader
    from .uioptions import get_ui_options

    s3db = current.s3db

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T
        record_id = record.id

        ui_options = get_ui_options()
        is_admin = current.auth.s3_has_role("ADMIN")

        if tablename == "org_organisation":

            table = resource.table

            if record.root_organisation == record_id:
                branch = False
            else:
                branch = True

            # Custom tabs
            tabs = [(T("Basic Details"), None),
                    (T("Branches"), "branch"),
                    (T("Facilities"), "facility"),
                    (T("Staff & Volunteers"), "human_resource"),
                    #(T("Projects"), "project"),
                    (T("Counseling Themes"), "response_theme"),
                    ]

            if is_admin or ui_options.get("response_themes_needs"):
                # Ability to manage org-specific need types
                # as they are used in themes:
                tabs.append((T("Counseling Reasons"), "need"))

            if not branch and \
               (is_admin or \
                ui_options.get("case_document_templates") and \
                current.auth.s3_has_role("ORG_ADMIN")):
                tabs.append((T("Document Templates"), "document"))

            rheader_tabs = s3_rheader_tabs(r, tabs)

            # Custom header
            from gluon import TABLE, TR, TH, TD
            rheader = DIV()

            # Name
            record_data = TABLE(TR(TH("%s: " % table.name.label),
                                   record.name,
                                   ),
                                )

            # Parent Organisation
            if branch:
                btable = s3db.org_organisation_branch
                query = (btable.branch_id == record_id) & \
                        (btable.organisation_id == table.id)
                row = current.db(query).select(table.id,
                                               table.name,
                                               limitby = (0, 1),
                                               ).first()
                if row:
                    record_data.append(TR(TH("%s: " % T("Branch of")),
                                          A(row.name, _href=URL(args=[row.id, "read"])),
                                          ))

            # Website as link
            if record.website:
                record_data.append(TR(TH("%s: " % table.website.label),
                                      A(record.website, _href=record.website)))

            logo = s3db.org_organisation_logo(record)
            if logo:
                rheader.append(TABLE(TR(TD(logo),
                                        TD(record_data),
                                        )))
            else:
                rheader.append(record_data)

            rheader.append(rheader_tabs)
            return rheader

        elif tablename == "org_facility":

            if not tabs:
                tabs = [(T("Basic Details"), None),
                        ]

            rheader_fields = [["name", "email"],
                              ["organisation_id", "phone1"],
                              ["location_id", "phone2"],
                              ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(r,
                                                         table=resource.table,
                                                         record=record,
                                                         )
    return rheader
示例#20
0
def rlp_vol_rheader(r, tabs=None):
    """ Custom rheader for vol/person """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:

        T = current.T
        db = current.db
        s3db = current.s3db
        auth = current.auth

        coordinator = auth.s3_has_role("COORDINATOR")

        if tablename == "pr_person":

            if coordinator:
                delegation_tab = (T("Recruitment"), "delegation")
            else:
                delegation_tab = (T("Recruitment"), "delegation/")

            if not tabs:
                tabs = [
                    (T("Personal Data"), None),
                    (T("Skills / Resources"), "competency"),
                    delegation_tab,
                ]

            volunteer = resource.select(
                [
                    "person_details.alias",
                    "pool_membership.group_id",
                    "pool_membership.group_id$group_type",
                    "date_of_birth",
                    "age",
                    "occupation_type_person.occupation_type_id",
                    "volunteer_record.site_id",
                ],
                represent=True,
                raw_data=True,
            ).rows
            if volunteer:
                # Extract volunteer details
                volunteer = volunteer[0]
                if coordinator or rlp_deployed_with_org(record.id):
                    name = s3_fullname
                else:
                    name = lambda row: volunteer["pr_person_details.alias"]
                pool = lambda row: volunteer[
                    "pr_pool_membership_group_membership.group_id"]
                age = lambda row: volunteer["pr_person.age"]
                occupation_type = lambda row: volunteer[
                    "pr_occupation_type_person.occupation_type_id"]
            else:
                # Target record exists, but doesn't match filters
                return None

            rheader_fields = [[
                (T("ID"), "pe_label"),
                (T("Pool"), pool),
            ], [
                (T("Age"), age),
                (T("Occupation Type"), occupation_type),
            ], [
                ("", None),
                ("", None),
            ]]

            if coordinator:
                raw = volunteer["_row"]
                site_id = raw["hrm_volunteer_record_human_resource.site_id"]
                if site_id:
                    # Get site details
                    otable = s3db.org_office
                    query = (otable.site_id == site_id) & \
                            (otable.deleted == False)
                    office = db(query).select(
                        otable.name,
                        otable.phone1,
                        otable.email,
                        limitby=(0, 1),
                    ).first()
                    if office:
                        rheader_fields[0].append((
                            T("Office##gov"),
                            lambda row: office.name,
                        ))
                        rheader_fields[1].append((
                            T("Office Phone##gov"),
                            lambda row: office.phone1,
                        ))
                        rheader_fields[2].append((
                            T("Office Email##gov"),
                            lambda row: office.email,
                        ))

            open_pool_member = (volunteer["_row"]["pr_group.group_type"] == 21)
            if not coordinator and open_pool_member:
                # Recruitment hint
                from gluon import SPAN
                hint = lambda row: SPAN(T(
                    "Please contact the volunteer directly for deployment"),
                                        _class="direct-contact-hint")
                rheader_fields.append([(None, hint, 5)])

        rheader = S3ResourceHeader(rheader_fields, tabs, title=name)(
            r,
            table=resource.table,
            record=record,
        )
    return rheader
示例#21
0
def rlp_profile_rheader(r, tabs=None):
    """ Custom rheader for default/person """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, S3ResourceHeader

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:

        T = current.T

        if tablename == "pr_person":

            rows = r.resource.select(["volunteer_record.id"], limit=1).rows
            if rows:
                volunteer_id = rows[0][
                    "hrm_volunteer_record_human_resource.id"]
            else:
                volunteer_id = None

            if volunteer_id:
                # Volunteer users
                tabs = [
                    (T("Person Details"), None),
                    (T("User Account"), "user_profile"),
                    (T("Address"), "address"),
                    (T("Contact Information"), "contacts"),
                    (T("Skills"), "competency"),
                ]
                rheader_fields = [[
                    (T("ID"), "pe_label"),
                ], [
                    (T("Name"), s3_fullname),
                ], [
                    "date_of_birth",
                ]]
            else:
                # Other users
                tabs = [
                    (T("Person Details"), None),
                    (T("User Account"), "user_profile"),
                    (T("Contact Information"), "contacts"),
                ]
                rheader_fields = [
                    [
                        (T("Name"), s3_fullname),
                    ],
                ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(
            r,
            table=resource.table,
            record=record,
        )
    return rheader
示例#22
0
文件: rheaders.py 项目: sahana/eden
def rlpptm_org_rheader(r, tabs=None):
    """ ORG custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T

        if tablename == "org_organisation":

            auth = current.auth
            is_org_group_admin = auth.s3_has_role("ORG_GROUP_ADMIN")

            db = current.db
            s3db = current.s3db

            if not tabs:

                invite_tab = None
                sites_tab = None
                doc_tab = None

                gtable = s3db.org_group
                mtable = s3db.org_group_membership
                query = (mtable.organisation_id == record.id) & \
                        (mtable.group_id == gtable.id)
                group = db(query).select(gtable.name, limitby=(0, 1)).first()
                if group:
                    from .config import TESTSTATIONS, SCHOOLS, GOVERNMENT
                    if group.name == TESTSTATIONS:
                        sites_tab = (T("Test Stations"), "facility")
                        doc_tab = (T("Documents"), "document")
                    elif group.name == SCHOOLS:
                        sites_tab = (T("Administrative Offices"), "office")
                        if is_org_group_admin:
                            invite_tab = (T("Invite"), "invite")
                    elif group.name == GOVERNMENT:
                        sites_tab = (T("Warehouses"), "warehouse")

                tabs = [
                    (T("Organisation"), None),
                    invite_tab,
                    sites_tab,
                    (T("Staff"), "human_resource"),
                    doc_tab,
                ]

            # Look up the OrgID
            def org_id(row):
                ttable = s3db.org_organisation_tag
                query = (ttable.organisation_id == row.id) & \
                        (ttable.tag == "OrgID") & \
                        (ttable.deleted == False)
                tag = db(query).select(ttable.value, limitby=(0, 1)).first()
                return tag.value if tag else "-"

            # Check for active user accounts:
            rheader_fields = [[(T("Organization ID"), org_id)]]
            if is_org_group_admin:

                from .helpers import get_org_accounts
                active = get_org_accounts(record.id)[0]

                active_accounts = lambda row: len(active)
                rheader_fields.append([(T("Active Accounts"), active_accounts)
                                       ])

            rheader_title = "name"

        rheader = S3ResourceHeader(rheader_fields, tabs, title=rheader_title)
        rheader = rheader(r, table=resource.table, record=record)

    return rheader
示例#23
0
def drk_dvr_rheader(r, tabs=None):
    """ DVR custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    from s3 import s3_rheader_resource, \
                   S3ResourceHeader, \
                   s3_fullname
    from .uioptions import get_ui_options

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []

    if record:
        T = current.T
        record_id = record.id

        if tablename == "pr_person":

            # UI Options and ability to read cases from multiple orgs
            ui_opts = get_ui_options()
            ui_opts_get = ui_opts.get

            from .helpers import case_read_multiple_orgs
            multiple_orgs = case_read_multiple_orgs()[0]

            if not tabs:
                activity_tab_label = ui_opts_get("activity_tab_label")
                if activity_tab_label:
                    ACTIVITIES = T(activity_tab_label)
                else:
                    ACTIVITIES = T("Counseling Reasons")

                # Basic Case Documentation
                tabs = [(T("Basic Details"), None),
                        (T("Contact Info"), "contacts"),
                        (T("Family Members"), "group_membership/"),
                        (ACTIVITIES, "case_activity"),
                        ]

                # Optional Case Documentation
                if ui_opts_get("case_use_response_tab"):
                    tabs.append((T("Actions"), "response_action"))
                if ui_opts_get("case_use_appointments"):
                    tabs.append((T("Appointments"), "case_appointment"))
                if ui_opts_get("case_use_service_contacts"):
                    tabs.append((T("Service Contacts"), "service_contact"))
                if ui_opts_get("case_use_photos_tab"):
                    tabs.append((T("Photos"), "image"))

                # Uploads
                tabs.append((T("Documents"), "document/"))

                # Notes etc.
                if ui_opts_get("case_use_notes"):
                    tabs.append((T("Notes"), "case_note"))

            # Get the record data
            lodging_opt = ui_opts_get("case_lodging")
            if lodging_opt == "site":
                lodging_sel = "dvr_case.site_id"
                lodging_col = "dvr_case.site_id"
            elif lodging_opt == "text":
                lodging_sel = "case_details.lodging"
                lodging_col = "dvr_case_details.lodging"
            else:
                lodging_sel = None
                lodging_col = None

            if ui_opts_get("case_use_flags"):
                flags_sel = "dvr_case_flag_case.flag_id"
            else:
                flags_sel = None

            if ui_opts_get("case_use_place_of_birth"):
                pob_sel = "person_details.place_of_birth"
            else:
                pob_sel = None

            if ui_opts_get("case_use_bamf"):
                bamf_sel = "bamf.value"
            else:
                bamf_sel = None

            case = resource.select(["first_name",
                                    "last_name",
                                    "dvr_case.status_id",
                                    "dvr_case.archived",
                                    "dvr_case.household_size",
                                    "dvr_case.organisation_id",
                                    "case_details.arrival_date",
                                    bamf_sel,
                                    "person_details.nationality",
                                    pob_sel,
                                    lodging_sel,
                                    flags_sel,
                                    ],
                                    represent = True,
                                    raw_data = True,
                                    ).rows

            if case:
                # Extract case data
                case = case[0]

                name = lambda person: s3_fullname(person, truncate=False)
                raw = case["_row"]

                case_status = lambda row: case["dvr_case.status_id"]
                archived = raw["dvr_case.archived"]
                organisation = lambda row: case["dvr_case.organisation_id"]
                arrival_date = lambda row: case["dvr_case_details.arrival_date"]
                household_size = lambda row: case["dvr_case.household_size"]
                nationality = lambda row: case["pr_person_details.nationality"]

                # Warn if nationality is lacking while mandatory
                if ui_opts_get("case_nationality_mandatory") and \
                   raw["pr_person_details.nationality"] is None:
                    current.response.warning = T("Nationality lacking!")

                bamf = lambda row: case["pr_bamf_person_tag.value"]

                if pob_sel:
                    place_of_birth = lambda row: case["pr_person_details.place_of_birth"]
                else:
                    place_of_birth = None
                if lodging_col:
                    lodging = (T("Lodging"), lambda row: case[lodging_col])
                else:
                    lodging = None
                if flags_sel:
                    flags = lambda row: case["dvr_case_flag_case.flag_id"]
                else:
                    flags = None
            else:
                # Target record exists, but doesn't match filters
                return None

            arrival_date_label = ui_opts_get("case_arrival_date_label")
            arrival_date_label = T(arrival_date_label) \
                                 if arrival_date_label else T("Date of Entry")

            # Adaptive rheader-fields
            rheader_fields = [[None,
                               (T("Nationality"), nationality),
                               (T("Case Status"), case_status)],
                              [None, None, None],
                              [None, None, None],
                              ]

            if ui_opts_get("case_use_pe_label"):
                rheader_fields[0][0] = (T("ID"), "pe_label")
                rheader_fields[1][0] = "date_of_birth"
            else:
                rheader_fields[0][0] = "date_of_birth"

            if pob_sel:
                pob_row = 1 if rheader_fields[1][0] is None else 2
                rheader_fields[pob_row][0] = (T("Place of Birth"), place_of_birth)

            if bamf_sel:
                doe_row = 2
                rheader_fields[1][1] = (T("BAMF-Az"), bamf)
            else:
                doe_row = 1
            rheader_fields[doe_row][1] = (arrival_date_label, arrival_date)

            if lodging:
                rheader_fields[1][2] = lodging

            if ui_opts_get("case_show_total_consultations"):
                from .helpers import get_total_consultations
                total_consultations = (T("Number of Consultations"), get_total_consultations)
                if rheader_fields[1][2] is None:
                    rheader_fields[1][2] = total_consultations
                else:
                    rheader_fields[0].append(total_consultations)

            hhsize = (T("Size of Family"), household_size)
            if rheader_fields[1][0] is None:
                rheader_fields[1][0] = hhsize
            elif rheader_fields[2][0] is None:
                rheader_fields[2][0] = hhsize
            elif rheader_fields[1][2] is None:
                rheader_fields[1][2] = hhsize
            else:
                rheader_fields[2][2] = hhsize

            colspan = 5

            if multiple_orgs:
                # Show organisation if user can see cases from multiple orgs
                rheader_fields.insert(0, [(T("Organisation"), organisation, colspan)])
            if flags_sel:
                rheader_fields.append([(T("Flags"), flags, colspan)])
            if ui_opts_get("case_header_protection_themes"):
                from .helpers import get_protection_themes
                rheader_fields.append([(T("Protection Need"),
                                        get_protection_themes,
                                        colspan,
                                        )])
            if archived:
                # "Case Archived" hint
                hint = lambda record: SPAN(T("Invalid Case"), _class="invalid-case")
                rheader_fields.insert(0, [(None, hint)])

            # Generate rheader XML
            rheader = S3ResourceHeader(rheader_fields, tabs, title=name)(
                            r,
                            table = resource.table,
                            record = record,
                            )

            # Add profile picture
            from s3 import s3_avatar_represent
            rheader.insert(0, A(s3_avatar_represent(record_id,
                                                    "pr_person",
                                                    _class = "rheader-avatar",
                                                    _width = 60,
                                                    _height = 60,
                                                    ),
                                _href=URL(f = "person",
                                          args = [record_id, "image"],
                                          vars = r.get_vars,
                                          ),
                                )
                           )

            return rheader

        elif tablename == "dvr_case":

            if not tabs:
                tabs = [(T("Basic Details"), None),
                        (T("Activities"), "case_activity"),
                        ]

            rheader_fields = [["reference"],
                              ["status_id"],
                              ]

        rheader = S3ResourceHeader(rheader_fields, tabs)(r,
                                                         table=resource.table,
                                                         record=record,
                                                         )
示例#24
0
文件: rheaders.py 项目: sahana/eden
def rlpptm_fin_rheader(r, tabs=None):
    """ FIN custom resource headers """

    if r.representation != "html":
        # Resource headers only used in interactive views
        return None

    tablename, record = s3_rheader_resource(r)
    if tablename != r.tablename:
        resource = current.s3db.resource(tablename, id=record.id)
    else:
        resource = r.resource

    rheader = None
    rheader_fields = []
    rheader_title = None
    img = None

    if record:
        T = current.T

        if tablename == "fin_voucher":

            if not tabs:
                tabs = [
                    (T("Voucher"), None),
                ]

            rheader_title = None
            rheader_fields = [
                [
                    "program_id",
                ],
                [
                    "signature",
                ],
                [
                    "date",
                ],
                [
                    "valid_until",
                ],
            ]

            signature = record.signature
            if signature:
                try:
                    import qrcode
                except ImportError:
                    pass
                else:
                    from s3 import s3_qrcode_represent
                    img = s3_qrcode_represent(signature, show_value=False)
                    img.add_class("rheader-qrcode")

        elif tablename == "fin_voucher_debit":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                ]

                # If user can cancel the debit and the debit can be
                # cancelled, add the cancel-action as tab
                from .helpers import can_cancel_debit
                if can_cancel_debit(record):
                    p = current.s3db.fin_VoucherProgram(record.program_id)
                    error = p.cancellable(record.id)[1]
                    if not error:
                        tabs.append((T("Cancel##debit"), "cancel"))

            rheader_title = "signature"
            rheader_fields = [
                [
                    (T("Status"), "status"),
                ],
            ]

        elif tablename == "fin_voucher_invoice":

            if not tabs:
                tabs = [
                    (T("Basic Details"), None),
                ]

            from .helpers import InvoicePDF, check_invoice_integrity

            # Lookup the invoice header data
            data = InvoicePDF.lookup_header_data(record)
            addr_street = lambda row: data.get("addr_street", "-")
            addr_place = lambda row: "%s %s" % (
                data.get("addr_postcode", ""),
                data.get("addr_place", "?"),
            )
            email = lambda row: data.get("email") or "-"

            rheader_title = "pe_id"
            rheader_fields = [
                [
                    (T("Address"), addr_street),
                    "invoice_no",
                    (T("Integrity Check"), check_invoice_integrity),
                ],
                [(T("Place"), addr_place), "date"],
                [(T("Email"), email), "status"],
            ]

        rheader = S3ResourceHeader(rheader_fields, tabs, title=rheader_title)
        rheader = rheader(r, table=resource.table, record=record)

        if img:
            rheader.insert(0, img)

    return rheader