Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
4794 Ansichten

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)
Avatar
Verwerfen
Autor Beste Antwort

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



Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Sept. 25
11754
0
Juli 21
3033
0
Mai 19
3424
2
Juli 18
4862
0
Juni 17
3178