<s> import os <EOL> from django . db . models . signals import post_delete , post_save <EOL> from django . db . models . signals import pre_delete <EOL> from lfs . catalog . models import File , Property <EOL> from lfs . catalog . models import Image <EOL> from lfs . catalog . models import ProductAttachment <EOL> from lfs . catalog . models import PropertyGroup <EOL> from lfs . catalog . models import ProductPropertyValue <EOL> from lfs . catalog . models import PropertyOption <EOL> from lfs . catalog . models import GroupsPropertiesRelation <EOL> from lfs . catalog . settings import DELETE_FILES , PROPERTY_VALUE_TYPE_FILTER <EOL> from lfs . catalog . settings import DELETE_IMAGES <EOL> from lfs . catalog . settings import THUMBNAIL_SIZES <EOL> from lfs . core . signals import property_type_changed <EOL> from lfs . core . signals import product_removed_property_group <EOL> def property_option_deleted_listener ( sender , instance , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> prop = instance . property <EOL> ProductPropertyValue . objects . filter ( property = prop , value = str ( instance . id ) ) . delete ( ) <EOL> pre_delete . connect ( property_option_deleted_listener , sender = PropertyOption ) <EOL> def property_group_deleted_listener ( sender , instance , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ProductPropertyValue . objects . filter ( property_group = instance ) . delete ( ) <EOL> pre_delete . connect ( property_group_deleted_listener , sender = PropertyGroup ) <EOL> def property_removed_from_property_group_listener ( sender , instance , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ProductPropertyValue . objects . filter ( property_group = instance . group , property = instance . property ) . delete ( ) <EOL> pre_delete . connect ( property_removed_from_property_group_listener , sender = GroupsPropertiesRelation ) <EOL> def product_removed_from_property_group_listener ( sender , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> property_group = sender <EOL> product = kwargs . get ( "<STR_LIT>" ) <EOL> ProductPropertyValue . objects . filter ( product = product , property_group = property_group ) . delete ( ) <EOL> product_removed_property_group . connect ( product_removed_from_property_group_listener ) <EOL> def property_changed_to_not_filterable_listener ( sender , instance , created , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not instance . filterable : <EOL> ProductPropertyValue . objects . filter ( property = instance , type = PROPERTY_VALUE_TYPE_FILTER ) . delete ( ) <EOL> post_save . connect ( property_changed_to_not_filterable_listener , sender = Property ) <EOL> def property_type_changed_listener ( sender , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ProductPropertyValue . objects . filter ( property = sender ) . delete ( ) <EOL> property_type_changed . connect ( property_type_changed_listener ) <EOL> def delete_image_files ( sender , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if DELETE_IMAGES : <EOL> image = kwargs . get ( "<STR_LIT>" ) <EOL> try : <EOL> path = image . image . _get_path ( ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> try : <EOL> os . remove ( path ) <EOL> except OSError : <EOL> pass <EOL> base , ext = os . path . splitext ( path ) <EOL> for width , height in THUMBNAIL_SIZES : <EOL> try : <EOL> os . remove ( "<STR_LIT>" % ( base , width , height , ext ) ) <EOL> except OSError : <EOL> continue <EOL> post_delete . connect ( delete_image_files , sender = Image ) <EOL> def delete_file_files ( sender , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if DELETE_FILES : <EOL> file = kwargs . get ( "<STR_LIT>" ) <EOL> try : <EOL> path = file . file . _get_path ( ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> try : <EOL> os . remove ( path ) <EOL> except OSError : <EOL> pass <EOL> post_delete . connect ( delete_file_files , sender = ProductAttachment ) <EOL> post_delete . connect ( delete_file_files , sender = File ) </s>
