Exemplo n.º 1
0
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def mavc_rheader(r, tabs=None):
    """ Custom rheaders """

    if r.representation != "html":
        return None

    from s3 import s3_rheader_resource, s3_rheader_tabs
    from gluon import A, DIV, H1, H2, TAG

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

    T = current.T
    s3db = current.s3db

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

    rheader = ""

    if tablename == "org_organisation":

        # Tabs
        if not tabs:
            INDIVIDUALS = current.deployment_settings.get_hrm_staff_label()

            tabs = [
                (T("About"), None),
                (INDIVIDUALS, "human_resource"),
                (T("Service Locations"), "service_location"),
                # @todo: activities
            ]

        # Use OrganisationRepresent for title to get L10n name if available
        represent = s3db.org_OrganisationRepresent(acronym=False, parent=False)
        title = represent(record.id)

        # Retrieve other details for the rheader
        data = resource.select(["organisation_organisation_type.organisation_type_id", "website"], represent=True)
        row = data.rows[0]
        subtitle = row["org_organisation_organisation_type.organisation_type_id"]
        website = row["org_organisation.website"]

        # Compile the rheader
        rheader = DIV(DIV(H1(title), H2(subtitle), website if record.website else "", _class="rheader-details"))

    if tabs:
        rheader_tabs = s3_rheader_tabs(r, tabs)
        rheader.append(rheader_tabs)

    return rheader
Exemplo n.º 4
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
Exemplo n.º 5
0
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
0
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
Exemplo n.º 10
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
Exemplo n.º 11
0
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
Exemplo n.º 12
0
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
Exemplo n.º 13
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
Exemplo n.º 14
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
Exemplo n.º 15
0
    def ucce_rheader(r):
        """
            Custom rheaders
        """

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

        # Need to use this format as otherwise req_match?viewing=org_office.x
        # doesn't have an rheader
        from s3 import s3_rheader_resource, s3_rheader_tabs
        tablename, record = s3_rheader_resource(r)

        if record is None:
            # List or Create form: rheader makes no sense here
            return None

        from gluon import A, DIV, TABLE, TR, TH, URL

        if tablename == "dc_template":
            #tabs = [(T("Basic Details"), None),
            #        (T("Participants"), "participant"),
            #        ]

            #rheader_tabs = s3_rheader_tabs(r, tabs)

            db = current.db
            s3db = current.s3db

            ttable = s3db.dc_target
            target = db(ttable.template_id == record.id).select(ttable.id,
                                                                ttable.status,
                                                                limitby = (0, 1)
                                                                ).first()
            try:
                target_id = target.id
                target_status = target.status
            except AttributeError:
                target_id = None
                target_status = None

            if not target_status:
                # No Target linked...something odd happening
                button = ""
            elif target_status == 2:
                # Active
                button = A(T("Deactivate"),
                           _href=URL(c="dc", f="target",
                                     args=[target_id, "deactivate.popup"],
                                     ),
                           _class="action-btn s3_modal",
                           _title=T("Deactivate Survey"),
                           )
            else:
                # Draft / Deactivated
                button = A(T("Activate"),
                           _href=URL(c="dc", f="target",
                                     args=[target_id, "activate.popup"],
                                     ),
                           _class="action-btn s3_modal",
                           _title=T("Activate Survey"),
                           )

            ptable = s3db.project_project
            ltable = s3db.project_project_target
            query = (ltable.target_id == target_id) & \
                    (ltable.project_id == ptable.id)
            project = db(query).select(ptable.name,
                                       limitby = (0, 1)
                                       ).first()
            try:
                project_name = project.name
            except AttributeError:
                project_name = ""

            #table = r.table
            rheader = DIV(TABLE(TR(# @ToDo: make this editable
                                   TH("%s: " % T("Survey name")),
                                   record.name,
                                   TH("%s: " % T("Project")),
                                   project_name,
                                   button,
                                   )),
                          #rheader_tabs,
                          )

        return rheader
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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
Exemplo n.º 18
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
Exemplo n.º 19
0
def mavc_rheader(r, tabs=None):
    """ Custom rheaders """

    if r.representation != "html":
        return None

    from s3 import s3_rheader_resource, s3_rheader_tabs
    from gluon import A, DIV, H1, H2, TAG

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

    T = current.T
    s3db = current.s3db

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

    rheader = ""

    if tablename == "org_organisation":

        # Tabs
        if not tabs:
            INDIVIDUALS = current.deployment_settings.get_hrm_staff_label()

            tabs = [(T("About"), None),
                    (INDIVIDUALS, "human_resource"),
                    (T("Services"), "service_location"),
                    (T("Facilities"), "facility"),
                    (T("Projects"), "project"),
                    (T("Attachments"), "document"),
                    ]

        # Use OrganisationRepresent for title to get L10n name if available
        represent = s3db.org_OrganisationRepresent(acronym=False,
                                                   parent=False,
                                                   )
        title = represent(record.id)

        # Retrieve details for the rheader
        data = resource.select(["organisation_organisation_type.organisation_type_id",
                                "country",
                                "website",
                                ],
                               raw_data = True,
                               represent = True,
                               )
        row = data.rows[0]
        raw = row["_row"]

        # Construct subtitle
        subtitle_fields = ("org_organisation_organisation_type.organisation_type_id",
                           "org_organisation.country",
                           )
        items = []
        for fname in subtitle_fields:
            if raw[fname]:
                items.append(s3_unicode(row[fname]))
        subtitle = ", ".join(items)

        # Website
        website = row["org_organisation.website"]

        # Compose the rheader
        rheader = DIV(DIV(H1(title),
                          H2(subtitle),
                          website if record.website else "",
                          _class="rheader-details",
                          ),
                      )

    elif tablename == "project_project":

        if not tabs:
            tabs = [(T("About"), None),
                    (T("Locations"), "location"),
                    (T("Attachments"), "document"),
                    ]

        # Retrieve details for the rheader
        data = resource.select(["name",
                                "organisation_id",
                                ],
                               represent = True,
                               )
        row = data.rows[0]

        # Title and Subtitle
        title = row["project_project.name"]
        subtitle = row["project_project.organisation_id"]

        # Compose the rheader
        rheader = DIV(DIV(H1(title),
                          H2(subtitle),
                          _class="rheader-details",
                          ),
                      )

    elif tablename == "pr_person":

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

        from s3 import s3_fullname
        title = s3_fullname(record)

        # Link organisation_id representation to staff tab
        linkto = URL(c = "org",
                     f = "organisation",
                     args = ["[id]", "human_resource"],
                     )
        htable = s3db.hrm_human_resource
        field = htable.organisation_id
        field.represent = s3db.org_OrganisationRepresent(show_link = True,
                                                         linkto = linkto,
                                                         )

        # Retrieve details for the rheader
        data = resource.select(["human_resource.job_title_id",
                                "human_resource.organisation_id",
                                ],
                               raw_data = True,
                               represent = True,
                               )
        row = data.rows[0]
        raw = row["_row"]

        # Construct subtitle
        organisation_id = raw["hrm_human_resource.organisation_id"]
        if organisation_id:
            subtitle = row["hrm_human_resource.organisation_id"]
            job_title_id = raw["hrm_human_resource.job_title_id"]
            if job_title_id:
                subtitle = TAG[""]("%s, " % row["hrm_human_resource.job_title_id"],
                                   subtitle,
                                   )

        # Compose the rheader
        rheader = DIV(DIV(H1(title),
                          H2(subtitle),
                          _class="rheader-details",
                          ),
                      )

    if tabs:
        rheader_tabs = s3_rheader_tabs(r, tabs)
        rheader.append(rheader_tabs)

    return rheader
Exemplo n.º 20
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
Exemplo n.º 21
0
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
Exemplo n.º 22
0
def mavc_rheader(r, tabs=None):
    """ Custom rheaders """

    if r.representation != "html":
        return None

    from s3 import s3_rheader_resource, s3_rheader_tabs
    from gluon import A, DIV, H1, H2, TAG

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

    T = current.T
    s3db = current.s3db

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

    rheader = ""

    if tablename == "org_organisation":

        # Tabs
        if not tabs:
            INDIVIDUALS = current.deployment_settings.get_hrm_staff_label()

            tabs = [
                (T("About"), None),
                (INDIVIDUALS, "human_resource"),
                (T("Services"), "service_location"),
                (T("Facilities"), "facility"),
                (T("Projects"), "project"),
                (T("Attachments"), "document"),
            ]

        # Use OrganisationRepresent for title to get L10n name if available
        represent = s3db.org_OrganisationRepresent(
            acronym=False,
            parent=False,
        )
        title = represent(record.id)

        # Retrieve details for the rheader
        data = resource.select(
            [
                "organisation_organisation_type.organisation_type_id",
                "country",
                "website",
            ],
            raw_data=True,
            represent=True,
        )
        row = data.rows[0]
        raw = row["_row"]

        # Construct subtitle
        subtitle_fields = (
            "org_organisation_organisation_type.organisation_type_id",
            "org_organisation.country",
        )
        items = []
        for fname in subtitle_fields:
            if raw[fname]:
                items.append(s3_unicode(row[fname]))
        subtitle = ", ".join(items)

        # Website
        website = row["org_organisation.website"]

        # Compose the rheader
        rheader = DIV(
            DIV(
                H1(title),
                H2(subtitle),
                website if record.website else "",
                _class="rheader-details",
            ), )

    elif tablename == "project_project":

        if not tabs:
            tabs = [
                (T("About"), None),
                (T("Locations"), "location"),
                (T("Attachments"), "document"),
            ]

        # Retrieve details for the rheader
        data = resource.select(
            [
                "name",
                "organisation_id",
            ],
            represent=True,
        )
        row = data.rows[0]

        # Title and Subtitle
        title = row["project_project.name"]
        subtitle = row["project_project.organisation_id"]

        # Compose the rheader
        rheader = DIV(DIV(
            H1(title),
            H2(subtitle),
            _class="rheader-details",
        ), )

    elif tablename == "pr_person":

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

        from s3 import s3_fullname
        title = s3_fullname(record)

        # Link organisation_id representation to staff tab
        linkto = URL(
            c="org",
            f="organisation",
            args=["[id]", "human_resource"],
        )
        htable = s3db.hrm_human_resource
        field = htable.organisation_id
        field.represent = s3db.org_OrganisationRepresent(
            show_link=True,
            linkto=linkto,
        )

        # Retrieve details for the rheader
        data = resource.select(
            [
                "human_resource.job_title_id",
                "human_resource.organisation_id",
            ],
            raw_data=True,
            represent=True,
        )
        row = data.rows[0]
        raw = row["_row"]

        # Construct subtitle
        organisation_id = raw["hrm_human_resource.organisation_id"]
        if organisation_id:
            subtitle = row["hrm_human_resource.organisation_id"]
            job_title_id = raw["hrm_human_resource.job_title_id"]
            if job_title_id:
                subtitle = TAG[""](
                    "%s, " % row["hrm_human_resource.job_title_id"],
                    subtitle,
                )

        # Compose the rheader
        rheader = DIV(DIV(
            H1(title),
            H2(subtitle),
            _class="rheader-details",
        ), )

    if tabs:
        rheader_tabs = s3_rheader_tabs(r, tabs)
        rheader.append(rheader_tabs)

    return rheader
Exemplo n.º 23
0
def mavc_rheader(r, tabs=None):
    """ Custom rheaders """

    if r.representation != "html":
        return None

    from s3 import s3_rheader_resource, s3_rheader_tabs
    from gluon import A, DIV, H1, H2, TAG

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

    T = current.T
    s3db = current.s3db

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

    rheader = ""

    if tablename == "org_organisation":

        # Tabs
        if not tabs:
            INDIVIDUALS = current.deployment_settings.get_hrm_staff_label()

            tabs = [
                (T("About"), None),
                (INDIVIDUALS, "human_resource"),
                (T("Services"), "service_location"),
                (T("Facilities"), "facility"),
                (T("Projects"), "project"),
            ]

        # Use OrganisationRepresent for title to get L10n name if available
        represent = s3db.org_OrganisationRepresent(
            acronym=False,
            parent=False,
        )
        title = represent(record.id)

        # Retrieve details for the rheader
        data = resource.select(
            [
                "organisation_organisation_type.organisation_type_id",
                "country",
                "website",
            ],
            raw_data=True,
            represent=True,
        )
        row = data.rows[0]
        raw = row["_row"]

        # Construct subtitle
        subtitle_fields = (
            "org_organisation_organisation_type.organisation_type_id",
            "org_organisation.country",
        )
        items = []
        for fname in subtitle_fields:
            if raw[fname]:
                items.append(s3_unicode(row[fname]))
        subtitle = ", ".join(items)

        # Website
        website = row["org_organisation.website"]

        # Compile the rheader
        rheader = DIV(
            DIV(
                H1(title),
                H2(subtitle),
                website if record.website else "",
                _class="rheader-details",
            ), )

    if tabs:
        rheader_tabs = s3_rheader_tabs(r, tabs)
        rheader.append(rheader_tabs)

    return rheader
Exemplo n.º 24
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,
                                                         )
Exemplo n.º 25
0
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