Hi Alex,

I didn't read carefully your code but just a couple advice...  With
SQLFORM.factory you need to insert you data yourself like this :

form =  SQLFORM.factory(db.your_table_name, ...)
if form.process().accept:
     id =
db.lotns_sample.insert(**db.your_table_name._filter_fields(form.vars))

You can re-use the id of inserted record when you use more than one table
in your SQLFORM.factory(db.table1, db.table2)...

This is covert in the book.

About you predefined choice from a all ready existing record (update mode
with .factory()), I you have to set the default value for the form base on
the value extract form the DB for the existing record...

Hope it helps.

Richard


On Thu, Sep 12, 2013 at 8:03 PM, Alex Glaros <alexgla...@gmail.com> wrote:

> Anybody see anything wrong with the second controller below that gets
> called by the first one?
>
> The error is that no data gets written to table IdeaComment, but if I
> substitute "smartgrid" for "factory", all suggestions instead of just the
> one selected in the first controller get displayed, and forces me to
> re-choose a suggestion, then it writes it correctly.
>
> No errors displayed when "factory" is used in second controller, but no
> record is written.
>
> Controller
>
> @auth.requires_login()
> def add_suggestion_comments(): ## This controller selects a suggestion
> record (db.Idea) and passes selection to controller comment_on_a_suggestion
> below.
>     db.Suggestion.ideaID.represent = lambda id, r:
> A(db.Idea(id).ideaTitle, _href=URL('comment_on_a_suggestion',
> vars=dict(filter=id)))
>     query = ((db.Suggestion.ideaID == db.Idea.id))
>     suggestionList =
> SQLFORM.grid(query,create=True,editable=True,deletable=True,
> details=True,links_in_grid=True, paginate=10,
>  fields=[db.Suggestion.ideaID, db.Idea.ideaShortSummary],
> maxtextlength={db.Idea.ideaShortSummary:140})
>     return dict(suggestionList = suggestionList)
>
> @auth.requires_login() ## This controller receives Idea.id parm from
> add_suggestion_comments controller above.  It then writes user comments to
> table db.IdeaComment
> def comment_on_a_suggestion():
>     db.IdeaComment.ideaID.readable = True
>     db.IdeaComment.ideaID.writable = False
>     db.auth_user.partyID.readable = db.auth_user.partyID.writable = False
>
>     db.IdeaComment.ideaID.default = request.vars.filter
>     db.IdeaComment.ideaStageID.default = 1  ##  make default 'Suggestion'
>
>     db.IdeaComment.ideaStageID.readable =
> db.IdeaComment.ideaStageID.writable = False
>     form=SQLFORM.factory(db.IdeaComment)
>     if form.process().accepted:
>         response.flash='Thanks for adding a comment to a suggestion.'
>     return dict(form=form)
>
>
> Model
>
> db.define_table('IdeaComment', ## lets any registered user make a commment
> on suggestion
> Field('ideaID','reference Idea'),
> Field('partyID','reference Party', label='Commenter', comment='Party that
> is commenting'), ## this is commenter.  Has to be logged on.
> Field('ideaStageID','reference IdeaStageLookupTable', comment='What stage
> of the idea do you want to comment on?  Suggestion, proposal, effort,
> project, program?'),
> Field('ideaComment','string', label='Comment', comment='Your comments'),
> Field('personClassCode','reference PersonClass', comment='In what capacity
> are you making this comment?'))
>
> ## ---------------------------------------------------
> db.define_table('Idea',
> Field('ideaTitle','string', length=140, label='Idea Title', comment='140
> characters max'),
> Field('ideaShortSummary','string', length=280, label='Summary info',
> comment='short summary - 280 characters max'),
> Field('ideaStageID','reference IdeaStageLookupTable', label='Idea Stage',
> comment='Idea stage may be part of a series of stages of an idea:
> Suggestion, Proposal, Effort, Project, and Program.  (1) Suggestion - The
> first time an idea is presented; the original concept (2) Proposal - a
> specific plan to fully implement and idea by a specific party (3) Effort -
> the work done on a proposal such as evaluation before the effort is
> transformed into a project.  It may never transform into a project, in
> which case it can be categorized as a task or series of tasks (4) Project -
> sequence of tasks, planned from beginning to end, bounded by time, i.e.,
> has start and end date, resources, and required results, defined outcome
> and "deliverables" (5) Program - a permanent or long-term re-occurring
> event, such as the "Head-Start Program" or a warehouse inventory system.'))
>
> ## ---------------------------------------------------
> db.define_table('Suggestion',
> Field('ideaID', 'reference Idea',label='Suggestion Idea ID'), ## not sure
> if this should not be objectID: Field('objectID', 'reference
> ObjectSuperType'),
> Field('objectID', 'reference ObjectSuperType'), ## harmless redundancy,
> but keeps my options open
> Field('IPcreatedBy','string'),
> Field('partyID','reference Party', label='Party making the suggestion'),
> ## need to make this limited to what person's party capacities are
> Field('personClassCode','string'))
>
> thanks,
>
> Alex Glaros
>
>  --
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to