text: # -*- coding: utf-8 -*-
  # Copyright (c) 2021, PibiCo and contributors
  # For license information, please see license.txt
  
  from __future__ import unicode_literals
  import frappe
  from frappe.model.document import Document
  from frappe import _
  from frappe.desk.form.linked_with import get_linked_doctypes
  
  class Participant(Document):
  	def validate(self):
  		self.title = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name]))
  
  		if frappe.get_value("Participant", self.name, "title") != self.title:
  			self.update_participant_name_in_linked_doctype()
  
  	def update_participant_name_in_linked_doctype(self):
  		linked_doctypes = get_linked_doctypes("Participant")
  		for d in linked_doctypes:
  			meta = frappe.get_meta(d)
  			if not meta.issingle:
  				if "participant_name" in [f.fieldname for f in meta.fields]:
  					frappe.db.sql("""UPDATE `tab{0}` set participant_name = %s where {1} = %s"""
  						.format(d, linked_doctypes[d]["fieldname"][0]),(self.title, self.name))
  
  				if "child_doctype" in linked_doctypes[d].keys() and "participant_name" in \
  					[f.fieldname for f in frappe.get_meta(linked_doctypes[d]["child_doctype"]).fields]:
  					frappe.db.sql("""UPDATE `tab{0}` set participant_name = %s where {1} = %s"""
  						.format(linked_doctypes[d]["child_doctype"], linked_doctypes[d]["fieldname"][0]),(self.title, self.name))
  