<s> from __future__ import unicode_literals <EOL> import frappe <EOL> from frappe import _ <EOL> from frappe . model . document import Document <EOL> class WebsiteTheme ( Document ) : <EOL> def validate ( self ) : <EOL> self . validate_if_customizable ( ) <EOL> self . validate_colors ( ) <EOL> def on_update ( self ) : <EOL> if ( not self . custom <EOL> and frappe . local . conf . get ( '<STR_LIT>' ) <EOL> and not ( frappe . flags . in_import or frappe . flags . in_test ) ) : <EOL> self . export_doc ( ) <EOL> self . clear_cache_if_current_theme ( ) <EOL> def is_standard_and_not_valid_user ( self ) : <EOL> return ( not self . custom <EOL> and not frappe . local . conf . get ( '<STR_LIT>' ) <EOL> and not ( frappe . flags . in_import or frappe . flags . in_test ) ) <EOL> def on_trash ( self ) : <EOL> if self . is_standard_and_not_valid_user ( ) : <EOL> frappe . throw ( _ ( "<STR_LIT>" ) , <EOL> frappe . PermissionError ) <EOL> def validate_if_customizable ( self ) : <EOL> if self . is_standard_and_not_valid_user ( ) : <EOL> frappe . throw ( _ ( "<STR_LIT>" ) ) <EOL> def validate_colors ( self ) : <EOL> if ( self . top_bar_color or self . top_bar_text_color ) and self . top_bar_color == self . top_bar_text_color : <EOL> frappe . throw ( _ ( "<STR_LIT>" ) ) <EOL> def export_doc ( self ) : <EOL> """<STR_LIT>""" <EOL> from frappe . modules . export_file import export_to_files <EOL> export_to_files ( record_list = [ [ '<STR_LIT>' , self . name ] ] ) <EOL> def clear_cache_if_current_theme ( self ) : <EOL> website_settings = frappe . get_doc ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if getattr ( website_settings , "<STR_LIT>" , None ) == self . name : <EOL> website_settings . clear_cache ( ) <EOL> def use_theme ( self ) : <EOL> use_theme ( self . name ) <EOL> @ frappe . whitelist ( ) <EOL> def use_theme ( theme ) : <EOL> website_settings = frappe . get_doc ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> website_settings . website_theme = theme <EOL> website_settings . ignore_validate = True <EOL> website_settings . save ( ) <EOL> def add_website_theme ( context ) : <EOL> bootstrap = frappe . get_hooks ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> web_include_css = context . web_include_css <EOL> context . theme = frappe . _dict ( ) <EOL> if not context . disable_website_theme : <EOL> website_theme = get_active_theme ( ) <EOL> context . theme = website_theme and website_theme . as_dict ( ) or frappe . _dict ( ) <EOL> if website_theme : <EOL> if website_theme . bootstrap : <EOL> bootstrap = website_theme . bootstrap <EOL> context . no_sidebar = website_theme . no_sidebar <EOL> context . web_include_css = [ "<STR_LIT>" ] + context . web_include_css <EOL> context . web_include_css = [ bootstrap ] + context . web_include_css <EOL> def get_active_theme ( ) : <EOL> website_theme = frappe . db . get_value ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if website_theme : <EOL> try : <EOL> return frappe . get_doc ( "<STR_LIT>" , website_theme ) <EOL> except frappe . DoesNotExistError : <EOL> pass </s>
