Пример #1
0
  def __init__(self, field_def, config, user_views=None):
    super(FieldDefView, self).__init__(field_def)

    self.type_name = str(field_def.field_type)

    self.choices = []
    if field_def.field_type == tracker_pb2.FieldTypes.ENUM_TYPE:
      self.choices = tracker_helpers.LabelsMaskedByFields(
          config, [field_def.field_name], trim_prefix=True)

    self.docstring_short = template_helpers.FitUnsafeText(
        field_def.docstring, 200)
    self.validate_help = None

    if field_def.is_required:
      self.importance = 'required'
    elif field_def.is_niche:
      self.importance = 'niche'
    else:
      self.importance = 'normal'

    if field_def.min_value is not None:
      self.min_value = field_def.min_value
      self.validate_help = 'Value must be >= %d' % field_def.min_value
    else:
      self.min_value = None  # Otherwise it would default to 0

    if field_def.max_value is not None:
      self.max_value = field_def.max_value
      self.validate_help = 'Value must be <= %d' % field_def.max_value
    else:
      self.max_value = None  # Otherwise it would default to 0

    if field_def.min_value is not None and field_def.max_value is not None:
      self.validate_help = 'Value must be between %d and %d' % (
          field_def.min_value, field_def.max_value)

    if field_def.regex:
      self.validate_help = 'Value must match regex: %s' % field_def.regex

    if field_def.needs_member:
      self.validate_help = 'Value must be a project member'

    if field_def.needs_perm:
      self.validate_help = (
          'Value must be a project member with permission %s' %
          field_def.needs_perm)

    self.date_action_str = str(field_def.date_action or 'no_action').lower()

    self.admins = []
    if user_views:
      self.admins = [user_views.get(admin_id)
                     for admin_id in field_def.admin_ids]
Пример #2
0
    def ProcessSubtabForm(self, post_data, mr):
        """Process changes to labels and custom field definitions.

    Args:
      post_data: HTML form data for the HTTP request being processed.
      mr: commonly used info parsed from the request.

    Returns:
      The URL of the page to show after processing.
    """
        wkl_text = post_data.get('predefinedlabels', '')
        wkl_matches = framework_constants.IDENTIFIER_DOCSTRING_RE.findall(
            wkl_text)
        wkl_tuples = [(label.lstrip('#'), docstring.strip(),
                       label.startswith('#'))
                      for label, docstring in wkl_matches]

        config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id)
        field_names = [
            fd.field_name for fd in config.field_defs if not fd.is_deleted
        ]
        masked_labels = tracker_helpers.LabelsMaskedByFields(
            config, field_names)
        wkl_tuples.extend([(masked.name, masked.docstring, False)
                           for masked in masked_labels])

        excl_prefix_text = post_data.get('excl_prefixes', '')
        excl_prefixes = framework_constants.IDENTIFIER_RE.findall(
            excl_prefix_text)

        if not mr.errors.AnyErrors():
            self.services.config.UpdateConfig(
                mr.cnxn,
                mr.project,
                well_known_labels=wkl_tuples,
                excl_label_prefixes=excl_prefixes)

        # TODO(jrobbins): define a "strict" mode that affects only labels.

        return urls.ADMIN_LABELS