当前位置: 首页>>代码示例>>Python>>正文


Python CreateByImportDelimForm.is_valid方法代码示例

本文整理汇总了Python中beeswax.forms.CreateByImportDelimForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python CreateByImportDelimForm.is_valid方法的具体用法?Python CreateByImportDelimForm.is_valid怎么用?Python CreateByImportDelimForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beeswax.forms.CreateByImportDelimForm的用法示例。


在下文中一共展示了CreateByImportDelimForm.is_valid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_wizard

# 需要导入模块: from beeswax.forms import CreateByImportDelimForm [as 别名]
# 或者: from beeswax.forms.CreateByImportDelimForm import is_valid [as 别名]
def import_wizard(request, database='default'):
  """
  Help users define table and based on a file they want to import to Hive.
  Limitations:
    - Rows are delimited (no serde).
    - No detection for map and array types.
    - No detection for the presence of column header in the first row.
    - No partition table.
    - Does not work with binary data.
  """
  encoding = i18n.get_site_encoding()
  app_name = get_app_name(request)

  db = dbms.get(request.user)
  dbs = db.get_databases()
  databases = [{'name':db, 'url':reverse('beeswax:import_wizard', kwargs={'database': db})} for db in dbs]

  if request.method == 'POST':
    #
    # General processing logic:
    # - We have 3 steps. Each requires the previous.
    #   * Step 1      : Table name and file location
    #   * Step 2a     : Display sample with auto chosen delim
    #   * Step 2b     : Display sample with user chosen delim (if user chooses one)
    #   * Step 3      : Display sample, and define columns
    # - Each step is represented by a different form. The form of an earlier step
    #   should be present when submitting to a later step.
    # - To preserve the data from the earlier steps, we send the forms back as
    #   hidden fields. This way, when users revisit a previous step, the data would
    #   be there as well.
    #
    delim_is_auto = False
    fields_list, n_cols = [[]], 0
    s3_col_formset = None
    s1_file_form = CreateByImportFileForm(request.POST, db=db)

    if s1_file_form.is_valid():
      do_s2_auto_delim = request.POST.get('submit_file')        # Step 1 -> 2
      do_s2_user_delim = request.POST.get('submit_preview')     # Step 2 -> 2
      do_s3_column_def = request.POST.get('submit_delim')       # Step 2 -> 3
      do_hive_create = request.POST.get('submit_create')        # Step 3 -> execute

      cancel_s2_user_delim = request.POST.get('cancel_delim')   # Step 2 -> 1
      cancel_s3_column_def = request.POST.get('cancel_create')  # Step 3 -> 2

      # Exactly one of these should be True
      if len(filter(None, (do_s2_auto_delim, do_s2_user_delim, do_s3_column_def, do_hive_create, cancel_s2_user_delim, cancel_s3_column_def))) != 1:
        raise PopupException(_('Invalid form submission'))

      if not do_s2_auto_delim:
        # We should have a valid delim form
        s2_delim_form = CreateByImportDelimForm(request.POST)
        if not s2_delim_form.is_valid():
          # Go back to picking delimiter
          do_s2_user_delim, do_s3_column_def, do_hive_create = True, False, False
      if do_hive_create:
        # We should have a valid columns formset
        s3_col_formset = ColumnTypeFormSet(prefix='cols', data=request.POST)
        if not s3_col_formset.is_valid():
          # Go back to define columns
          do_s3_column_def, do_hive_create = True, False

      #
      # Go to step 2: We've just picked the file. Preview it.
      #
      if do_s2_auto_delim:
        delim_is_auto = True
        fields_list, n_cols, s2_delim_form = _delim_preview(request.fs, s1_file_form, encoding, [reader.TYPE for reader in FILE_READERS], DELIMITERS)

      if (do_s2_user_delim or do_s3_column_def or cancel_s3_column_def) and s2_delim_form.is_valid():
        # Delimit based on input
        fields_list, n_cols, s2_delim_form = _delim_preview(request.fs, s1_file_form, encoding, (s2_delim_form.cleaned_data['file_type'],),
                                                            (s2_delim_form.cleaned_data['delimiter'],))

      if do_s2_auto_delim or do_s2_user_delim or cancel_s3_column_def:
        return render('choose_delimiter.mako', request, {
          'action': reverse(app_name + ':import_wizard', kwargs={'database': database}),
          'delim_readable': DELIMITER_READABLE.get(s2_delim_form['delimiter'].data[0], s2_delim_form['delimiter'].data[1]),
          'initial': delim_is_auto,
          'file_form': s1_file_form,
          'delim_form': s2_delim_form,
          'fields_list': fields_list,
          'delimiter_choices': TERMINATOR_CHOICES,
          'n_cols': n_cols,
          'database': database,
          'databases': databases
        })

      #
      # Go to step 3: Define column.
      #
      if do_s3_column_def:
        if s3_col_formset is None:
          columns = []
          for i in range(n_cols):
            columns.append({
                'column_name': 'col_%s' % (i,),
                'column_type': 'string',
            })
          s3_col_formset = ColumnTypeFormSet(prefix='cols', initial=columns)
#.........这里部分代码省略.........
开发者ID:shobull,项目名称:hue,代码行数:103,代码来源:create_table.py

示例2: PopupException

# 需要导入模块: from beeswax.forms import CreateByImportDelimForm [as 别名]
# 或者: from beeswax.forms.CreateByImportDelimForm import is_valid [as 别名]
    raise PopupException(msg)

  n_cols = max([ len(row) for row in fields_list ])
  # ``delimiter`` is a MultiValueField. delimiter_0 and delimiter_1 are the sub-fields.
  delimiter_0 = delim
  delimiter_1 = ''
  # If custom delimiter
  if not filter(lambda val: val[0] == delim, TERMINATOR_CHOICES):
    delimiter_0 = '__other__'
    delimiter_1 = delim

  delim_form = CreateByImportDelimForm(dict(delimiter_0=delimiter_0,
                                            delimiter_1=delimiter_1,
                                            file_type=file_type,
                                            n_cols=n_cols))
  if not delim_form.is_valid():
    assert False, _('Internal error when constructing the delimiter form: %(error)s.') % {'error': delim_form.errors}
  return fields_list, n_cols, delim_form


def _parse_fields(path, file_obj, encoding, filetypes, delimiters):
  """
  _parse_fields(path, file_obj, encoding, filetypes, delimiters)
                                  -> (delimiter, filetype, fields_list)

  Go through the list of ``filetypes`` (gzip, text) and stop at the first one
  that works for the data. Then apply the list of ``delimiters`` and pick the
  most appropriate one.
  ``path`` is used for debugging only.

  Return the best delimiter, filetype and the data broken down into rows of fields.
开发者ID:shobull,项目名称:hue,代码行数:33,代码来源:create_table.py

示例3: import_wizard

# 需要导入模块: from beeswax.forms import CreateByImportDelimForm [as 别名]
# 或者: from beeswax.forms.CreateByImportDelimForm import is_valid [as 别名]
def import_wizard(request, database=None):
  """
  Help users define table and based on a file they want to import to Hive.
  Limitations:
    - Rows are delimited (no serde).
    - No detection for map and array types.
    - No detection for the presence of column header in the first row.
    - No partition table.
    - Does not work with binary data.
  """
  database = _get_last_database(request, database)
  encoding = i18n.get_site_encoding()
  app_name = get_app_name(request)

  if request.method == 'POST':
    # Have a while loop to allow an easy way to break
    for _ in range(1):
      #
      # General processing logic:
      # - We have 3 steps. Each requires the previous.
      #   * Step 1      : Table name and file location
      #   * Step 2a     : Display sample with auto chosen delim
      #   * Step 2b     : Display sample with user chosen delim (if user chooses one)
      #   * Step 3      : Display sample, and define columns
      # - Each step is represented by a different form. The form of an earlier step
      #   should be present when submitting to a later step.
      # - To preserve the data from the earlier steps, we send the forms back as
      #   hidden fields. This way, when users revisit a previous step, the data would
      #   be there as well.
      #
      delim_is_auto = False
      fields_list, n_cols = [ [] ], 0
      s3_col_formset = None

      # Everything requires a valid file form
      db = dbms.get(request.user)
      s1_file_form = CreateByImportFileForm(request.POST, db=db)
      if not s1_file_form.is_valid():
        break

      do_s2_auto_delim = request.POST.get('submit_file')        # Step 1 -> 2
      do_s2_user_delim = request.POST.get('submit_preview')     # Step 2 -> 2
      do_s3_column_def = request.POST.get('submit_delim')       # Step 2 -> 3
      do_hive_create = request.POST.get('submit_create')        # Step 3 -> execute

      cancel_s2_user_delim = request.POST.get('cancel_delim')   # Step 2 -> 1
      cancel_s3_column_def = request.POST.get('cancel_create')  # Step 3 -> 2

      # Exactly one of these should be True
      assert len(filter(None, (do_s2_auto_delim,
                               do_s2_user_delim,
                               do_s3_column_def,
                               do_hive_create,
                               cancel_s2_user_delim,
                               cancel_s3_column_def))) == 1, 'Invalid form submission'

      #
      # Fix up what we should do in case any form is invalid
      #
      if not do_s2_auto_delim:
        # We should have a valid delim form
        s2_delim_form = CreateByImportDelimForm(request.POST)
        if not s2_delim_form.is_valid():
          # Go back to picking delimiter
          do_s2_user_delim, do_s3_column_def, do_hive_create = True, False, False

      if do_hive_create:
        # We should have a valid columns formset
        s3_col_formset = ColumnTypeFormSet(prefix='cols', data=request.POST)
        if not s3_col_formset.is_valid():
          # Go back to define columns
          do_s3_column_def, do_hive_create = True, False

      #
      # Go to step 2: We've just picked the file. Preview it.
      #
      if do_s2_auto_delim:
        delim_is_auto = True
        fields_list, n_cols, s2_delim_form = _delim_preview(
                                              request.fs,
                                              s1_file_form,
                                              encoding,
                                              [ reader.TYPE for reader in FILE_READERS ],
                                              DELIMITERS,
                                              False)

      if (do_s2_user_delim or do_s3_column_def or cancel_s3_column_def) and s2_delim_form.is_valid():
        # Delimit based on input
        fields_list, n_cols, s2_delim_form = _delim_preview(
                                              request.fs,
                                              s1_file_form,
                                              encoding,
                                              (s2_delim_form.cleaned_data['file_type'],),
                                              (s2_delim_form.cleaned_data['delimiter'],),
                                              s2_delim_form.cleaned_data.get('read_column_headers'))

      if do_s2_auto_delim or do_s2_user_delim or cancel_s3_column_def:
        return render('choose_delimiter.mako', request, {
          'action': reverse(app_name + ':import_wizard', kwargs={'database': database}),
          'delim_readable': DELIMITER_READABLE.get(s2_delim_form['delimiter'].data[0], s2_delim_form['delimiter'].data[1]),
#.........这里部分代码省略.........
开发者ID:OpenPOWER-BigData,项目名称:HDP-hue,代码行数:103,代码来源:create_table.py

示例4: import_wizard

# 需要导入模块: from beeswax.forms import CreateByImportDelimForm [as 别名]
# 或者: from beeswax.forms.CreateByImportDelimForm import is_valid [as 别名]
def import_wizard(request, database="default"):
    """
  Help users define table and based on a file they want to import to Hive.
  Limitations:
    - Rows are delimited (no serde).
    - No detection for map and array types.
    - No detection for the presence of column header in the first row.
    - No partition table.
    - Does not work with binary data.
  """
    encoding = i18n.get_site_encoding()
    app_name = get_app_name(request)

    db = dbms.get(request.user)
    dbs = db.get_databases()
    databases = [{"name": db, "url": reverse("beeswax:import_wizard", kwargs={"database": db})} for db in dbs]

    if request.method == "POST":
        #
        # General processing logic:
        # - We have 3 steps. Each requires the previous.
        #   * Step 1      : Table name and file location
        #   * Step 2a     : Display sample with auto chosen delim
        #   * Step 2b     : Display sample with user chosen delim (if user chooses one)
        #   * Step 3      : Display sample, and define columns
        # - Each step is represented by a different form. The form of an earlier step
        #   should be present when submitting to a later step.
        # - To preserve the data from the earlier steps, we send the forms back as
        #   hidden fields. This way, when users revisit a previous step, the data would
        #   be there as well.
        #
        delim_is_auto = False
        fields_list, n_cols = [[]], 0
        s3_col_formset = None
        s1_file_form = CreateByImportFileForm(request.POST, db=db)

        if s1_file_form.is_valid():
            do_s2_auto_delim = request.POST.get("submit_file")  # Step 1 -> 2
            do_s2_user_delim = request.POST.get("submit_preview")  # Step 2 -> 2
            do_s3_column_def = request.POST.get("submit_delim")  # Step 2 -> 3
            do_hive_create = request.POST.get("submit_create")  # Step 3 -> execute

            cancel_s2_user_delim = request.POST.get("cancel_delim")  # Step 2 -> 1
            cancel_s3_column_def = request.POST.get("cancel_create")  # Step 3 -> 2

            # Exactly one of these should be True
            if (
                len(
                    filter(
                        None,
                        (
                            do_s2_auto_delim,
                            do_s2_user_delim,
                            do_s3_column_def,
                            do_hive_create,
                            cancel_s2_user_delim,
                            cancel_s3_column_def,
                        ),
                    )
                )
                != 1
            ):
                raise PopupException(_("Invalid form submission"))

            if not do_s2_auto_delim:
                # We should have a valid delim form
                s2_delim_form = CreateByImportDelimForm(request.POST)
                if not s2_delim_form.is_valid():
                    # Go back to picking delimiter
                    do_s2_user_delim, do_s3_column_def, do_hive_create = True, False, False
            if do_hive_create:
                # We should have a valid columns formset
                s3_col_formset = ColumnTypeFormSet(prefix="cols", data=request.POST)
                if not s3_col_formset.is_valid():
                    # Go back to define columns
                    do_s3_column_def, do_hive_create = True, False

            #
            # Go to step 2: We've just picked the file. Preview it.
            #
            if do_s2_auto_delim:
                delim_is_auto = True
                fields_list, n_cols, s2_delim_form = _delim_preview(
                    request.fs, s1_file_form, encoding, [reader.TYPE for reader in FILE_READERS], DELIMITERS
                )

            if (do_s2_user_delim or do_s3_column_def or cancel_s3_column_def) and s2_delim_form.is_valid():
                # Delimit based on input
                fields_list, n_cols, s2_delim_form = _delim_preview(
                    request.fs,
                    s1_file_form,
                    encoding,
                    (s2_delim_form.cleaned_data["file_type"],),
                    (s2_delim_form.cleaned_data["delimiter"],),
                )

            if do_s2_auto_delim or do_s2_user_delim or cancel_s3_column_def:
                return render(
                    "choose_delimiter.mako",
                    request,
#.........这里部分代码省略.........
开发者ID:mobilist,项目名称:hue,代码行数:103,代码来源:create_table.py

示例5: import_wizard

# 需要导入模块: from beeswax.forms import CreateByImportDelimForm [as 别名]
# 或者: from beeswax.forms.CreateByImportDelimForm import is_valid [as 别名]
def import_wizard(request):
    """
  Help users define table and based on a file they want to import to Hive.
  Limitations:
    - Rows are delimited (no serde).
    - No detection for map and array types.
    - No detection for the presence of column header in the first row.
    - No partition table.
    - Does not work with binary data.
  """
    encoding = i18n.get_site_encoding()

    if request.method == "POST":
        # Have a while loop to allow an easy way to break
        for _ in range(1):
            #
            # General processing logic:
            # - We have 3 steps. Each requires the previous.
            #   * Step 1      : Table name and file location
            #   * Step 2a     : Display sample with auto chosen delim
            #   * Step 2b     : Display sample with user chosen delim (if user chooses one)
            #   * Step 3      : Display sample, and define columns
            # - Each step is represented by a different form. The form of an earlier step
            #   should be present when submitting to a later step.
            # - To preserve the data from the earlier steps, we send the forms back as
            #   hidden fields. This way, when users revisit a previous step, the data would
            #   be there as well.
            #
            delim_is_auto = False
            fields_list, n_cols = [[]], 0
            s3_col_formset = None

            # Everything requires a valid file form
            db = dbms.get(request.user)
            s1_file_form = CreateByImportFileForm(request.POST, db=db)
            if not s1_file_form.is_valid():
                break

            do_s2_auto_delim = request.POST.get("submit_file")  # Step 1 -> 2
            do_s2_user_delim = request.POST.get("submit_preview")  # Step 2 -> 2
            do_s3_column_def = request.POST.get("submit_delim")  # Step 2 -> 3
            do_hive_create = request.POST.get("submit_create")  # Step 3 -> execute

            cancel_s2_user_delim = request.POST.get("cancel_delim")  # Step 2 -> 1
            cancel_s3_column_def = request.POST.get("cancel_create")  # Step 3 -> 2

            # Exactly one of these should be True
            assert (
                len(
                    filter(
                        None,
                        (
                            do_s2_auto_delim,
                            do_s2_user_delim,
                            do_s3_column_def,
                            do_hive_create,
                            cancel_s2_user_delim,
                            cancel_s3_column_def,
                        ),
                    )
                )
                == 1
            ), "Invalid form submission"

            #
            # Fix up what we should do in case any form is invalid
            #
            if not do_s2_auto_delim:
                # We should have a valid delim form
                s2_delim_form = CreateByImportDelimForm(request.POST)
                if not s2_delim_form.is_valid():
                    # Go back to picking delimiter
                    do_s2_user_delim, do_s3_column_def, do_hive_create = True, False, False

            if do_hive_create:
                # We should have a valid columns formset
                s3_col_formset = ColumnTypeFormSet(prefix="cols", data=request.POST)
                if not s3_col_formset.is_valid():
                    # Go back to define columns
                    do_s3_column_def, do_hive_create = True, False

            #
            # Go to step 2: We've just picked the file. Preview it.
            #
            if do_s2_auto_delim:
                delim_is_auto = True
                fields_list, n_cols, s2_delim_form = _delim_preview(
                    request.fs, s1_file_form, encoding, [reader.TYPE for reader in FILE_READERS], DELIMITERS
                )

            if (do_s2_user_delim or do_s3_column_def or cancel_s3_column_def) and s2_delim_form.is_valid():
                # Delimit based on input
                fields_list, n_cols, s2_delim_form = _delim_preview(
                    request.fs,
                    s1_file_form,
                    encoding,
                    (s2_delim_form.cleaned_data["file_type"],),
                    (s2_delim_form.cleaned_data["delimiter"],),
                )

#.........这里部分代码省略.........
开发者ID:ahonko,项目名称:hue,代码行数:103,代码来源:create_table.py


注:本文中的beeswax.forms.CreateByImportDelimForm.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。