'Save or overwrite a slice'

def save_or_overwrite_slice(self, args, slc, slice_add_perm, slice_overwrite_perm, datasource_id, datasource_type):

    slice_name = args.get(u'slice_name')
    action = args.get(u'action')
    form_data = self.get_form_data()
    if (action in u'saveas'):
        if (u'slice_id' in form_data):
            form_data.pop(u'slice_id')
        slc = models.Slice(owners=([g.user] if g.user else []))
    slc.params = json.dumps(form_data)
    slc.datasource_name = args.get(u'datasource_name')
    slc.viz_type = form_data[u'viz_type']
    slc.datasource_type = datasource_type
    slc.datasource_id = datasource_id
    slc.slice_name = slice_name
    if ((action in u'saveas') and slice_add_perm):
        self.save_slice(slc)
    elif ((action == u'overwrite') and slice_overwrite_perm):
        self.overwrite_slice(slc)
    dash = None
    if (request.args.get(u'add_to_dash') == u'existing'):
        dash = db.session.query(models.Dashboard).filter_by(id=int(request.args.get(u'save_to_dashboard_id'))).one()
        flash(u'Slice    [{}]    was    added    to    dashboard    [{}]'.format(slc.slice_name, dash.dashboard_title), u'info')
    elif (request.args.get(u'add_to_dash') == u'new'):
        dash = models.Dashboard(dashboard_title=request.args.get(u'new_dashboard_name'), owners=([g.user] if g.user else []))
        flash(u'Dashboard    [{}]    just    got    created    and    slice    [{}]    was    added    to    it'.format(dash.dashboard_title, slc.slice_name), u'info')
    if (dash and (slc not in dash.slices)):
        dash.slices.append(slc)
        db.session.commit()
    if (request.args.get(u'goto_dash') == u'true'):
        return dash.url
    else:
        return slc.slice_url
