Francisco Ribeiro | 21 Oct 16:53 2014
Picon

Re: Customizing generated columns from SQLFROM.grid

child's play!

Answer to my own question:
======================

on the db file, add the following:
def get_index(grid, colname):
   
return grid.rows.colnames.index(colname)


def apply_title_to_column(grid, title_list, column_number):
   
for cell,title in zip(grid[2][0][0][2], title_list):
       
if title is not None and str(title) != "<td></td>" and str(title) != "<td>None</td>":
            cell
[column_number]=TD(cell[column_number][0],_title=title)


def get_table_rows(grid):
   
return grid[2][0][0][2]


def get_column(grid, column_number):
   
return [row[column_number] for row in get_table_rows(grid)]


def remove_grid_column(grid, column_number):
   
del grid[2][0][0][0][column_number]
   
del grid[2][0][0][1][0][column_number]
   
for row in get_table_rows(grid):
       
del row[column_number]


def add_titles(grid):
    cols_to_delete
=[]
   
for colname in grid.rows.colnames:
       
if colname.endswith('_msg'):
            cols_to_delete
.append(get_index(grid, colname))
            title_list
= get_column(grid, get_index(grid, colname))
            apply_title_to_column
(grid, title_list,  get_index(grid, colname[:-4]))


   
for col_number in reversed(cols_to_delete):
        remove_grid_column
(grid, col_number)

# then on the controller you can have something like:
def housegrid():

    grid
=SQLFORM.smartgrid(db.house)
    add_titles
(grid)
   
return grid

# view code:
{{=LOAD('default','housegrid.load', ajax=True)}}

Notes:
  • this code is outrageous, egregious, preposterous but it works and it's quite modular if you want to use it for other changes like this.
  • one nice detail about this is that you can still make all your queries, including within the fields that are now only being shown on mouse hovering 
  • an alternative approach would be to use jQuery manipulations in the DOM but this looks a lot more resilient and decoupled from the view side of things
  • obviously, this uses internals that can be modified at any time so backward compatibility can not be assured even though this should be very rare.
  • it would be nice to have an API for grids. I think there is this big "jump" for database records to generated HTML code ready to be rendered, not so much control over the Application logic on it.

Kind regards,
Francisco 


On Saturday, 18 October 2014 15:00:33 UTC+1, Francisco Ribeiro wrote:
hello everyone,
I believe I have ran into a dead end but maybe one of you may find a way for what I'm trying to do. So, please consider this model:

db.define_table('house',
    Field('location_type', requires=IS_IN_SET(['city', 'country', 'sea'])),
    Field('location_type_msg'),
    Field('capacity', requires=IS_IN_SET(['single', 'couple', 'small family', 'big family']),
    Field('capacity_msg'))

you can see the pattern I used in the field names, "fieldname" followed by "fieldname_msg".

Now, what I want to do is to generate a grid with only two columns "location_type" and "capacity" where "location_type_msg" and "capacity_msg" would be accessible once you mouse hover  through their respective fields.

Example:

id | location_type | capacity
===========================
1  |     city             |       single
2  |     sea             |     small family

now if i go over the word 'city' I would see something like "New York" or "London" and if I mouse hover "small family" i would see something like "90 square meters"
hope it makes sense.

Thank you,
Kind regards
Francisco

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Manuele Pesenti | 21 Oct 11:44 2014
Picon

common way to star developing a new app

Hi!
Do you think it could be a good approach for starting to develop all my
web2py applications with predefined tools such as a logger and a test unit?
https://github.com/manuelep/web2py-new-app

Does anybody has a similar approach to share?
Thank you very mutch

    Manuele

--

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@...
For more options, visit https://groups.google.com/d/optout.

LoveWeb2py | 21 Oct 07:35 2014
Picon

did I structure my table and table reference wrong?

Hi... I'm trying to create a grading system where I can reference the questions_answered with the questions id.

I want to be able to load all of the questions from the first table and and see whether or not the student got them right in the second. If the student got them right I actually only want the title of the question and not the question itself but I never made a reference to it in my questions_answered. I do however have a "question" field in my questions_answered which references the questions table. Is there a way for me to pull the title as well?


db.define_table('questions',
                Field('id','integer'),
                Field('title','string'),
                Field('question','text'),
                Field('answer','string'),
                migrate=False)

db.define_table('questions_answered',
                Field('id','integer'),
                Field('question', type='reference questions',
                    requires=IS_EMPTY_OR(IS_IN_DB(db,db.uct_challenge.id,"%(question)s")),represent=lambda id, r: db.questions(id).question),
                Field('submitted','string', writable=False),
                Field('answered_by',db.auth_user),
                Field('correct','boolean'),
                format='%(name)s', migrate=True)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
David Ripplinger | 20 Oct 22:48 2014
Picon

unittest with multiple test files

Hi,

I'm using unittest in my app as suggested here, but I don't want all my tests to be in one file. As far as I can tell, my options are:
  1. Bite the bullet and put all tests in one file.
  2. Run each test file separately and have a shell script automate over all of them. The drawback here is I can't run them as one test suite.
  3. Put all test files in the modules folder so I can import them. The drawback here is I think that's a tacky file structure for my code. I'd rather have a test folder at the top level of the application to put stuff in.
Does anyone know of a way I can get it to work with multiple test files and putting them in whatever directory I wish? If not, any comments to the pros and cons of the above options? What setup do you use for testing?

David

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Picon

web2pyslices

Hi, I am trying to upload a plugin (for images thumbnails creation) to 
web2pyslices, but I uploaded it 6 days ago, and there is no errors, no 
notifications, and the only trace of my plugin is in activities, but if 
I click on it, sends me to the web2pyslices home page. It is normal, o 
there is something wrong?

--
Nunca digas nunca, di mejor: gracias, permiso, disculpe.

Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el
cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el
compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

--

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@...
For more options, visit https://groups.google.com/d/optout.

Spokes | 20 Oct 13:51 2014
Picon

Is it sensible to generate images on the fly/use a base64 string as image source?

For reasons of which I'm not totally sure, I was unable to use web2py's download function with a particular table's upload field. Consequently, I hacked my way around it by doing something like this:

def return_image_as_string(db, table_name, field_name, image_name):
   
import base64
    _
, stream = db[table_name][field_name].retrieve(image_name)
   
return 'data:image/png;base64,' + base64.b64encode(stream.read())

def myfunc():
    img
= IMG(..., _src = return_image_as_string(...))
   
...

Does it make sense to do this from the point of view of efficiency, security, functionality (i.e. will it work on all browsers?), etc...? If the idea is fundamentally sound, are there possible improvements to the above code?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
António Ramos | 20 Oct 12:12 2014
Picon

We could have something like this

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tony Huang | 18 Oct 04:26 2014
Picon

Change to postgresql database issue

Recently, I start to research web2py.
I type 'python web2py.py' to run web2py application, and create a new application name 'myapp'.
The default database is SQLite, and I can sing up new user successful.
However, it will crash when I change the database to postgresql.
The error is: <type 'exceptions.Exception'> Validation error, field:email <gluon.validators.IS_NOT_IN_DB object at 0x00000000043BC208>

I only modify the db.py model in myapp:
#db = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
db = DAL('postgres://postgres:1234-savSHZN5Fh8qMp+WYRx65w@public.gmane.org/mytestdb', pool_size=1,migrate_enabled=False)

Anybody can tell me what's going on and how to fix it?
Thanks!

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Jigar Mistry | 18 Oct 04:20 2014
Picon

Deployment

Hello everyone,

Is this possible to deploy single web2py app on nginx without web2py?



Thanks,
Jigar Mistry

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Spokes | 18 Oct 17:07 2014
Picon

Image not showing: NetworkError: 404 NOT FOUND

I'm doing something pretty routine in defining a db table in a class within a file in modules, and later, attempting to display an image associated with that table. The table is defined like so:

class Image:

   
def __init__(self, db, auth_signature, session, request, response):
       
...

       
if not 't_image' in db.tables:
           
self.db.define_table('t_image',      
               
Field('f_user_id', type="reference auth_user", readable=False, writable=False,
                       
default=session.auth.user.id if session.auth else ''),
               
Field('image',type="upload",
                      requires
= (IS_EMPTY_OR(IS_IMAGE(
                      error_message
= current.T('Error...'),
                      extensions
= ('jpeg','jpg','png','bmp','gif'), maxsize = (1200, 1200))),IS_LENGTH(524288)),
                      label
= current.T('Image'), autodelete = True, uploadseparate = True),  
                     
                     
...
                     
               
self.auth_signature)

In attempting to display the image, I'm doing something like this in a non-default controller (I tried the equivalent in the default controller, and that didn't change anything):
               
def show_user():
   
...
   
from user_custom import Image
    cl__image
= Image(db = db, auth_signature = auth.signature, session = session,
           request
= request, response = response)

    row__image
= db(db.t_image.f_user_id == user_id).select('image').first()
    image_filename
= row__image['image'] if row__image else None

    img
= DIV(IMG(_src = URL('default', 'download/' + image_filename, extension = False)))
   
...
   
return dict(img = img)

This produces a "NetworkError: 404 NOT FOUND" error. A blank image container appears on the screen, and examining it, the url that shows up looks reasonable, and seems to point to the appropriate file. Any ideas as to what could be going on and how to fix it? Thank you.
   

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Leonel Câmara | 18 Oct 13:42 2014
Picon

Re: Apostrophe causes new column in PYFPDF

Fix for web2py's side of the problem submitted:
https://github.com/web2py/web2py/pull/531

This fixes web2py's escaping of '&#x27;'.

On to fpdf unquoting stuff.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane