<commit_before># -*- coding: utf-8 -*-
# File:   src/webframe/admin.py
# Date:   2019-11-21 14:55
# Author: <NAME> <<EMAIL>>
# Desc:   The file provide the Admin-Tools in webframe module
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _, ugettext
from .models import *
import logging

logger=logging.getLogger('webframe.admin')

class PreferenceChildParentFilter(admin.SimpleListFilter):
   title=_('webframe.models.Preference.childParentFilter')
   parameter_name='child_parent_filter'

   def lookups(self, req, modelAdmin):
      rst=[
         ('parent', _('webframe.models.Preference.childParentFilter.parent')),
         ('child',  _('webframe.models.Preference.childParentFilter.child')),
      ]
      return rst

   def queryset(self, req, q):
      logger.info('Filtering by PreferenceChildParentFilter: {0}'.format(self.value()))
      if self.value() is None:
         return q
      elif self.value()=='parent':
         return q.filter(id__in=Preference.objects.filter(parent__isnull=False).values('parent__id'))
      else:
         return q.filter(parent__isnull=False)

@admin.register(Preference)
class PreferenceAdmin(admin.ModelAdmin):
   list_display=('id', 'name', 'parent', 'reserved', 'lmb', 'lmd')
   list_filter=('reserved', PreferenceChildParentFilter, 'tipe',)
   search_fields=('name', 'value', 'owner__username', 'owner__name')
   ordering=('owner__username', 'name', 'value')<commit_msg>Fixing the Preference filtering exception<commit_after># -*- coding: utf-8 -*-
# File:   src/webframe/admin.py
# Date:   2019-11-21 14:55
# Author: <NAME> <<EMAIL>>
# Desc:   The file provide the Admin-Tools in webframe module
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _, ugettext
from .models import *
import logging

logger=logging.getLogger('webframe.admin')

class PreferenceChildParentFilter(admin.SimpleListFilter):
   title=_('webframe.models.Preference.childParentFilter')
   parameter_name='child_parent_filter'

   def lookups(self, req, modelAdmin):
      rst=[
         ('parent', _('webframe.models.Preference.childParentFilter.parent')),
         ('child',  _('webframe.models.Preference.childParentFilter.child')),
      ]
      return rst

   def queryset(self, req, q):
      logger.info('Filtering by PreferenceChildParentFilter: {0}'.format(self.value()))
      if self.value() is None:
         return q
      elif self.value()=='parent':
         return q.filter(id__in=Preference.objects.filter(parent__isnull=False).values('parent__id'))
      else:
         return q.filter(parent__isnull=False)

@admin.register(Preference)
class PreferenceAdmin(admin.ModelAdmin):
   list_display=('id', 'name', 'parent', 'reserved', 'lmb', 'lmd')
   list_filter=('reserved', PreferenceChildParentFilter, 'tipe',)
   search_fields=('name', 'value', 'owner__username', 'owner__username')
   ordering=('owner__username', 'name', 'value')
{'fraction_non_alphanumeric': 0.1425661914460285, 'fraction_numerical': 0.009504412763068567, 'mean_word_length': 4.549905838041432, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5333213', 'n_tokens_mistral': 928, 'n_tokens_neox': 902, 'n_words': 185}