Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4317 Widoki

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)
Awatar
Odrzuć
Autor Najlepsza odpowiedź

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



Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
lip 24
10975
0
lip 21
2649
0
maj 19
3074
2
lip 18
4413
0
cze 17
2762