<commit_before>from django import forms
from django.forms import widgets

import autocomplete_light

from antioch.core import models
from antioch.plugins.editors import tasks

class BaseModelForm(forms.ModelForm):
	def __init__(self, user_id=None, *args, **kwargs):
		super(BaseModelForm, self).__init__(*args, **kwargs)
		self.user_id = user_id

class ObjectForm(BaseModelForm):
	class Meta:
		model = models.Object
		exclude = ('observers',)
	
	owner = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'))
	location = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'), required=False)
	parents = forms.ModelMultipleChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.MultipleChoiceWidget('ObjectAutocomplete'), required=False)
	
	def clean_location(self):
		value = self.cleaned_data['location']
		return value.id if value else None
	
	def clean_owner(self):
		value = self.cleaned_data['owner']
		return value.id if value else None
	
	def clean_parents(self):
		value = self.cleaned_data['parents']
		return [x.id for x in value or []]
	
	def _post_clean(self):
		pass
	
	def save(self, force_insert=False, force_update=False, commit=True):
		tasks.modifyobject.delay(
			user_id		= self.user_id,
			object		= self.instance.id,
			name		= self.cleaned_data['name'],
			location	= self.cleaned_data['location'],
			owner		= self.cleaned_data['owner'],
			parents		= self.cleaned_data['parents']
		).get(timeout=5)
		return self

class PropertyForm(BaseModelForm):
	class Meta:
		model = models.Property
		exclude = ('origin',)
	
	value = forms.CharField(widget=widgets.HiddenInput)
	owner = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'))
	
	def clean_owner(self):
		value = self.cleaned_data['owner']
		return value.id if value else None
	
	def _post_clean(self):
		pass
	
	def save(self, force_insert=False, force_update=False, commit=True):
		tasks.modifyproperty.delay(
			user_id		= self.user_id,
			object		= self.instance.origin.id,
			property_id	= self.instance.id,
			name		= self.cleaned_data['name'],
			value		= self.cleaned_data['value'],
			type		= self.cleaned_data['type'],
			owner		= self.cleaned_data['owner'],
		).get(timeout=5)
		return self

class VerbForm(BaseModelForm):
	class Meta:
		model = models.Verb
		exclude = ('origin',)
	
	names = forms.CharField()
	code = forms.CharField(widget=widgets.HiddenInput)
	owner = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'))
	
	def clean_owner(self):
		value = self.cleaned_data['owner']
		return value.id if value else None
	<commit_msg>cleanup<commit_after>from django import forms
from django.forms import widgets
from django.forms.models import BaseModelFormSet

import autocomplete_light

from antioch.core import models
from antioch.plugins.editors import tasks

class AuthenticatedModelForm(forms.ModelForm):
	def __init__(self, user_id=None, *args, **kwargs):
		super(AuthenticatedModelForm, self).__init__(*args, **kwargs)
		self.user_id = user_id

class ObjectForm(AuthenticatedModelForm):
	class Meta:
		model = models.Object
		exclude = ('observers',)
	
	owner = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'))
	location = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'), required=False)
	parents = forms.ModelMultipleChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.MultipleChoiceWidget('ObjectAutocomplete'), required=False)
	
	def clean_location(self):
		value = self.cleaned_data['location']
		return value.id if value else None
	
	def clean_owner(self):
		value = self.cleaned_data['owner']
		return value.id if value else None
	
	def clean_parents(self):
		value = self.cleaned_data['parents']
		return [x.id for x in value or []]
	
	def _post_clean(self):
		pass
	
	def save(self, force_insert=False, force_update=False, commit=True):
		tasks.modifyobject.delay(
			user_id		= self.user_id,
			object		= self.instance.id,
			name		= self.cleaned_data['name'],
			location	= self.cleaned_data['location'],
			owner		= self.cleaned_data['owner'],
			parents		= self.cleaned_data['parents']
		).get(timeout=5)
		return self

class PropertyForm(AuthenticatedModelForm):
	class Meta:
		model = models.Property
		exclude = ('origin',)
	
	value = forms.CharField(widget=widgets.HiddenInput)
	owner = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'))
	
	def clean_owner(self):
		value = self.cleaned_data['owner']
		return value.id if value else None
	
	def _post_clean(self):
		pass
	
	def save(self, force_insert=False, force_update=False, commit=True):
		tasks.modifyproperty.delay(
			user_id		= self.user_id,
			object		= self.instance.origin.id,
			property_id	= self.instance.id,
			name		= self.cleaned_data['name'],
			value		= self.cleaned_data['value'],
			type		= self.cleaned_data['type'],
			owner		= self.cleaned_data['owner'],
		).get(timeout=5)
		return self

class VerbForm(AuthenticatedModelForm):
	class Meta:
		model = models.Verb
		exclude = ('origin',)
	
	names = forms.CharField()
	code = forms.CharField(widget=widgets.HiddenInput)
	owner = forms.ModelChoiceField(models.Object.objects.all(),
		widget=autocomplete_light.ChoiceWidget('ObjectAutocomplete'))
	
	def clean_owner(self):
		value = self.cleaned_data['owner']
		return value.id if value else None
	
{'fraction_non_alphanumeric': 0.11930815390045887, 'fraction_numerical': 0.0007059654076950229, 'mean_word_length': 5.261878453038674, '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': '112580', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1813, 'n_words': 360}