Return an ordered mapping of self, excluding texts unless ``include_text`` is True. Used for serialization. Empty values are not included.
(self, include_text=False)
| 2145 | return data |
| 2146 | |
| 2147 | def to_dict(self, include_text=False): |
| 2148 | """ |
| 2149 | Return an ordered mapping of self, excluding texts unless |
| 2150 | ``include_text`` is True. Used for serialization. Empty values are not |
| 2151 | included. |
| 2152 | """ |
| 2153 | data = {} |
| 2154 | |
| 2155 | is_false_positive = self.is_false_positive |
| 2156 | |
| 2157 | if self.license_expression: |
| 2158 | data['license_expression'] = self.license_expression |
| 2159 | |
| 2160 | flags = self.license_flag_names + ( |
| 2161 | 'is_false_positive', |
| 2162 | 'is_required_phrase', |
| 2163 | 'skip_for_required_phrase_generation', |
| 2164 | 'is_continuous', |
| 2165 | 'is_deprecated' |
| 2166 | ) |
| 2167 | |
| 2168 | # default to English which is implied |
| 2169 | if self.language != 'en': |
| 2170 | data['language'] = self.language |
| 2171 | |
| 2172 | for flag in flags: |
| 2173 | tag_value = getattr(self, flag, False) |
| 2174 | if tag_value: |
| 2175 | data[flag] = tag_value |
| 2176 | |
| 2177 | if self.has_stored_relevance and self.relevance and not is_false_positive: |
| 2178 | data['relevance'] = as_int(self.relevance) |
| 2179 | |
| 2180 | if self.has_stored_minimum_coverage and self.minimum_coverage > 0 and not is_false_positive: |
| 2181 | data['minimum_coverage'] = as_int(self.minimum_coverage) |
| 2182 | |
| 2183 | if self.referenced_filenames and not is_false_positive: |
| 2184 | data['referenced_filenames'] = self.referenced_filenames |
| 2185 | |
| 2186 | if self.notes: |
| 2187 | data['notes'] = self.notes |
| 2188 | |
| 2189 | if self.source: |
| 2190 | data['source'] = self.source |
| 2191 | |
| 2192 | if self.is_deprecated and self.replaced_by: |
| 2193 | data['replaced_by'] = self.replaced_by |
| 2194 | |
| 2195 | if include_text and self.text: |
| 2196 | data['text'] = self.text |
| 2197 | |
| 2198 | if not is_false_positive: |
| 2199 | ignorables = ( |
| 2200 | 'ignorable_copyrights', |
| 2201 | 'ignorable_holders', |
| 2202 | 'ignorable_authors', |
| 2203 | 'ignorable_urls', |
| 2204 | 'ignorable_emails', |