a
    Kcòf)#  ã                   @   sB  d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZ d dlmZ d d	lmZmZ d d
lmZmZ d dlmZ d dlmZmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl#m%Z& d dl'm(Z( d dl)m*Z* e e(ƒZ+e e*ƒ ƒZ,e -e¡G dd„ dej.ƒƒZ/e -e¡G dd„ dej.ƒƒZ0dS )é    )Úsettings)ÚadminÚmessages)ÚIS_POPUP_VAR)Úunquote)Úupdate_session_auth_hash)ÚAdminPasswordChangeFormÚUserChangeFormÚUserCreationForm)ÚGroupÚUser)ÚPermissionDenied)ÚrouterÚtransaction)ÚHttp404ÚHttpResponseRedirect)ÚTemplateResponse)ÚpathÚreverse)Úmethod_decorator)Úescape)Úgettext)Úgettext_lazy)Úcsrf_protect)Úsensitive_post_parametersc                       s*   e Zd ZdZdZdZd‡ fdd„	Z‡  ZS )Ú
GroupAdmin©Úname)ÚpermissionsNc                    sB   |j dkr*| d|jjj¡}| d¡|d< tƒ j|fd|i|¤ŽS )Nr   ZquerysetÚcontent_typeÚrequest)r   ÚgetZremote_fieldÚmodelÚobjectsZselect_relatedÚsuperÚformfield_for_manytomany)ÚselfZdb_fieldr    ÚkwargsÚqs©Ú	__class__© úV/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/contrib/auth/admin.pyr%   "   s    
z#GroupAdmin.formfield_for_manytomany)N)Ú__name__Ú
__module__Ú__qualname__Úsearch_fieldsÚorderingÚfilter_horizontalr%   Ú__classcell__r+   r+   r)   r,   r      s   r   c                       sð   e Zd ZdZdZdddifedƒddifedƒddifed	ƒdd
iffZddddœffZeZ	e
ZeZdZdZdZdZdZd$‡ fdd„	Zd%‡ fdd„	Z‡ fdd„Z‡ fdd„Zeed&dd„ƒƒZd'‡ fdd„	Zed(d d!„ƒZd)‡ fd"d#„	Z‡  ZS )*Ú	UserAdminzadmin/auth/user/add_form.htmlNÚfields)ÚusernameÚpasswordzPersonal info)Ú
first_nameÚ	last_nameÚemailZPermissions)Ú	is_activeÚis_staffÚis_superuserÚgroupsÚuser_permissionszImportant dates)Z
last_loginZdate_joined)Zwide)r6   Z	password1Z	password2)Úclassesr5   )r6   r:   r8   r9   r<   )r<   r=   r;   r>   )r6   r8   r9   r:   )r6   )r>   r?   c                    s   |s
| j S tƒ  ||¡S )N)Úadd_fieldsetsr$   Úget_fieldsets)r&   r    Úobjr)   r+   r,   rB   U   s    zUserAdmin.get_fieldsetsc                    s6   i }|du r| j |d< | |¡ tƒ j||fi |¤ŽS )z7
        Use special form during user creation
        NÚform)Úadd_formÚupdater$   Úget_form)r&   r    rC   r'   Údefaultsr)   r+   r,   rG   Z   s
    

zUserAdmin.get_formc                    s$   t d| j | j¡dd�gtƒ  ¡  S )Nz<id>/password/Zauth_user_password_changer   )r   Ú
admin_siteZ
admin_viewÚuser_change_passwordr$   Úget_urls)r&   r)   r+   r,   rK   d   s    ýÿúzUserAdmin.get_urlsc                    s   |  d¡ otƒ  ||¡S )Nr7   )Ú
startswithr$   Úlookup_allowed)r&   ÚlookupÚvaluer)   r+   r,   rM   m   s    ÿzUserAdmin.lookup_allowedÚ c                 C   sF   t jt | j¡d�� |  |||¡W  d   ƒ S 1 s80    Y  d S )N)Úusing)r   Zatomicr   Zdb_for_writer"   Ú	_add_view)r&   r    Úform_urlÚextra_contextr+   r+   r,   Úadd_views   s    zUserAdmin.add_viewc                    sh   |   |¡s&|  |¡r"tjr"tdƒ‚t‚|d u r2i }| j | jj	¡}d|j
dœ}| |¡ tƒ  |||¡S )Nz¯Your user does not have the "Change user" permission. In order to add users, Django requires that your user account have both the "Add user" and "Change user" permissions set.r+   )Zauto_populated_fieldsZusername_help_text)Úhas_change_permissionZhas_add_permissionr   ÚDEBUGr   r   ÚoptsÚ	get_fieldr"   ZUSERNAME_FIELDÚ	help_textrF   r$   rU   )r&   r    rS   rT   Zusername_fieldrH   r)   r+   r,   rR   y   s    
ÿþ
zUserAdmin._add_viewc                 C   sv  |   |t|ƒ¡}|  ||¡s t‚|d u rFttdƒ| jjt|ƒdœ ƒ‚|j	dkrÖ|  
||j¡}| ¡ rà| ¡  |  ||d ¡}|  |||¡ tdƒ}t ||¡ t||jƒ ttd| jj|jj|jjf |jfd�ƒS n
|  
|¡}d dt|jƒifg}tj  !||i ¡}	tdƒt| "¡ ƒ |	||t#|jv �p0t#|j$v t#d	d
d
d	d
| j|d
d	dœ| j %|¡¥}
| jj|_&t'|| j(�ppd|
ƒS )Nz8%(name)s object with primary key %(key)r does not exist.)r   ÚkeyÚPOSTzPassword changed successfully.z%s:%s_%s_change)Úargsr5   zChange password: %sTF)ÚtitleZ	adminFormrS   rD   Zis_popupZis_popup_varÚaddZchangeZhas_delete_permissionrV   Zhas_absolute_urlrX   ÚoriginalZsave_asZ	show_savez$admin/auth/user/change_password.html))Z
get_objectr   rV   r   r   Ú_rX   Zverbose_namer   ÚmethodÚchange_password_formr\   Zis_validÚsaveZconstruct_change_messageZ
log_changer   r   Úsuccessr   Úuserr   r   rI   r   Ú_metaZ	app_labelZ
model_nameÚpkÚlistÚbase_fieldsr   ÚhelpersZ	AdminFormZget_usernamer   ÚGETZeach_contextZcurrent_appr   Úchange_user_password_template)r&   r    ÚidrS   rf   rD   Zchange_messageÚmsgÚ	fieldsetsZ
admin_formÚcontextr+   r+   r,   rJ   •   sv    þÿÿ
ýÿùÿ
ñ
ð
üzUserAdmin.user_change_passwordc                    s:   d|j vr*t|j vr*|j  ¡ |_ d|j d< tƒ  |||¡S )zÒ
        Determine the HttpResponse for the add_view stage. It mostly defers to
        its superclass implementation but is customized because the User model
        has a slightly different workflow.
        Z_addanotheré   Z	_continue)r\   r   Úcopyr$   Úresponse_add)r&   r    rC   Zpost_url_continuer)   r+   r,   rt   Ø   s    
zUserAdmin.response_add)N)N)rP   N)rP   N)rP   )N)r-   r.   r/   Zadd_form_templaterm   ra   rp   rA   r	   rD   r
   rE   r   rc   Zlist_displayZlist_filterr0   r1   r2   rB   rG   rK   rM   Úsensitive_post_parameters_mÚcsrf_protect_mrU   rR   rJ   rt   r3   r+   r+   r)   r,   r4   +   sF   
ÿþñþþÿ	
	Br4   N)1Zdjango.confr   Zdjango.contribr   r   Zdjango.contrib.admin.optionsr   Zdjango.contrib.admin.utilsr   Zdjango.contrib.authr   Zdjango.contrib.auth.formsr   r	   r
   Zdjango.contrib.auth.modelsr   r   Zdjango.core.exceptionsr   Z	django.dbr   r   Zdjango.httpr   r   Zdjango.template.responser   Zdjango.urlsr   r   Zdjango.utils.decoratorsr   Zdjango.utils.htmlr   Zdjango.utils.translationr   r   ra   Zdjango.views.decorators.csrfr   Zdjango.views.decorators.debugr   rv   ru   ÚregisterZ
ModelAdminr   r4   r+   r+   r+   r,   Ú<module>   s.   
