Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4297 Lượt xem

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)
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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')



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 7 24
10944
0
thg 7 21
2633
0
thg 5 19
3065
2
thg 7 18
4395
0
thg 6 17
2754