<commit_before># -*- coding: utf-8 -*-
from django.contrib import admin
from django.db import models
from django.forms.fields import Select
from django import forms

from piwik import PiwikAPI
from piwik.django.models import PiwikSite

from django.conf import settings

class PiwikWidget(Select):
    def getPiwikSites(self):
        piwik = PiwikAPI(settings.PIWIK_URL, settings.PIWIK_TOKEN)
        sites = piwik.getAllSites()
        choices = []
        for index in sites:
            id = int(index[0])
            site = piwik.getSiteFromId(id)
            choices.append((id, '%d - %s' % (id, site[0]["name"])))
        return tuple(choices)
    def render(self, name, value, attrs=None, choices=()):
        return super(PiwikWidget, self).render(name, value, attrs=attrs, choices=self.getPiwikSites())

class PiwikSiteForm(forms.ModelForm):
    id_site = forms.IntegerField(widget=PiwikWidget())
    class Meta:
        model = PiwikSite

class PiwikSitesAdmin(admin.ModelAdmin):
    form = PiwikSiteForm
    
admin.site.register(PiwikSite, PiwikSitesAdmin)<commit_msg>Improve admin interface<commit_after># -*- coding: utf-8 -*-
from django.contrib import admin
from django.db import models
from django.forms.fields import Select
from django import forms

from piwik import PiwikAPI
from piwik.django.models import PiwikSite

from django.conf import settings

class PiwikWidget(Select):
    def getPiwikSites(self):
        piwik = PiwikAPI(settings.PIWIK_URL, settings.PIWIK_TOKEN)
        sites = piwik.getAllSites()
        choices = []
        for index in sites:
            id = int(index[0])
            site = piwik.getSiteFromId(id)
            choices.append((id, '%d - %s' % (id, site[0]["name"])))
        return tuple(choices)
    def render(self, name, value, attrs=None, choices=()):
        return super(PiwikWidget, self).render(name, value, attrs=attrs, choices=self.getPiwikSites())

class PiwikSiteForm(forms.ModelForm):
    id_site = forms.IntegerField(widget=PiwikWidget())
    class Meta:
        model = PiwikSite

class PiwikSitesAdmin(admin.ModelAdmin):
    form = PiwikSiteForm
    list_display = ('id_site', 'site')
    
admin.site.register(PiwikSite, PiwikSitesAdmin)
{'fraction_non_alphanumeric': 0.11146352514725873, 'fraction_numerical': 0.002718622564567286, 'mean_word_length': 3.4787018255578093, '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': '5071712', 'n_tokens_mistral': 713, 'n_tokens_neox': 692, 'n_words': 168}