Example #1
0
    def person_deduplicate(item):
        """
            Wrapper for person deduplicator to identify person
            records, but preventing actual imports of persons
        """

        # Run standard person deduplication
        if deduplicate:
            deduplicate(item)

        # Person not found?
        if item.method != item.METHOD.UPDATE:

            # Provide some meaningful details of the failing
            # person record to facilitate correction of the source:
            from s3 import s3_unicode
            person_details = []
            append = person_details.append
            data = item.data
            for f in ("pe_label", "last_name", "first_name", "date_of_birth"):
                value = data.get(f)
                if value:
                    append(s3_unicode(value))
            error = "Person not found: %s" % ", ".join(person_details)
            item.error = error
            item.element.set(current.xml.ATTRIBUTE["error"], error)

            # Reject any new person records
            item.accepted = False

        # Skip - we don't want to update person records here
        item.skip = True
        item.method = None
Example #2
0
File: dvr.py Project: nursix/eden
    def person_deduplicate(item):
        """
            Wrapper for person deduplicator to identify person
            records, but preventing actual imports of persons
        """

        # Run standard person deduplication
        if deduplicate:
            deduplicate(item)

        # Person not found?
        if item.method != item.METHOD.UPDATE:

            # Provide some meaningful details of the failing
            # person record to facilitate correction of the source:
            from s3 import s3_unicode
            person_details = []
            append = person_details.append
            data = item.data
            for f in ("pe_label", "last_name", "first_name", "date_of_birth"):
                value = data.get(f)
                if value:
                    append(s3_unicode(value))
            error = "Person not found: %s" % ", ".join(person_details)
            item.error = error
            item.element.set(current.xml.ATTRIBUTE["error"], error)

            # Reject any new person records
            item.accepted = False

        # Skip - we don't want to update person records here
        item.skip = True
        item.method = None
Example #3
0
def write_details_to_csv(csv_file, statistic, data):
    cnt = 0
    writerow = csv_file.writerow
    for (location, details) in data.items():
        loc = location_list[location]
        for key in sorted(details.keys()):
            row = details[key]
            source = row[2]
            source_url = ""
            url = urlparse(source)
            if url[0] != "":
                source_url = source
                (head, tail) = split(url[2])
                source = tail.replace("%20", " ")
            cnt += 1
            writerow([statistic, row[0], loc[0], loc[1], loc[2], loc[3], key, s3_unicode(source).encode("utf-8"), row[1], source_url])
Example #4
0
def write_details_to_csv(csv_file, statistic, data):
    cnt = 0
    writerow = csv_file.writerow
    for (location, details) in data.items():
        loc = location_list[location]
        for key in sorted(details.keys()):
            row = details[key]
            source = row[2]
            source_url = ""
            url = urlparse(source)
            if url[0] != "":
                source_url = source
                (head, tail) = split(url[2])
                source = tail.replace("%20", " ")
            cnt += 1
            writerow([statistic, row[0], loc[0], loc[1], loc[2], loc[3], key, s3_unicode(source).encode("utf-8"), row[1], source_url])
Example #5
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
Example #6
0
    def rdrt_member_profile_header(r):
        """ Custom profile header to allow update of RDRT roster status """

        record = r.record
        if not record:
            return ""

        person_id = record.person_id
        from s3 import s3_fullname, s3_avatar_represent
        name = s3_fullname(person_id)

        table = r.table

        # Organisation
        comments = table.organisation_id.represent(record.organisation_id)

        from s3 import s3_unicode
        from gluon.html import A, DIV, H2, LABEL, P, SPAN

        # Add job title if present
        job_title_id = record.job_title_id
        if job_title_id:
            comments = (SPAN("%s, " % \
                             s3_unicode(table.job_title_id.represent(job_title_id))),
                             comments)

        # Determine the current roster membership status (active/inactive)
        atable = current.s3db.deploy_application
        status = atable.active
        query = atable.human_resource_id == r.id
        row = current.db(query).select(atable.id,
                                       atable.active,
                                       limitby=(0, 1)).first()
        if row:
            active = 1 if row.active else 0
            status_id = row.id
            roster_status = status.represent(row.active)
        else:
            active = None
            status_id = None
            roster_status = current.messages.UNKNOWN_OPT

        if status_id and \
           current.auth.s3_has_permission("update",
                                          "deploy_application",
                                          record_id=status_id):
            # Make inline-editable
            roster_status = A(roster_status,
                              data = {"status": active},
                              _id = "rdrt-roster-status",
                              _title = T("Click to edit"),
                              )
            s3 = current.response.s3
            script = "/%s/static/themes/IFRC/js/rdrt.js" % r.application
            if script not in s3.scripts:
                s3.scripts.append(script)
            script = '''$.rdrtStatus('%(url)s','%(active)s','%(inactive)s','%(submit)s')'''
            from gluon import URL
            options = {"url": URL(c="deploy", f="application",
                                  args=["%s.s3json" % status_id]),
                       "active": status.represent(True),
                       "inactive": status.represent(False),
                       "submit": T("Save"),
                       }
            s3.jquery_ready.append(script % options)
        else:
            # Read-only
            roster_status = SPAN(roster_status)

        # Render profile header
        return DIV(A(s3_avatar_represent(person_id,
                                         tablename="pr_person",
                                         _class="media-object",
                                         ),
                     _class="pull-left",
                     ),
                   H2(name),
                   P(comments),
                   DIV(LABEL(status.label + ": "), roster_status),
                   _class="profile-header",
                   )
Example #7
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
Example #8
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