<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _

from frappe.model.document import Document

not_allowed_fieldtype_change = ['naming_series']

class PropertySetter(Document):
	def autoname(self):
		self.name = '{doctype}-{field}-{property}'.format(
			doctype = self.doc_type,
			field = self.field_name or self.row_name or 'main',
			property = self.property
		)

	def validate(self):
		self.validate_fieldtype_change()
		self.delete_property_setter()

		# clear cache
		frappe.clear_cache(doctype = self.doc_type)

	def validate_fieldtype_change(self):
		if self.field_name in not_allowed_fieldtype_change and \
			self.property == 'fieldtype':
			frappe.throw(_("Field type cannot be changed for {0}").format(self.field_name))

	def delete_property_setter(self):
		"""delete other property setters on this, if this is new"""
		if self.get('__islocal'):
			filters = dict(doc_type = self.doc_type, property=self.property)
			if self.field_name:
				dict['field_name'] = self.field_name

			frappe.db.delete('Property Setter', filters)

	def get_property_list(self, dt):
		return frappe.db.get_all('DocField',
			fields=['fieldname', 'label', 'fieldtype'],
			filters={
				'parent': dt,
				'fieldtype': ['not in', ('Section Break', 'Column Break', 'HTML', 'Read Only', 'Fold') + frappe.model.table_fields],
				'fieldname': ['!=', '']
			},
			order_by='label asc',
			as_dict=1
		)

	def get_setup_data(self):
		return {
			'doctypes': [d[0] for d in frappe.db.sql("select name from tabDocType")],
			'dt_properties': self.get_property_list('DocType'),
			'df_properties': self.get_property_list('DocField')
		}

	def get_field_ids(self):
		return frappe.db.sql("select name, fieldtype, label, fieldname from tabDocField where parent=%s", self.doc_type, as_dict = 1)

	def get_defaults(self):
		if not self.field_name:<commit_msg>fix(minor): typo<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _

from frappe.model.document import Document

not_allowed_fieldtype_change = ['naming_series']

class PropertySetter(Document):
	def autoname(self):
		self.name = '{doctype}-{field}-{property}'.format(
			doctype = self.doc_type,
			field = self.field_name or self.row_name or 'main',
			property = self.property
		)

	def validate(self):
		self.validate_fieldtype_change()
		self.delete_property_setter()

		# clear cache
		frappe.clear_cache(doctype = self.doc_type)

	def validate_fieldtype_change(self):
		if self.field_name in not_allowed_fieldtype_change and \
			self.property == 'fieldtype':
			frappe.throw(_("Field type cannot be changed for {0}").format(self.field_name))

	def delete_property_setter(self):
		"""delete other property setters on this, if this is new"""
		if self.get('__islocal'):
			filters = dict(doc_type = self.doc_type, property=self.property)
			if self.field_name:
				filters['field_name'] = self.field_name

			frappe.db.delete('Property Setter', filters)

	def get_property_list(self, dt):
		return frappe.db.get_all('DocField',
			fields=['fieldname', 'label', 'fieldtype'],
			filters={
				'parent': dt,
				'fieldtype': ['not in', ('Section Break', 'Column Break', 'HTML', 'Read Only', 'Fold') + frappe.model.table_fields],
				'fieldname': ['!=', '']
			},
			order_by='label asc',
			as_dict=1
		)

	def get_setup_data(self):
		return {
			'doctypes': [d[0] for d in frappe.db.sql("select name from tabDocType")],
			'dt_properties': self.get_property_list('DocType'),
			'df_properties': self.get_property_list('DocField')
		}

	def get_field_ids(self):
		return frappe.db.sql("select name, fieldtype, label, fieldname from tabDocField where parent=%s", self.doc_type, as_dict = 1)

	def get_defaults(self):
		if not self.field_name:
{'fraction_non_alphanumeric': 0.1340909090909091, 'fraction_numerical': 0.00404040404040404, 'mean_word_length': 4.859467455621302, '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': '3952289', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1345, 'n_words': 316}