so, if I do print the form, I do get a full detail (which should be a
good thing). but, if I look at the indivifual items, I get nothing....
record:
None
form.vars:
<Storage {}>
form.vars.User_id:
None
request.vars.id:
None
Now, I am stumped :(
On Sep 27, 1:58 pm, mart <[email protected]> wrote:
> so, I'm looking... still can't see why I get a new row as opposed to
> an updated one... Obviously, I am doing something wrong, but can't see
> it. I'm thinking that the corresponding user ID has to be pre-
> populated? Then again, maybe not... do I need to get the target
> table's row ID before I submit and force it to work on that row
> instead of creating a new one?
>
> Thanks,
> Mart :)
>
> On Sep 27, 12:59 pm, mart <[email protected]> wrote:
>
> > You are very correct, my row is None (and I should have checked this
> > before sending all those lines of sad looking code ;) )
>
> > row:
> > None
>
> > Thanks,
> > Mart :)
>
> > On Sep 27, 12:53 pm, mart <[email protected]> wrote:
>
> > > here I go (hope there is enough room here...), and yes, I know it
> > > looks sad ;):
>
> > > Controller:
>
> > > ## -*- coding: utf-8 -*-
>
> > > #########################################################################
> > > ## This is a samples controller
> > > ## - index is the default action of any application
> > > ## - user is required for authentication and authorization
> > > ## - download is for downloading files uploaded in the db (does
> > > streaming)
> > > ## - call exposes all registered services (none by default)
> > > #########################################################################
>
> > > import os, sys, string, re
> > > from collections import deque
>
> > > @auth.requires_login()
> > > def index():
> > > """
> > > example action using the internationalization operator T and flash
> > > rendered by views/default/index.html or views/generic.html
> > > """
> > > #response.flash = T('P4 user account cleanup!')
>
> > > return dict()
>
> > > @auth.requires_login()
> > > def test():
> > > return(dict)
>
> > > def data():
> > > return dict(form=crud())
>
> > > '''
> > > def populateP4Users():
> > > # proposed list to start -> suspect MANY more to come
> > > non_active_list = [
> > > 'benoit.nadeau',
> > > 'bernard.sjiariel',
> > > 'binh.dang',
> > > 'bulucc',
> > > 'craigt',
> > > 'davidk',
> > > 'gabriels',
> > > 'kevin',
> > > 'kyans',
> > > 'max',
> > > 'mikem',
> > > 'nam.phan',
> > > 'nguyen.tran',
> > > 'nirbhay.vashi',
> > > 'rachel',
> > > 'rachelv',
> > > 'reuben',
> > > 'ron.prior',
> > > 'sanamm',
> > > 'sang.vo',
> > > 'thinh.phan',
> > > 'tom.zhang',
> > > 'trang.mai',
> > > 'van.nguyen',
> > > 'vesna.cakarevic',
> > > 'will',
> > > 'yosef',
> > > 'yuehuay'
> > > ]
>
> > > form = SQLFORM(db.p4users)
> > > if form.accepts(request.vars, session, dbio=False):
> > > response.flash = T('in populateP4Users!')
> > > f = open('./p4users.txt', 'r')
> > > users = f.readlines()
> > > f.close()
> > > uInfo = deque()
> > > garbageList = deque()
> > > for user in users:
> > > uDictList = {}
> > > one = string.split(user, '<')
> > > if one:
> > > p4UserStatus = None
> > > strP4_user = string.strip(one[0])
> > > two = string.split(one[1],'>')
> > > strMail = string.strip(two[0])
> > > three = string.split(two[1],'(')
> > > four = string.split(user, '(')
> > > [1]
> > > strName = string.split(four,')')[0]
> > > last_accessDate = string.split(three[1],')')[1]
> > > date = string.split(last_accessDate,'accessed')[1]
> > > strAccessed = string.strip(date,'\\n')
> > > if not 'tao' in user or not 'error:' in user:
> > > if strP4_user in non_active_list:
> > > p4UserStatus = 1
>
> > > db.p4users.insert(p4_user=strP4_user,mail=strMail,p4_name=strName,accessed=strAccessed,p4status=p4UserStatus)
>
> > > SQLFORM(table, record=None, deletable=False,
> > > linkto=None, upload=None, fields=None, labels=None, col3={},
> > > submit_button='Submit', delete_label='Check to delete:',
> > > id_label='Record id: ', showid=True,
> > > readonly=False, comments=True, keepopts=[],
> > > ignore_rw=False, formstyle='table3cols',**attributes)
>
> > > '''
> > > def update_user():
> > > form = SQLFORM(db.p4users_all,record)
> > > if form.accepts(request.vars, session, dbio=False):
> > > if form.vars.get('delete_this_record', False):
> > > db(db.person.id==record.id).delete()
> > > else:
> > > record.update_record(**dict(form.vars))
> > > response.flash = 'record updated'
>
> > > def edit():
> > > row = db.p4users_all[request.args(0)]
> > > form = SQLFORM(db.p4users_all, row, deletable=True)
> > > if form.accepts(request.vars, session):
> > > response.flash = 'record updated'
> > > return dict(form=form)
>
> > > def display_form():
> > > # record = db.p4users_all(request.args(0))
> > > row = db.p4users_all[request.args(0)]
> > > form = SQLFORM(db.p4users_all, row, deletable=True)
> > > form.vars.id = request.vars.id
> > > if form.accepts(request.vars, session):
>
> > > response.flash = 'form accepted'
> > > elif form.errors:
> > > response.flash = 'form has errors'
> > > return dict(form=form)
>
> > > def countUsers():
> > > pass # will do this later -> for pie chart
>
> > > '''
>
> > > didn't work out -> page for for update wasn't 'pretty'
> > > '''
> > > @auth.requires_login()
> > > def p4():
> > > grid = webgrid.WebGrid(crud)
> > > grid.crud_function = 'data'
> > > grid.datasource = db(db.p4users.p4status==db.p4Status.id)
> > > grid.pagesize = 200
> > > grid.fields = ['p4users.id',
> > > 'p4users.p4_user',
> > > 'p4users.mail',
> > > 'p4users.p4_name',
> > > 'p4users.accessed',
> > > 'p4users.p4status',
> > > 'p4users.license_status',
> > > 'p4users.comments']
> > > # grid.filters =
> > > ['summitTrackableItems.responsible','summitTrackableItems.status']
> > > grid.filters = ['p4users.p4status']
> > > grid.filter_query = lambda f, v: f >= v
> > > return dict(grid=grid())
>
> > > def user():
> > > """
> > > exposes:
> > > http://..../[app]/default/user/login
> > > http://..../[app]/default/user/logout
> > > http://..../[app]/default/user/register
> > > http://..../[app]/default/user/profile
> > > http://..../[app]/default/user/retrieve_password
> > > http://..../[app]/default/user/change_password
> > > use @auth.requires_login()
> > > @auth.requires_membership('group name')
> > > @auth.requires_permission('read','table name',record_id)
> > > to decorate functions that need access control
> > > """
> > > return dict(form=auth())
>
> > > def download():
> > > """
> > > allows downloading of uploaded files
> > > http://..../[app]/default/download/[filename]
> > > """
> > > return response.download(request,db)
>
> > > def call():
> > > """
> > > exposes services. for example:
> > > http://..../[app]/default/call/jsonrpc
> > > decorate with @services.jsonrpc the functions to expose
> > > supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
> > > """
> > > session.forget()
> > > return service()
>
> > > Model:
>
> > > # -*- coding: utf-8 -*-
>
> > > #########################################################################
> > > ## This scaffolding model makes your app work on Google App Engine too
> > > #########################################################################
>
> > > if request.env.web2py_runtime_gae: # if running on Google
> > > App Engine
> > > db = DAL('gae') # connect to Google
> > > BigTable
> > > session.connect(request, response, db = db) # and store sessions
> > > and tickets there
> > > ### or use the following lines to store sessions in Memcache
> > > # from gluon.contrib.memdb import MEMDB
> > > # from google.appengine.api.memcache import Client
> > > # session.connect(request, response, db = MEMDB(Client()))
> > > else: # else use a normal
> > > relational database
> > > db = DAL('sqlite://storage.sqlite') # if not, use SQLite or
> > > other DB
> > > ## if no need for session
> > > # session.forget()
>
> ...
>
> read more »