@staticmethod
    def _create_popup(r, widget, list_id, resource, context, numrows):
        """
            Render an action link for a create-popup (used in data lists
            and data tables).

            @param r: the S3Request instance
            @param widget: the widget definition as dict
            @param list_id: the list ID
            @param resource: the target resource
            @param context: the context filter
            @param numrows: the total number of rows in the list/table
        """

        create = ""

        insert = widget.get("insert", True)
        if not insert:
            return create

        table = resource.table
        tablename = resource.tablename

        # Default to primary REST controller for the resource being added
        c, f = tablename.split("_", 1)
        create_controller = widget.get("create_controller")
        if create_controller:
            c = create_controller
        create_function = widget.get("create_function")
        if create_function:
            f = create_function

        permit = current.auth.s3_has_permission
        create_ok = permit("create", table, c=c, f=f)
        if create_ok:
            if not create_controller or not create_function:
                # Assume not component context
                create_ok = permit("update", r.table, record_id=r.id, c=c, f=f)
        if create_ok:
            #if tablename = "org_organisation":
                # @ToDo: Special check for creating resources on Organisation profile

            # URL-serialize the widget filter
            widget_filter = widget.get("filter")
            if widget_filter:
                url_vars = widget_filter.serialize_url(resource)
            else:
                url_vars = Storage()

            # URL-serialize the context filter
            if context:
                filters = context.serialize_url(resource)
                for selector in filters:
                    url_vars[selector] = filters[selector]

            # URL-serialize the widget default
            default = widget.get("default")
            if default:
                k, v = default.split("=", 1)
                url_vars[k] = v

            # URL-serialize the list ID (refresh-target of the popup)
            url_vars.refresh = list_id

            # Indicate that popup comes from profile (and which)
            url_vars.profile = r.tablename

            # CRUD string
            label_create = widget.get("label_create", None)
            # Activate if-required
            #if label_create and isinstance(label_create, basestring):
            if label_create:
                label_create = current.T(label_create)
            else:
                label_create = S3CRUD.crud_string(tablename, "label_create")

            # Popup URL
            component = widget.get("create_component", None)
            if component:
                args = [r.id, component, "create.popup"]
            else:
                args = ["create.popup"]
            add_url = URL(c=c, f=f, args=args, vars=url_vars)

            if callable(insert):
                # Custom widget
                create = insert(r, list_id, label_create, add_url)

            elif current.deployment_settings.ui.formstyle == "bootstrap":
                # Bootstrap-style action icon
                create = A(ICON("plus-sign", _class="small-add"),
                           _href=add_url,
                           _class="s3_modal",
                           _title=label_create,
                           )
            else:
                # Standard action button
                create = A(label_create,
                           _href=add_url,
                           _class="action-btn profile-add-btn s3_modal",
                           )

            if widget.get("type") == "datalist":

                # If this is a multiple=False widget and we already
                # have a record, we hide the create-button
                multiple = widget.get("multiple", True)
                if not multiple and hasattr(create, "update"):
                    if numrows:
                        create.update(_style="display:none")
                    else:
                        create.update(_style="display:block")
                    # Script to hide/unhide the create-button on Ajax
                    # list updates
                    createid = create["_id"]
                    if not createid:
                        createid = "%s-add-button" % list_id
                        create.update(_id=createid)
                    script = \
'''$('#%(list_id)s').on('listUpdate',function(){
$('#%(createid)s').css({display:$(this).datalist('getTotalItems')?'none':'block'})
})''' % dict(list_id=list_id, createid=createid)
                    current.response.s3.jquery_ready.append(script)

        return create

# END =========================================================================
dataset/ETHPy150Open sahana/eden/modules/s3/s3profile.py/S3Profile._create_popup/original