<s> from django . apps import apps <EOL> from django . db import DEFAULT_DB_ALIAS , router <EOL> from django . utils import six <EOL> from django . utils . six . moves import input <EOL> def update_contenttypes ( app_config , verbosity = <NUM_LIT:2> , interactive = True , using = DEFAULT_DB_ALIAS , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not app_config . models_module : <EOL> return <EOL> try : <EOL> ContentType = apps . get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except LookupError : <EOL> return <EOL> if not router . allow_migrate_model ( using , ContentType ) : <EOL> return <EOL> ContentType . objects . clear_cache ( ) <EOL> app_label = app_config . label <EOL> app_models = { <EOL> model . _meta . model_name : model <EOL> for model in app_config . get_models ( ) } <EOL> if not app_models : <EOL> return <EOL> content_types = { <EOL> ct . model : ct <EOL> for ct in ContentType . objects . using ( using ) . filter ( app_label = app_label ) <EOL> } <EOL> to_remove = [ <EOL> ct <EOL> for ( model_name , ct ) in six . iteritems ( content_types ) <EOL> if model_name not in app_models <EOL> ] <EOL> cts = [ <EOL> ContentType ( <EOL> app_label = app_label , <EOL> model = model_name , <EOL> ) <EOL> for ( model_name , model ) in six . iteritems ( app_models ) <EOL> if model_name not in content_types <EOL> ] <EOL> ContentType . objects . using ( using ) . bulk_create ( cts ) <EOL> if verbosity >= <NUM_LIT:2> : <EOL> for ct in cts : <EOL> print ( "<STR_LIT>" % ( ct . app_label , ct . model ) ) <EOL> if to_remove : <EOL> if interactive : <EOL> content_type_display = '<STR_LIT:\n>' . join ( <EOL> '<STR_LIT>' % ( ct . app_label , ct . model ) <EOL> for ct in to_remove <EOL> ) <EOL> ok_to_delete = input ( """<STR_LIT>""" % content_type_display ) <EOL> else : <EOL> ok_to_delete = False <EOL> if ok_to_delete == '<STR_LIT:yes>' : <EOL> for ct in to_remove : <EOL> if verbosity >= <NUM_LIT:2> : <EOL> print ( "<STR_LIT>" % ( ct . app_label , ct . model ) ) <EOL> ct . delete ( ) <EOL> else : <EOL> if verbosity >= <NUM_LIT:2> : <EOL> print ( "<STR_LIT>" ) </s>
