<s> from __future__ import unicode_literals <EOL> import frappe <EOL> import frappe . utils <EOL> import json <EOL> from frappe . utils . jinja import validate_template <EOL> from frappe . model . document import Document <EOL> class PrintFormat ( Document ) : <EOL> def validate ( self ) : <EOL> if ( self . standard == "<STR_LIT>" <EOL> and not frappe . local . conf . get ( "<STR_LIT>" ) <EOL> and not ( frappe . flags . in_import or frappe . flags . in_test ) ) : <EOL> frappe . throw ( frappe . _ ( "<STR_LIT>" ) ) <EOL> self . old_doc_type = frappe . db . get_value ( '<STR_LIT>' , <EOL> self . name , '<STR_LIT>' ) <EOL> self . extract_images ( ) <EOL> if self . html : <EOL> validate_template ( self . html ) <EOL> def extract_images ( self ) : <EOL> from frappe . utils . file_manager import extract_images_from_html <EOL> if self . format_data : <EOL> data = json . loads ( self . format_data ) <EOL> for df in data : <EOL> if df . get ( '<STR_LIT>' ) and df [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' ) and df . get ( '<STR_LIT>' ) : <EOL> df [ '<STR_LIT>' ] = extract_images_from_html ( self , df [ '<STR_LIT>' ] ) <EOL> self . format_data = json . dumps ( data ) <EOL> def on_update ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) and self . old_doc_type : <EOL> frappe . clear_cache ( doctype = self . old_doc_type ) <EOL> if self . doc_type : <EOL> frappe . clear_cache ( doctype = self . doc_type ) <EOL> self . export_doc ( ) <EOL> def export_doc ( self ) : <EOL> if self . standard == '<STR_LIT>' and ( frappe . conf . get ( '<STR_LIT>' ) or <NUM_LIT:0> ) == <NUM_LIT:1> : <EOL> module = frappe . db . get_value ( "<STR_LIT>" , self . doc_type , "<STR_LIT>" ) <EOL> from frappe . modules . export_file import export_to_files <EOL> export_to_files ( record_list = [ [ '<STR_LIT>' , self . name ] ] , <EOL> record_module = module ) <EOL> def on_trash ( self ) : <EOL> if self . doc_type : <EOL> frappe . clear_cache ( doctype = self . doc_type ) <EOL> @ frappe . whitelist ( ) <EOL> def make_default ( name ) : <EOL> """<STR_LIT>""" <EOL> frappe . has_permission ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> print_format = frappe . get_doc ( "<STR_LIT>" , name ) <EOL> if ( frappe . conf . get ( '<STR_LIT>' ) or <NUM_LIT:0> ) == <NUM_LIT:1> : <EOL> doctype = frappe . get_doc ( "<STR_LIT>" , print_format . doc_type ) <EOL> doctype . default_print_format = name <EOL> doctype . save ( ) <EOL> else : <EOL> frappe . make_property_setter ( { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : print_format . doc_type , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:value>' : name , <EOL> } ) <EOL> frappe . msgprint ( frappe . _ ( "<STR_LIT>" ) ) </s>
