@ensure_configuration
def save_design(request, save_form, query_form, type_, design, explicit_save=False):

  if type_ == beeswax_models.RDBMS:
    design_cls = SQLdesign
  else:
    raise ValueError(_('Invalid design type %(type)s') % {'type': type_})

  old_design = design
  design_obj = design_cls(query_form)
  new_data = design_obj.dumps()

  # Auto save if (1) the user didn't click "save", and (2) the data is different.
  # Don't generate an auto-saved design if the user didn't change anything
  if explicit_save:
    design.name = save_form.cleaned_data['name']
    design.desc = save_form.cleaned_data['desc']
    design.is_auto = False
  elif new_data != old_design.data:
    # Auto save iff the data is different
    if old_design.id is not None:
      # Clone iff the parent design isn't a new unsaved model
      design = old_design.clone()
      if not old_design.is_auto:
        design.name = old_design.name + beeswax_models.SavedQuery.AUTO_DESIGN_SUFFIX
    else:
      design.name = beeswax_models.SavedQuery.DEFAULT_NEW_DESIGN_NAME
    design.is_auto = True

  design.name = design.name[:64]
  design.type = type_
  design.data = new_data

  design.save()

  LOG.info('Saved %s design "%s" (id %s) for %s' % (design.name and '' or 'auto ', design.name, design.id, design.owner))

  if design.doc.exists():
    design.doc.update(name=design.name, description=design.desc)
  else:
    Document.objects.link(design, owner=design.owner, extra=design.type, name=design.name, description=design.desc)

  if design.is_auto:
    design.doc.get().add_to_history()

  return design
save_design(request, save_form, query_form, type_, design, explicit_save) -> SavedQuery
dataset/ETHPy150Open cloudera/hue/apps/rdbms/src/rdbms/views.py/save_design