<commit_before>import os
import tarfile
import zipfile
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.models import User
from mod.models import Mod
from settings import MEDIA_ROOT


def make_dir(path):
    if not os.path.exists(path):
        os.makedirs(path)


class UserAdmin(AuthUserAdmin):
    def save_model(self, request, obj, form, change):
        if obj.is_active:
            path = os.path.join(MEDIA_ROOT, 'users', obj.username)
            if not os.path.exists(path):
                os.makedirs(path)
            mods = Mod.objects.all()
            zips = mods.filter(mimetype='application/zip')
            tars = mods.filter(mimetype='application/x-tar')
            for mod in zips:
                mod_path = os.path.join(MEDIA_ROOT, 'users', obj.username, mod.title)
                if not os.path.exists(mod_path):
                    os.makedirs(mod_path)
                    with zipfile.ZipFile(mod.mod_file.path) as z:
                        z.extractall(mod_path)
            for mod in tars:
                mod_path = os.path.join(MEDIA_ROOT, 'users', obj.username, mod.title)
                if not os.path.exists(mod_path):
                    os.makedirs(mod_path)
                    with tarfile.TarFile(mod.mod_file.path) as t:
                        t.extractall(mod_path)
        obj.save()

# unregister old user admin
admin.site.unregister(User)
# register new user admin
admin.site.register(User, UserAdmin)<commit_msg>show active/inactive users in user admin list view<commit_after>import os
import tarfile
import zipfile
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.models import User
from mod.models import Mod
from settings import MEDIA_ROOT


def make_dir(path):
    if not os.path.exists(path):
        os.makedirs(path)


class UserAdmin(AuthUserAdmin):
    list_display = ('username', 'email', 'first_name', 'last_name', 'is_active', 'is_staff')

    def save_model(self, request, obj, form, change):
        if obj.is_active:
            path = os.path.join(MEDIA_ROOT, 'users', obj.username)
            if not os.path.exists(path):
                os.makedirs(path)
            mods = Mod.objects.all()
            zips = mods.filter(mimetype='application/zip')
            tars = mods.filter(mimetype='application/x-tar')
            for mod in zips:
                mod_path = os.path.join(MEDIA_ROOT, 'users', obj.username, mod.title)
                if not os.path.exists(mod_path):
                    os.makedirs(mod_path)
                    with zipfile.ZipFile(mod.mod_file.path) as z:
                        z.extractall(mod_path)
            for mod in tars:
                mod_path = os.path.join(MEDIA_ROOT, 'users', obj.username, mod.title)
                if not os.path.exists(mod_path):
                    os.makedirs(mod_path)
                    with tarfile.TarFile(mod.mod_file.path) as t:
                        t.extractall(mod_path)
        obj.save()

# unregister old user admin
admin.site.unregister(User)
# register new user admin
admin.site.register(User, UserAdmin)
{'fraction_non_alphanumeric': 0.09884627377611475, 'fraction_numerical': 0.0, 'mean_word_length': 2.1762376237623764, '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': '4496670', 'n_tokens_mistral': 984, 'n_tokens_neox': 953, 'n_words': 225}