<commit_before>'''
The mixin code for ModelAdmin to link to the SchemaModel objects in models.py.
'''
from metashare.utils import verify_subclass, get_class_by_name
from metashare.repository.supermodel import SchemaModel
from metashare.repository.editor.editorutils import encode_as_inline
from django.db.models.fields import FieldDoesNotExist


class SchemaModelLookup(object):
    show_tabbed_fieldsets = False
    
    def is_field(self, name):
        return not self.is_inline(name)
    
    def is_inline(self, name):
        return name.endswith('_set')


    def is_required_field(self, name):
        """
        Checks whether the field with the given name is a required field.
        """
        # pylint: disable-msg=E1101
        _fields = self.model.get_fields()
        return name in _fields['required']


    def is_visible_as_normal_field(self, field_name, exclusion_list):
        return self.is_field(field_name) and field_name not in exclusion_list
    
    def is_visible_as_inline(self, field_name, include_inlines, inlines):
        return include_inlines and (field_name in inlines or self.is_inline(field_name))

    def get_excluded_fields(self):
        if hasattr(self, 'exclude') and self.exclude is not None:
            return tuple(self.exclude)
        return ()
    
    def get_hidden_fields(self):
        if hasattr(self, 'hidden_fields') and self.hidden_fields is not None:
            return tuple(self.hidden_fields)
        return ()
    
    def get_non_editable_fields(self):
        _readonly = ()
        if hasattr(self, 'readonly_fields') and self.readonly_fields is not None:
            _readonly += tuple(self.readonly_fields)
        _fields = self.model.get_fields_flat()
        for _field_name in _fields:
            try:
                if not self.model._meta.get_field(_field_name).editable:<commit_msg>Avoid false pylint alarm about non-existing fields.<commit_after>'''
The mixin code for ModelAdmin to link to the SchemaModel objects in models.py.
'''
from metashare.utils import verify_subclass, get_class_by_name
from metashare.repository.supermodel import SchemaModel
from metashare.repository.editor.editorutils import encode_as_inline
from django.db.models.fields import FieldDoesNotExist


class SchemaModelLookup(object):
    show_tabbed_fieldsets = False
    
    def is_field(self, name):
        return not self.is_inline(name)
    
    def is_inline(self, name):
        return name.endswith('_set')


    def is_required_field(self, name):
        """
        Checks whether the field with the given name is a required field.
        """
        # pylint: disable-msg=E1101
        _fields = self.model.get_fields()
        return name in _fields['required']


    def is_visible_as_normal_field(self, field_name, exclusion_list):
        return self.is_field(field_name) and field_name not in exclusion_list
    
    def is_visible_as_inline(self, field_name, include_inlines, inlines):
        return include_inlines and (field_name in inlines or self.is_inline(field_name))

    def get_excluded_fields(self):
        # pylint: disable-msg=E1101
        if hasattr(self, 'exclude') and self.exclude is not None:
            return tuple(self.exclude)
        return ()
    
    def get_hidden_fields(self):
        # pylint: disable-msg=E1101
        if hasattr(self, 'hidden_fields') and self.hidden_fields is not None:
            return tuple(self.hidden_fields)
        return ()
    
    def get_non_editable_fields(self):
        # pylint: disable-msg=E1101
        _readonly = ()
        if hasattr(self, 'readonly_fields') and self.readonly_fields is not None:
            _readonly += tuple(self.readonly_fields)
        _fields = self.model.get_fields_flat()
        for _field_name in _fields:
            try:
                if not self.model._meta.get_field(_field_name).editable:
{'fraction_non_alphanumeric': 0.07902892561983471, 'fraction_numerical': 0.005165289256198347, 'mean_word_length': 3.0134715025906735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '927660', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1122, 'n_words': 295}