[web2py] Re: CRUD read or OneToOne

2010-05-19 Thread mdipierro
I think you want to replace

form=crud.create(db.project_location)

with

location =
db(db.project_location.project==project_id).select().first()
form=crud.update(db.project_location,location)

if location is None, crud.update defaults to crud.create

On May 19, 8:57 am, greenpoise danel.sega...@gmail.com wrote:
 Hi there. I am a bit stuck here. ANy help greatly appreciated. I have
 this:

 @auth.requires_login()
 def crear_project_location():
     project_id=request.args(0)
     project=db.project[project_id]

     if project:
         db.project_location.project.default=project_id
         db.project_location.project.writable=False
         form=crud.create(db.project_location)

 projects=db(db.project_location.project==project.id).select(orderby=db.project_location.project)

     else:
         form=None

 projects=db(db.project_location.id0).select(orderby=db.project_location.name)
     return dict(project=project,projects=projects,form=form)

 It works perfect BUT it will always get me to a blank editable form
 due to the crud.create. I tried putting a crud.read. I want the user
 to click on the link and if there is already a project _location for a
 project then just display it (crud.read), if the project has no
 location associated, then it will give me crud.write. I know it must
 be simple but I cant figure it out.

 THanks


[web2py] Re: CRUD read or OneToOne

2010-05-19 Thread annet

 I want the user to click on the link and if there is already
 a project _location for a project then just display it (crud.read),
 if the project has no location associated, then it will give me
 crud.write. I know it must be simple but I cant figure it out.

I am not sure I do understand your problem correctly, but I'll give it
a try. You list projects, when the user clicks on one of the projects,
depending on the project's location being set or not you either
display the project's details or display an update form

@auth.requires_login()
def update_project_location():
projects=db(..).select(..)
form=[]
if request.args:
project_id=request.args(0)
project=db.project[project_id]
if project[0].location:
form=crud.read(db.project,project_id)
else:
form=crud.update(db.project,project_id)
return(projects=projects,form=form)


I hope this helps to point you in right direction.

Annet.


[web2py] Re: CRUD read or OneToOne

2010-05-19 Thread greenpoise
that did it. That was simpler than what I thought. Thanks


d

On May 19, 10:32 am, mdipierro mdipie...@cs.depaul.edu wrote:
 I think you want to replace

         form=crud.create(db.project_location)

 with

         location =
 db(db.project_location.project==project_id).select().first()
         form=crud.update(db.project_location,location)

 if location is None, crud.update defaults to crud.create

 On May 19, 8:57 am, greenpoise danel.sega...@gmail.com wrote:

  Hi there. I am a bit stuck here. ANy help greatly appreciated. I have
  this:

  @auth.requires_login()
  def crear_project_location():
      project_id=request.args(0)
      project=db.project[project_id]

      if project:
          db.project_location.project.default=project_id
          db.project_location.project.writable=False
          form=crud.create(db.project_location)

  projects=db(db.project_location.project==project.id).select(orderby=db.project_location.project)

      else:
          form=None

  projects=db(db.project_location.id0).select(orderby=db.project_location.name)
      return dict(project=project,projects=projects,form=form)

  It works perfect BUT it will always get me to a blank editable form
  due to the crud.create. I tried putting a crud.read. I want the user
  to click on the link and if there is already a project _location for a
  project then just display it (crud.read), if the project has no
  location associated, then it will give me crud.write. I know it must
  be simple but I cant figure it out.

  THanks


[web2py] Re: CRUD read or OneToOne

2010-05-19 Thread greenpoise
I did it the mdpierro way because just saw your post. Your way would
have worked too. Exactly what I wanted.

Thanks


On May 19, 10:36 am, annet annet.verm...@gmail.com wrote:
  I want the user to click on the link and if there is already
  a project _location for a project then just display it (crud.read),
  if the project has no location associated, then it will give me
  crud.write. I know it must be simple but I cant figure it out.

 I am not sure I do understand your problem correctly, but I'll give it
 a try. You list projects, when the user clicks on one of the projects,
 depending on the project's location being set or not you either
 display the project's details or display an update form

 @auth.requires_login()
 def update_project_location():
     projects=db(..).select(..)
     form=[]
     if request.args:
         project_id=request.args(0)
         project=db.project[project_id]
         if project[0].location:
             form=crud.read(db.project,project_id)
         else:
             form=crud.update(db.project,project_id)
     return(projects=projects,form=form)

 I hope this helps to point you in right direction.

 Annet.