Two problems: 1) userSoftware references the release date by id not by actual date 2) db().select() returns Rows object (like a list) not a single record
Here is a fix: appVer = db(db.version.fileS == request.args(0)).select(db.version.id).first() if not (db(queryID).update(Filename=request.args(0))) : db.userSoftware.insert(user_id =auth.user_id,Filename=request.args(0),Release_Date=appVer.id) On Mar 21, 1:12 pm, Matthew McNaughton <mamcnaugh...@gmail.com> wrote: > Thanks for all the help so far! Now that I got the userID and filename > in the table, I'm having problems populating the other fields. I have > been trying to run queries, but i'm not sure I completely understand the > syntax allowed in the controller yet. Eitherway, these are the last two > issues I've been having: > > Recall the models: > ------------------------------------ > db.define_table('version', > Field('application_id', db.application), > Field('vers'), > Field('Release_Date', 'date'), > Field('opSystem'), > Field('reqs'), > Field('changeLog', 'text'), > Field('fileS', 'upload')) > > db.define_table('userSoftware', > Field('user_id', db.auth_user, writable=False), > Field('application_id', db.application), > Field('version_id', db.version), > Field('Release_Date', db.version), > Field('Filename')) > ------------------------------ > > I tried the following: > ------------------------------ > appVer = db(db.version.fileS == > request.args(0)).select(db.version.Release_Date) > > if not (db(queryID).update(Filename=request.args(0))) : > db.userSoftware.insert(user_id = > auth.user_id,Filename=request.args(0), Release_Date=appVer.Release_Date) > ------------------------------- > > I keep getting the follow traceback, which states that no field > 'Release_Date' exists > > Traceback (most recent call last): > File "/home/matthewm/Downloads/web2py/gluon/restricted.py", line 173, in > restricted > exec ccode in environment > File > "/home/matthewm/Downloads/web2py/applications/Amso/controllers/default.py", > line 147, in <module> > File "/home/matthewm/Downloads/web2py/gluon/globals.py", line 96, in > <lambda> > self._caller = lambda f: f() > File "/home/matthewm/Downloads/web2py/gluon/tools.py", line 1864, in f > return action(*a, **b) > File > "/home/matthewm/Downloads/web2py/applications/Amso/controllers/default.py", > line 82, in download > db.userSoftware.insert(user_id = auth.user_id,Filename=request.args(0), > Release_Date=appVer.Release_Date) > AttributeError: 'Rows' object has no attribute 'Release_Date' > > Any idea why that is the case? > > On Sun, 2010-03-21 at 07:35 -0700, mdipierro wrote: > > The problem is tht db(query).update(field=value) but you seem to have > > query where field=value goes. Try this: > > > db.define_table('userSoftware', > > Field('user_id', db.auth_user), > > Field('filename')) > > > def donwload(): > > query = db.userSoftware.user_id == auth.user_id > > if not db(query).update(filename=request.args(0)): > > db.userSoftware.insert(user_id = > > auth.user_id,filename=request.args(0)) > > return response.download(request,db) > > > there is only request.args(0) in your case not request.args(1), etc. > > > On Mar 21, 2:53 am, Matthew McNaughton <mamcnaugh...@gmail.com> wrote: > > > Ok, so I'm trying to create a Download function that keeps track of the > > > files that the user downloads and updates a database table. > > > > The database model is: > > > ------------------------------------------------ > > > db.define_table('userSoftware', > > > Field('user_id', db.auth_user), > > > Field('application_id', db.application), > > > Field('version_id', db.version), > > > Field('Release_Date', db.version)) > > > ----------------------------------------------- > > > > I'm trying to write a Download function that will update the above table > > > with the a new row if it is a new file that the user is downloading. My > > > current download function is below: > > > ------------------------------- > > > def downloadApp(): > > > if((db(db.userSoftware.user_id == auth.id).count())==0) : > > > db().update(db.userSoftware.user_id = auth.user_id) > > > else: > > > # db().update(db.userSoftware.user_id = auth.user_id) > > > > return response.download(request,db) > > > ------------------------------- > > > > The reason I haven't been able to get much farther than this is because > > > I get the following traceback error: > > > ------------------------------- > > > Traceback (most recent call last): > > > File "/home/matthewm/Downloads/web2py/gluon/restricted.py", line 171, > > > in restricted > > > ccode = compile(code.replace('\r\n', '\n'), layer, 'exec') > > > File > > > "/home/matthewm/Downloads/web2py/applications/Amso/controllers/default.py", > > > line 43 > > > db().update(db.userSoftware.user_id = auth.user_id) > > > SyntaxError: keyword can't be an expression > > > > I'm not really what the syntax error is complaining about. > > > Also what are the different arguments that are request.args? Massimo > > > mentioned > > > that request.args[0] was the filename. What are the others? > > > > Thank you again for all the assistance. > > > > On Sat, 2010-03-20 at 10:42 -0700, mdipierro wrote: > > > > You can put them in db.py after auth=..., or in a registration > > > > controller or simply in the user() action. As long as they are > > > > executed before the registration form runs. > > > > > Massimo > > > > > On Mar 20, 12:30 pm, Matthew McNaughton <mamcnaugh...@gmail.com> > > > > wrote: > > > > > DO the commands in 1) go into the db.py after auth=Auth(globals(),db) > > > > > or > > > > > in a new controller that is created for user registration? > > > > > > On Sat, 2010-03-20 at 08:03 -0700, mdipierro wrote: > > > > > > Good questions: > > > > > > > 1) > > > > > > > if not db(db.auth_group.role=='users').count(): > > > > > > db.auth_group.insert(role='users') > > > > > > auth.settings.register_onaccept=lambda form: > > > > > > auth.add_membership(auth.id_group('users'),form.vars.id) > > > > > > > 2) > > > > > > Not sure what you mean by file renaming. Can you explain more? > > > > > > To keep track of downloads create your own download function > > > > > > > def download(): > > > > > > ### log the download, filename is in request.args(0) and user in > > > > > > auth.user_id > > > > > > return response.download(request,db) > > > > > > > On Mar 20, 2:11 am, Matthew McNaughton <mamcnaugh...@gmail.com> > > > > > > wrote: > > > > > > > Greetings all, > > > > > > > I've read the access control section in book a couple times over, > > > > > > > and I > > > > > > > still can't completely figure out authorization. I want to do the > > > > > > > following: > > > > > > > I want to add all newly registered users to a specific group > > > > > > > called > > > > > > > "users", which I have already created in auth_groups > > > > > > > > I have another group called "admin" which can add records to the > > > > > > > various > > > > > > > databases. The only way to begin this user is use the web2py > > > > > > > administrator login. Where do I put the access privileges for this > > > > > > > group? > > > > > > > > A related question. If I have certain files that the user can > > > > > > > upload and > > > > > > > download. How do i manage the file renaming in the mysql db? > > > > > > > Also, how > > > > > > > do I keep track of the files that a user download from the server. > > > > > > > > I apologize for the newb questions. Thank you again for all the > > > > > > > help so > > > > > > > far. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.