Esempio n. 1
0
    def from_field(cls, field):
        if isinstance(field, models.NullBooleanField):
            return cls(verbose_name=ucfirst(field.verbose_name), null=True)

        if isinstance(field, models.BooleanField):
            null = getattr(field, 'null', False)
            return cls(verbose_name=ucfirst(field.verbose_name), null=null)
    def from_field(cls, field):
        if isinstance(field, models.NullBooleanField):
            return cls(verbose_name=ucfirst(field.verbose_name), null=True)

        if isinstance(field, models.BooleanField):
            null = getattr(field, "null", False)
            return cls(verbose_name=ucfirst(field.verbose_name), null=null)
Esempio n. 3
0
    def verbose_name(self):
        """
        Return the verbose name for this column.

        In order of preference, this will return:
          1) The column's explicitly defined `verbose_name`
          2) The model's `verbose_name` with the first letter capitalized (if applicable)
          3) Fall back to the column name, with first letter capitalized.

        Any `verbose_name` that was not passed explicitly in the column
        definition is returned with the first character capitalized in keeping
        with the Django convention of `verbose_name` being defined in lowercase and
        uppercased as needed by the application.

        If the table is using `QuerySet` data, then use the corresponding model
        field's `~.db.Field.verbose_name`. If it is traversing a relationship,
        then get the last field in the accessor (i.e. stop when the
        relationship turns from ORM relationships to object attributes [e.g.
        person.upper should stop at person]).
        """
        # Favor an explicit defined verbose_name
        if self.column.verbose_name is not None:
            return self.column.verbose_name

        # This is our reasonable fall back, should the next section not result
        # in anything useful.
        name = self.name.replace("_", " ")

        # Try to use a model field's verbose_name
        model = self._table.data.model
        if model:
            field = Accessor(self.accessor).get_field(model)
            if field:
                if hasattr(field, "field"):
                    name = field.field.verbose_name
                else:
                    name = getattr(field, "verbose_name", field.name)

            # If verbose_name was mark_safe()'d, return intact to keep safety
            if isinstance(name, SafeData):
                return name

        return ucfirst(name)
Esempio n. 4
0
    def verbose_name(self):
        """
        Return the verbose name for this column.

        In order of preference, this will return:
          1) The column's explicitly defined `verbose_name`
          2) The model's `verbose_name` with the first letter capitalized (if applicable)
          3) Fall back to the column name, with first letter capitalized.

        Any `verbose_name` that was not passed explicitly in the column
        definition is returned with the first character capitalized in keeping
        with the Django convention of `verbose_name` being defined in lowercase and
        uppercased as needed by the application.

        If the table is using `QuerySet` data, then use the corresponding model
        field's `~.db.Field.verbose_name`. If it is traversing a relationship,
        then get the last field in the accessor (i.e. stop when the
        relationship turns from ORM relationships to object attributes [e.g.
        person.upper should stop at person]).
        """
        # Favor an explicit defined verbose_name
        if self.column.verbose_name is not None:
            return self.column.verbose_name

        # This is our reasonable fall back, should the next section not result
        # in anything useful.
        name = self.name.replace("_", " ")

        # Try to use a model field's verbose_name
        model = self._table.data.model
        if model:
            field = Accessor(self.accessor).get_field(model)
            if field:
                if hasattr(field, "field"):
                    name = field.field.verbose_name
                else:
                    name = getattr(field, "verbose_name", field.name)

            # If verbose_name was mark_safe()'d, return intact to keep safety
            if isinstance(name, SafeData):
                return name

        return ucfirst(name)
Esempio n. 5
0
    def from_field(cls, field):
        """
        Return a specialised column for the model field or `None`.

        Arguments:
            field (Model Field instance): the field that needs a suitable column
        Returns:
            `.Column` object or `None`

        If the column is not specialised for the given model field, it should
        return `None`. This gives other columns the opportunity to do better.

        If the column is specialised, it should return an instance of itself
        that is configured appropriately for the field.
        """
        # Since this method is inherited by every subclass, only provide a
        # column if this class was asked directly.
        if cls is Column:
            if hasattr(field, "get_related_field"):
                verbose_name = field.get_related_field().verbose_name
            else:
                verbose_name = getattr(field, "verbose_name", field.name)

            return cls(verbose_name=ucfirst(verbose_name))
Esempio n. 6
0
    def from_field(cls, field):
        """
        Return a specialised column for the model field or `None`.

        Arguments:
            field (Model Field instance): the field that needs a suitable column
        Returns:
            `.Column` object or `None`

        If the column is not specialised for the given model field, it should
        return `None`. This gives other columns the opportunity to do better.

        If the column is specialised, it should return an instance of itself
        that is configured appropriately for the field.
        """
        # Since this method is inherited by every subclass, only provide a
        # column if this class was asked directly.
        if cls is Column:
            if hasattr(field, "get_related_field"):
                verbose_name = field.get_related_field().verbose_name
            else:
                verbose_name = getattr(field, "verbose_name", field.name)

            return cls(verbose_name=ucfirst(verbose_name))
Esempio n. 7
0
 def from_field(cls, field):
     if POSTGRES_AVAILABLE:
         if isinstance(field, JSONField) or isinstance(field, HStoreField):
             return cls(verbose_name=ucfirst(field.verbose_name))
Esempio n. 8
0
 def from_field(cls, field):
     if isinstance(field, models.EmailField):
         return cls(verbose_name=ucfirst(field.verbose_name))
Esempio n. 9
0
 def from_field(cls, field):
     if isinstance(field, models.URLField):
         return cls(verbose_name=ucfirst(field.verbose_name))
Esempio n. 10
0
 def from_field(cls, field):
     if POSTGRES_AVAILABLE:
         if isinstance(field, JSONField) or isinstance(field, HStoreField):
             return cls(verbose_name=ucfirst(field.verbose_name))