human
Complete this python program:
def location():
assistant
#Here is the Python code you requested.

    """RESTful CRUD controller
    """
    table = s3db.project_location
    def prep(r):
        if r.interactive:
            if r.record:
                table = s3db.project_sector_project
                query = ((table.project_id == r.record.project_id) & (table.deleted == False))
                rows = db(query).select(table.sector_id)
                sector_ids = [row.sector_id for row in rows]
            else:
                sector_ids = []
            set_activity_type_requires('project_activity_type_location', sector_ids)
            if (r.component_name == 'document'):
                table = db.doc_document
                table.organisation_id.readable = table.organisation_id.writable = False
                table.person_id.readable = table.person_id.writable = False
                table.location_id.readable = table.location_id.writable = False
        return True
    s3.prep = prep
    def postp(r, output):
        if (r.representation == 'plain'):
            item = TABLE()
            if settings.get_project_community():
                record = r.record
                table.id.readable = False
                table.location_id.readable = False
                fields = [table[f] for f in table.fields if table[f].readable]
                for field in fields:
                    data = record[field]
                    if data:
                        represent = field.represent
                        if represent:
                            item.append(TR(TD(field.label), TD(represent(data))))
                        else:
                            item.append(TR(TD(field.label), TD(data)))
                hierarchy = gis.get_location_hierarchy()
                gtable = s3db.gis_location
                location = db((gtable.id == record.location_id)).select(gtable.L1, gtable.L2, gtable.L3, gtable.L4).first()
                if location:
                    for field in ['L4', 'L3', 'L2', 'L1']:
                        if ((field in hierarchy) and location[field]):
                           ...