<commit_before>from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.contrib.gis import admin
from django import forms

from open511_server.models import RoadEvent, Jurisdiction, JurisdictionGeography, Area, Camera



class BaseRoadEventForm(forms.BaseModelForm):

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('initial', {})
        if kwargs.get('instance'):
            obj = kwargs['instance']
            for fname, field in self.base_fields.items():
                if hasattr(field, 'get_db_value'):
                    val = field.get_db_value(obj)
                    if val:
                        kwargs['initial'][fname] = val
        super(BaseRoadEventForm, self).__init__(*args, **kwargs)
        print kwargs

    def save(self, commit=True):
        obj = super(BaseRoadEventForm, self).save(commit=False)
        for fname, field in self.base_fields.items():
            if hasattr(field, 'set_db_value'):
                val = self.cleaned_data[fname]
                field.set_db_value(obj, val)
        if commit:
            obj.save()
        return obj

    class Meta(object):
        model = RoadEvent
        exclude = ['xml_data']

class RoadEventAdmin(admin.ModelAdmin):
    list_display = ['headline', 'full_id', 'severity', 'active', 'has_remaining_periods']
    list_filter = ['jurisdiction', 'active']
    search_fields = ['xml_data', 'id']


class JurisdictionAdmin(admin.ModelAdmin):
    filter_horizontal = ['permitted_users']

admin.site.register(RoadEvent, RoadEventAdmin)
admin.site.register(Jurisdiction, JurisdictionAdmin)
admin.site.register(JurisdictionGeography)
admin.site.register(Area)
admin.site.register(Camera)

class JurInline(admin.TabularInline):
    model = Jurisdiction.permitted_users.through
    extra = 1

class CustomUserAdmin(UserAdmin):
    inlines = [JurInline]

admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)<commit_msg>Use WKT box, not fancy widget, for JurisdictionGeography admin<commit_after>from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.contrib import admin
from django.contrib.gis.db import models
from django import forms

from open511_server.models import RoadEvent, Jurisdiction, JurisdictionGeography, Area, Camera


class BaseRoadEventForm(forms.BaseModelForm):

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('initial', {})
        if kwargs.get('instance'):
            obj = kwargs['instance']
            for fname, field in self.base_fields.items():
                if hasattr(field, 'get_db_value'):
                    val = field.get_db_value(obj)
                    if val:
                        kwargs['initial'][fname] = val
        super(BaseRoadEventForm, self).__init__(*args, **kwargs)
        print kwargs

    def save(self, commit=True):
        obj = super(BaseRoadEventForm, self).save(commit=False)
        for fname, field in self.base_fields.items():
            if hasattr(field, 'set_db_value'):
                val = self.cleaned_data[fname]
                field.set_db_value(obj, val)
        if commit:
            obj.save()
        return obj

    class Meta(object):
        model = RoadEvent
        exclude = ['xml_data']

class RoadEventAdmin(admin.ModelAdmin):
    list_display = ['headline', 'full_id', 'severity', 'active', 'has_remaining_periods']
    list_filter = ['jurisdiction', 'active']
    search_fields = ['xml_data', 'id']


class JurisdictionAdmin(admin.ModelAdmin):
    filter_horizontal = ['permitted_users']

class JurisdictionGeographyAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.GeometryField: {'widget': forms.widgets.Textarea }
    }

admin.site.register(RoadEvent, RoadEventAdmin)
admin.site.register(Jurisdiction, JurisdictionAdmin)
admin.site.register(JurisdictionGeography, JurisdictionGeographyAdmin)
admin.site.register(Area)
admin.site.register(Camera)

class JurInline(admin.TabularInline):
    model = Jurisdiction.permitted_users.through
    extra = 1

class CustomUserAdmin(UserAdmin):
    inlines = [JurInline]

admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
{'fraction_non_alphanumeric': 0.10819128787878787, 'fraction_numerical': 0.001893939393939394, 'mean_word_length': 3.2849898580121706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5489117', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1203, 'n_words': 260}