The problems are in order in which you do things: record= is executed
before the insert and response.init_flash is set both by the body and
by the crud.

Here is one possible solution

@auth.requires_login()
def index():
    response.functionname='Basic account'
 
record=db(db.tagline.company_id==auth.user.company_id).select().first()
    if record:
        if not response.init_flash: response.init_flash='Update
tagline'
        message='Tagline updated'
    else:
        if not response.init_flash:  response.init_flash='Insert
tagline'
        message='Tagline inserted'
        db.tagline.company_id.default=auth.user.company_id
    form=crud.update(db.tagline,record,message=message)
    return dict(form=form)

On May 23, 12:38 pm, annet <[email protected]> wrote:
> I defined the following function:
>
> @auth.requires_login()
> def index():
>     response.functionname='Basic account'
>
> record=db(db.tagline.company_id==auth.user.company_id).select().first()
>     if record:
>         response.init_flash='Update tagline'
>         form=crud.update(db.tagline,record,message='Tagline updated')
>     else:
>         response.init_flash='Insert tagline'
>         db.tagline.company_id.default=auth.user.company_id
>         form=crud.create(db.tagline,message='Tagline inserted')
>     return dict(form=form)
>
> When there is no tagline I get the create form and when I submit the
> form the Tagline inserted flash is displayed, however, the tagline
> field is empty,
>
> 1) whereas I expected it to contain the inserted tagline.
>
> When I refresh the page I get the update form and the flash says:
> Update tagline. When I update the tagline and submit the change the
> Tagline updated flash displays. Which is correct.
>
> When I check the 'check to delete' box, the alert displays, after
> clicking OK and clicking submit,
>
> 2) the Tagline updated flash displays and the tagline field still
> contains the tagline and the check box is still checked. When I click
> submit again the tagline is being deleted and the Insert tagline flash
> displays,
>
> 3) whereas I would like a flash telling the user that the tagline has
> been deleted.
>
> How do I solve these three problems?
>
> Kind regards,
>
> Annet.

Reply via email to