Пример #1
0
def s3_lx_update(table, record_id):
    """
        Write the Lx fields from the Location
        - used by hrm_human_resource & pr_address

        @ToDo: Allow the reverse operation.
        If these fields are populated then create/update the location
    """

    if "location_id" in table:

        db = current.db
        ltable = current.s3db.gis_location
        query = (table.id == record_id) & (ltable.id == table.location_id)
        location = (
            db(query).select(ltable.id, ltable.name, ltable.level, ltable.parent, ltable.path, limitby=(0, 1)).first()
        )
        if location:
            vars = Storage()
            if location.level == "L0":
                vars.L0 = location.name
            elif location.level == "L1":
                vars.L1 = location.name
                if location.parent:
                    query = ltable.id == location.parent
                    country = db(query).select(ltable.name, limitby=(0, 1)).first()
                    if country:
                        vars.L0 = country.name
            else:
                # Get Names of ancestors at each level
                vars = current.gis.get_parent_per_level(vars, location.id, feature=location, ids=False, names=True)
            # Update record
            db(table.id == record_id).update(**vars)
Пример #2
0
def s3_address_update(table, record_id):
    """
        Write the Address fields from the Location
        - used by asset_asset

        @ToDo: Allow the reverse operation.
        If these fields are populated then create/update the location
    """

    if "location_id" in table:

        db = current.db
        ltable = current.s3db.gis_location
        # Read Postcode & Street Address
        query = (table.id == record_id) & \
                (ltable.id == table.location_id)
        location = db(query).select(ltable.id,
                                    ltable.addr_street,
                                    ltable.addr_postcode,
                                    ltable.name,
                                    ltable.level,
                                    ltable.parent,
                                    ltable.path,
                                    limitby=(0, 1)).first()
        if location:
            vars = Storage()
            vars.address = location.addr_street
            vars.postcode = location.addr_postcode
            if location.level == "L0":
                vars.L0 = location.name
            elif location.level == "L1":
                vars.L1 = location.name
                if location.parent:
                    query = (ltable.id == location.parent)
                    country = db(query).select(ltable.name,
                                               limitby=(0, 1)).first()
                    if country:
                        vars.L0 = country.name
            else:
                if location.level is None:
                    vars.building_name = location.name
                # Get Names of ancestors at each level
                vars = current.gis.get_parent_per_level(vars,
                                                        location.id,
                                                        feature=location,
                                                        ids=False,
                                                        names=True)
            # Update record
            db(table.id == record_id).update(**vars)
Пример #3
0
def s3_address_update(table, record_id):
    """
        Write the Address fields from the Location
        - used by asset_asset & hrm_human_resource

        @ToDo: Allow the reverse operation.
        If these fields are populated then create/update the location
    """

    if "location_id" in table:

        db = current.db
        ltable = current.s3db.gis_location
        # Read Postcode & Street Address
        query = (table.id == record_id) & \
                (ltable.id == table.location_id)
        location = db(query).select(ltable.id,
                                    ltable.addr_street,
                                    ltable.addr_postcode,
                                    ltable.name,
                                    ltable.level,
                                    ltable.parent,
                                    ltable.path,
                                    limitby=(0, 1)).first()
        if location:
            vars = Storage()
            vars.address = location.addr_street
            vars.postcode = location.addr_postcode
            if location.level == "L0":
                vars.L0 = location.name
            elif location.level == "L1":
                vars.L1 = location.name
                if location.parent:
                    query = (ltable.id == location.parent)
                    country = db(query).select(ltable.name,
                                               limitby=(0, 1)).first()
                    if country:
                        vars.L0 = country.name
            else:
                if location.level is None:
                    vars.building_name = location.name
                # Get Names of ancestors at each level
                vars = current.gis.get_parent_per_level(vars,
                                                        location.id,
                                                        feature=location,
                                                        ids=False,
                                                        names=True)
            # Update record
            db(table.id == record_id).update(**vars)
Пример #4
0
def s3_lx_update(table, record_id):
    """
        Write the Lx fields from the Location
        - used by hrm_human_resource & pr_address

        @ToDo: Allow the reverse operation.
        If these fields are populated then create/update the location
    """

    if "location_id" in table:

        db = current.db
        ltable = current.s3db.gis_location
        query = (table.id == record_id) & \
                (ltable.id == table.location_id)
        location = db(query).select(ltable.id,
                                    ltable.name,
                                    ltable.level,
                                    ltable.parent,
                                    ltable.path,
                                    limitby=(0, 1)).first()
        if location:
            vars = Storage()
            if location.level == "L0":
                vars.L0 = location.name
            elif location.level == "L1":
                vars.L1 = location.name
                if location.parent:
                    query = (ltable.id == location.parent)
                    country = db(query).select(ltable.name,
                                               limitby=(0, 1)).first()
                    if country:
                        vars.L0 = country.name
            else:
                # Get Names of ancestors at each level
                vars = current.gis.get_parent_per_level(vars,
                                                        location.id,
                                                        feature=location,
                                                        ids=False,
                                                        names=True)
            # Update record
            db(table.id == record_id).update(**vars)