def template():

    atable = s3db.cap_alert
    s3.filter = (atable.is_template == True)

    viewing = request.vars["viewing"]
    tablename = "cap_alert"

    if viewing:
        table, _id = viewing.strip().split(".")
        if table == tablename:
            redirect(URL(c="cap", f="template", args=[_id]))

    def prep(r):
        list_fields = ["template_title",
                       "identifier",
                       "info.event_type_id",
                       "scope",
                       "incidents",
                       "info.category",
                       ]

        s3db.configure(tablename,
                       list_fields = list_fields,
                       list_orderby = "cap_info.event_type_id desc",
                       orderby = "cap_info.event_type_id desc",
                       )
        if r.representation == "xls":
            r.table.scope.represent = None
            r.table.incidents.represent = None
            list_fields = [(T("ID"), "id"),
                           "template_title",
                           "scope",
                           "restriction",
                           "note",
                           "incidents",
                           ]

            s3db.configure(tablename,
                           list_fields = list_fields,
                           )
        for f in ("identifier", "msg_type"):
            field = atable[f]
            field.writable = False
            field.readable = False
            field.requires = None
        atable.template_title.requires = IS_NOT_EMPTY()
        atable.status.readable = atable.status.writable = False

        if r.component_name == "info":
            itable = r.component.table
            for f in ("event",
                      "urgency",
                      "certainty",
                      "priority",
                      "severity",
                      "effective",
                      "onset",
                      "expires",
                      "web",
                      ):
                field = itable[f]
                field.writable = False
                field.readable = False
                field.required = False

            itable.category.required = False

            alert_id = request.args(0)
            # Check for prepopulate
            if alert_id:
                itable.web.default = settings.get_base_public_url()+\
                                     URL(c="cap", f="alert", args=alert_id)
                row = db(atable.id == alert_id).select(atable.event_type_id,
                                                       limitby=(0, 1)).first()
                itable.event_type_id.default = row.event_type_id

        elif r.component_name == "resource":
            rtable = r.component.table

            # Set is_template to true as only accessed by template
            rtable.is_template.default = True

        s3.crud_strings[tablename] = Storage(
            label_create = T("Create Template"),
            title_display = T("Template"),
            title_list = T("Templates"),
            title_update = T("Edit Template"), # If already-published, this should create a new "Update" alert instead of modifying the original
            title_upload = T("Import Templates"),
            label_list_button = T("List Templates"),
            label_delete_button = T("Delete Template"),
            msg_record_created = T("Template created"),
            msg_record_modified = T("Template modified"),
            msg_record_deleted = T("Template deleted"),
            msg_list_empty = T("No templates to show"))

        if r.representation == "html":
            s3.scripts.append("/%s/static/scripts/json2.min.js" % appname)
            if s3.debug:
                s3.scripts.append("/%s/static/scripts/S3/s3.cap.js" % appname)
            else:
                s3.scripts.append("/%s/static/scripts/S3/s3.cap.min.js" % appname)
            s3.stylesheets.append("S3/cap.css")

        elif r.representation == "json":
            # @ToDo: fix JSON representation's ability to use component list_fields
            list_fields = ["id",
                           "template_title",
                           "scope",
                           "sender",
                           "info.category",
                           "info.description",
                           "info.event_type_id",
                           "info.headline",
                           "info.response_type",
                           "info.sender_name",
                           ]

            s3db.configure(tablename,
                           list_fields = list_fields,
                           )

        return True
    s3.prep = prep

    def postp(r,output):
        lastid = r.resource.lastid
        if lastid:
            itable = s3db.cap_info
            row = db(itable.alert_id == lastid).select(itable.id,
                                                       limitby=(0, 1)).first()
            if row:
                r.next = URL(c="cap", f="template", args=[lastid, "info"])
            else:
                r.next = URL(c="cap", f="template", args=[lastid, "info", "create"])

        if r.interactive and "form" in output:
            if get_vars.get("_next"):
                r.next = get_vars.get("_next")

            s3.js_global.append('''i18n.cap_locked="%s"''' % T("Locked"))
            tablename = r.tablename
            if tablename == tablename:
                output["form"].add_class("cap_template_form")
            elif tablename == "cap_info":
                output["form"].add_class("cap_info_template_form")
        return output
    s3.postp = postp

    output = s3_rest_controller("cap", "alert",
                                rheader = s3db.cap_rheader)
    return output

# -----------------------------------------------------------------------------
Determine if 'library' is available to be linked against,
dataset/ETHPy150Open sahana/eden/controllers/cap.py/template--crossover with--dataset/ETHPy150Open babble/babble/include/jython/Lib/distutils/command/config.py/config.check_lib