跳至内容
菜单
此问题已终结
1 回复
4242 查看

I've got a problem on my website. when my form is successfully POST-ed, the record is created and the website redirects to the success page. If I refresh the page it creates the record again as many times as the page is refreshed. The page with the form and the success page are even two different pages.

Is there a way to destroy unset the data or to prevent records to be created when refreshing the page?

@http.route('/new-ticket', type='http', auth='user', website=True)
    def new_ticket(self, **kwargs):
        request_dict = dict()

        # get user
        user_id = http.request.env.context.get('uid')
        user = request.env['res.users'].search([('id', '=', user_id)])[0]

        request_dict['user'] = user

        parent_project_list = request.env['project.project'].search([('analytic_account_id.parent_project_id', '=', False),
                                                                     ('active', '=', True)])

        request_dict['parent_projects'] = parent_project_list


        if request.httprequest.method == 'POST':
            # get form data
            task_partner_id = request.params['task_partner_id']
            parent_project_id = request.params['parent_project_id']
            child_project_id = request.params['child_project_id']
            task_name = request.params['task_name']
            task_description = request.params['task_description']
            task_priority = self.check_priority(request.params['task_priority'])

            stages_dict = self.get_project_stages(child_project_id)
            stage_id = stages_dict.get('starting_stage_id')

            try:
                projects_env = request.env['project.project'] project = projects_env.sudo().search([('id', '=', child_project_id)])[0] salesperson_id = project.partner_id.user_id.id except: salesperson_id = False new_task = request.env['project.task'].create({'name': task_name, 'active': True, 'stage_id': stage_id, 'kanban_state': 'normal', 'description': task_description, 'project_id': child_project_id, 'priority': task_priority, 'user_id': user_id, 'partner_id': task_partner_id, 'order_partner_id': user.partner_id.id, 'salesperson_id': salesperson_id, }) tasks = self.get_users_tasks(user) return request.render('tabla_project_ticket.tickets', {'tasks': tasks}) return request.render('tabla_project_ticket.new_ticket', request_dict)
形象
丢弃
编写者 最佳答案

I was doing "redirects" the wrong way. I had to change: 

return request.render('tabla_project_ticket.tickets', {'tasks': tasks})

To:

return request.redirect('/tickets')



形象
丢弃
相关帖文 回复 查看 活动
3
7月 24
10816
0
7月 21
2574
0
5月 19
3026
2
7月 18
4356
0
6月 17
2667