Instead, why not make it more general and simply allow the linkto lambda to 
return an (r, href) tuple, where r could be an IMG object or anything else. 
Something like:

elif linkto and field.type == 'id':
    try:
        href = linkto(r, 'table', tablename)
        if isinstance(href, (list, tuple)):
            r, href = href

Then we don't need a new argument -- all the work can be done in the linkto 
function.

Anthony

On Wednesday, November 30, 2011 8:01:18 PM UTC-5, Alan Etkin wrote:
>
> I think that it would be practical to have the option when calling
> SQLTABLE to specify images in place of id links.
>
> Here is how i would change it (seems to work with version 1.99.2)
>
> diff -r 7dd85a51bb2a gluon/sqlhtml.py
> --- a/gluon/sqlhtml.py Tue Nov 29 22:32:30 2011 -0600
> +++ b/gluon/sqlhtml.py Wed Nov 30 21:50:01 2011 -0300
> @@ -1972,6 +1972,7 @@
>      optional arguments:
>
>      :param linkto: URL (or lambda to generate a URL) to edit
> individual records
> +    :param imagelink: URL of an image to wrap the linkto field
>      :param upload: URL to download uploaded files
>      :param orderby: Add an orderby link to column headers.
>      :param headers: dictionary of headers to headers redefinions
> @@ -2043,6 +2044,7 @@
>          self,
>          sqlrows,
>          linkto=None,
> +        imagelink=None,
>          upload=None,
>          orderby=None,
>          headers={},
> @@ -2146,7 +2148,7 @@
>                          href = linkto(r, 'table', tablename)
>                      except TypeError:
>                          href = '%s/%s/%s' % (linkto, tablename,
> r_old)
> -                    r = A(r, _href=href)
> +                    r = self.image_link(r, href, imagelink)
>                  elif field.type.startswith('reference'):
>                      if linkto:
>                          ref = field.type[10:]
> @@ -2247,6 +2249,14 @@
>
>          return css
>
> +
> +    def image_link(self, r, href, imagelink):
> +        if isinstance(imagelink, basestring):
> +            return A(IMG(_src=imagelink, _alt=r), _href=href)
> +        else:
> +            return A(r, _href=href)
> +
> +
>  form_factory = SQLFORM.factory # for backward compatibility,
> deprecated
>
>
>

Reply via email to