콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4489 화면

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
9월 25
11237
0
7월 21
2803
0
5월 19
3202
2
7월 18
4559
0
6월 17
2944