
    Vh+                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZ 	 d dlZdZ	 d dlZdZ G d	 d
e      Z G d de      Zy# e$ r dZY 'w xY w# e$ r dZY -w xY w)    N)apps)serializers)BaseCommandCommandError)parse_apps_and_model_labels)DEFAULT_DB_ALIASconnectionsrouterTFc                       e Zd Zy)ProxyModelWarningN)__name__
__module____qualname__     X/home/dcms/DCMS/lib/python3.12/site-packages/django/core/management/commands/dumpdata.pyr   r      s    r   r   c                       e Zd ZdZd Zd Zy)CommandzOutput the contents of the database as a fixture of the given format (using each model's default manager unless --all is specified).c                    |j                  dddd       |j                  ddd	       |j                  d
t        d       |j                  dt        t        t              d       |j                  dddg d       |j                  dddd       |j                  dddd       |j                  ddddd        |j                  d!d"d#$       |j                  d%d&d'(       y ))Nargszapp_label[.ModelName]*zHRestricts dumped data to the specified app_label or app_label.ModelName.)metavarnargshelpz--formatjsonz7Specifies the output serialization format for fixtures.)defaultr   z--indentz>Specifies the indent level to use when pretty-printing output.)typer   z
--databasezXNominates a specific database to dump fixtures from. Defaults to the "default" database.)r   choicesr   z-ez	--excludeappendzhAn app_label or app_label.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).)actionr   r   z--natural-foreign
store_trueuse_natural_foreign_keysz/Use natural foreign keys if they are available.)r    destr   z--natural-primaryuse_natural_primary_keysz/Use natural primary keys if they are available.z-az--alluse_base_managerzUse Django's base manager to dump all models stored in the database, including those that would otherwise be filtered or modified by a custom manager.z--pksprimary_keyszOnly dump objects with given primary keys. Accepts a comma-separated list of keys. This option only works when you specify one model.)r#   r   z-oz--outputz.Specifies file to which the output is written.)r   )add_argumentintr   tupler	   )selfparsers     r   add_argumentszCommand.add_arguments$   sT   +' 	 	
 	J 	 	

 	Q 	 	

 	$+&2	 	 	
 	H 	 	
 	+B	 	 	
 	+B	 	 	
 	#" 	 
	
 	O 	 	
 	*#S 	 	
r   c           
         !"# |d   }|d   }|d   #|d   }|d   }|d   }|d   "|d   }|d	   !|d
   }	|	r.|	j                  d      D 
cg c]  }
|
j                          c}
 ng  t        |      \  |s> rt        d      t        j                  fdt        j                         D              nt        |      dkD  r rt        d      i |D ]y  }	 |j                  d      \  }}	 t        j                  |      }|j                  |v r?	 |j                  |      }j                  |g       }|||vr|j                  |       { |t#        j$                         vr$	 t#        j&                  |       t        d|z        d! !"#fd	}	 d | j*                  _        d }d}|r@| j*                  j/                         r&|d   dkD  r| j*                  }t1         |d            }|rt2        j4                  j7                  |      \  }}t8        i |ft:        j8                  i |ft8        i |ft8        i |ft8        i |fd}t<        rt>        j8                  i |f|d<   t@        r<tB        j8                  dtB        jD                  i|f|d<   tB        j8                  i |f|d<   	 ||   \  }}}||k7  r@t2        j4                  jI                  |      }tK        jL                  d| d| dtN                ||dfi |}nd }	 t#        jP                  | |       |"||xs | j*                  ||       |r|jS                          y y c c}
w # t        $ r}t        t        |            d }~ww xY w# t        $ r t        d|d|      w xY w# t         $ rg  rt        d      |}	 t        j                  |      }n%# t        $ r}t        t        |            d }~ww xY w|j                  |v rY !d |<   Y )w xY w# t"        j(                  $ r Y w xY w# tF        $ r t8        i |}}}Y w xY w# |r|jS                          w w xY w# tT        $ r}|r t        d |z        d }~ww xY w)"Nformatindentdatabaseexcludeoutput	tracebackr"   r$   r%   r&   ,z,You can only use --pks option with one modelc              3   B   K   | ]  }|j                   |vr|  y w)N)models_module).0
app_configexcluded_appss     r   	<genexpr>z!Command.handle.<locals>.<genexpr>~   s-      %++7m3 %s      .zUnknown model: z Unknown serialization format: %sc              3     K   r&t        j                  j                         d      }nMg }j                         D ]8  \  }}| |j                  |j	                                (|j                  |       : |D ]Q  }|	v r	|j
                  j                  rJ|j
                  j                  |vr2t        j                  d|j
                  j                  z  t               |j
                  j                  rt        j                  |      sr|j                  }n|j                  }|j!                        j#                  |j
                  j$                  j&                        }
r|j)                  
      }| r"|j#                         j+                          (|j,                  rdnd}|j/                  |      E d{    T y7 w)	z
            Collate the objects to be serialized. If count_only is True, just
            count the number of objects to be serialized.
            T)allow_cyclesNz,%s is a proxy model and won't be serialized.)category)pk__ini  )
chunk_size)r   sort_dependenciesitemsextend
get_models_metaproxyproxy_for_modelwarningswarnlabelr   r
   allow_migrate_model_base_manager_default_managerusingorder_bypknamefiltercount_prefetch_related_lookupsiterator)
count_onlymodelsr8   
model_listmodelobjectsquerysetrA   app_listexcluded_modelsr&   r%   r"   rO   s           r   get_objectsz#Command.handle.<locals>.get_objects   s    
 ($66NN$4 .6nn.> 2*J
!)j&;&;&=>j1	2
   LO+;;$$)D)DF)RMMF++++,!2
 {{((V-G-Gu-U'"'"5"5"'"8"8&}}U3<<U[[^^=P=PQH##+??,?#G!&//17799 %-$F$FDD # $,#4#4
#4#KKK1L0 Ls   C7G;GB6GG		Gr   	verbosityT)rW   ).bz2z.gz.lzma.xzz.zipra   rb   rc   zUnsupported file extension (z). Fixtures saved in 'z'.wt)r/   r"   r$   streamprogress_outputobject_countz Unable to serialize database: %s)F)+splitstripr   r   dictfromkeysr   get_app_configslenget_app_configLookupErrorstrr6   	get_model
setdefaultr   
ValueErrorr   get_public_serializer_formatsget_serializerSerializerDoesNotExiststdoutendingisattysumospathsplitextopengziphas_bz2bz2has_lzmalzmaFORMAT_ALONEKeyErrorbasenamerI   rJ   RuntimeWarning	serializeclose	Exception)$r*   
app_labelsoptionsr.   r/   excludesr2   show_tracebackr$   pksrQ   rK   	app_labelmodel_labelr8   erZ   app_list_valuer_   rf   rg   	file_rootfile_extcompression_formatsopen_methodkwargs	file_path	file_namere   r]   r9   r^   r&   r%   r"   rO   s$                                @@@@@@@r   handlezCommand.handleh   s   ""
#9%" -#*+E#F #*+E#F "#56n%143@2BHHJ@LL)DX)N&"#QRR}} %"&"6"6"8% H :"|"#QRRH# $0#0-2[[-=*I{3%)%8%8%C
 "//7:;V  * 4 4[ A &.%8%8R%HN
 &1e>6Q&--e4-$0P BBDD**62 AFJKK*	L *	LX9	G!%DKK"OL$++,,.7;3G!3K"&++";$#?@&(gg&6&6v&>#	8!2y1 IIr62"B	2 "i0!2y1'# 3688R2H'/		!4#4#454'0
 37))R1H'.H5H5R2K & " 0 0 ;IMM6xj A..7[<&
 %Y??#%%M!-E-E!0T[[$3!-	 LLN G A0 ' 3*3q6223 ' *6?M  " 0#*J  !&I3%)%8%8%C
& 3*3q6223!//7:;V +/HZ(0( 55 Z   H6:BKH0 LLN  	GAAEFF	Gs   MN2MNM5*)N,P DQ +	P  4AQ 0P: 7Q 	M2M--M22N5NNP,OP	O$OO$$P:PPPP P73Q 6P77Q :QQ 	Q1Q,,Q1N)r   r   r   r   r,   r   r   r   r   r   r      s    	J 	
B
HuGr   r   )r   r{   rI   django.appsr   django.corer   django.core.management.baser   r   django.core.management.utilsr   	django.dbr   r	   r
   r   r   ImportErrorr   r   Warningr   r   r   r   r   <module>r      s     	   # A D ; ;GH
	 	Gk G  G  Hs"   A A# A A #A-,A-