o
    ÔèFhÁ#  ã                   @   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   ÚquerysetÚcontent_typeÚrequest)r   ÚgetÚremote_fieldÚmodelÚobjectsÚselect_relatedÚsuperÚformfield_for_manytomany)ÚselfÚdb_fieldr!   ÚkwargsÚqs©Ú	__class__© úR/var/www/html/loop/nvenv/lib/python3.10/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-   r0   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d$‡ 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ÚemailÚPermissions)Ú	is_activeÚis_staffÚis_superuserÚgroupsÚuser_permissionszImportant dates)Ú
last_loginÚdate_joined)Úwide)r;   Ú	password1Ú	password2)Úclassesr:   )r;   r?   r=   r>   rB   )rB   rC   rA   rD   )r;   r=   r>   r?   )r;   )rD   rE   c                    s   |s| j S tƒ  ||¡S r1   )Úadd_fieldsetsr'   Úget_fieldsets)r)   r!   Úobjr-   r/   r0   rM   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!   rN   r+   Údefaultsr-   r/   r0   rR   Z   s
   

zUserAdmin.get_formc                    s$   t d| j | j¡dd�gtƒ  ¡  S )Nz<id>/password/Úauth_user_password_changer   )r   Ú
admin_siteÚ
admin_viewÚuser_change_passwordr'   Úget_urls)r)   r-   r/   r0   rX   d   s   ýÿúzUserAdmin.get_urlsc                    s   |  d¡ otƒ  |||¡S )Nr<   )Ú
startswithr'   Úlookup_allowed)r)   ÚlookupÚvaluer!   r-   r/   r0   rZ   o   s   ÿzUserAdmin.lookup_allowedÚ c                 C   sF   t jt | j¡d�� |  |||¡W  d   ƒ S 1 sw   Y  d S )N)Úusing)r   Úatomicr   Údb_for_writer$   Ú	_add_view)r)   r!   Úform_urlÚextra_contextr/   r/   r0   Úadd_viewu   s   $ÿzUserAdmin.add_viewc                    sh   |   |¡s|  |¡rtjrtdƒ‚t‚|d u ri }| 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/   )Úauto_populated_fieldsÚusername_help_text)Úhas_change_permissionÚhas_add_permissionr   ÚDEBUGr   r   ÚoptsÚ	get_fieldr$   ÚUSERNAME_FIELDÚ	help_textrQ   r'   rd   )r)   r!   rb   rc   Úusername_fieldrS   r-   r/   r0   ra   {   s   
ÿþ
zUserAdmin._add_viewc                 C   sr  |   |t|ƒ¡}|  ||¡st‚|d u r#ttdƒ| jjt|ƒdœ ƒ‚|j	dkrk|  
||j¡}| ¡ rj| ¡  |  ||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 p—t#|j$v t#d	d
d
d	d
| j|d
d	dœ| j %|¡¥}
| jj|_&t'|| j(p¶d|
ƒS )Nz8%(name)s object with primary key %(key)r does not exist.)r   ÚkeyÚPOSTzPassword changed successfully.z%s:%s_%s_change)Úargsr:   zChange password: %sTF)ÚtitleÚ	adminFormrb   rO   Úis_popupÚis_popup_varÚaddÚchangeÚhas_delete_permissionrg   Úhas_absolute_urlrj   ÚoriginalÚsave_asÚ	show_savez$admin/auth/user/change_password.html))Ú
get_objectr   rg   r   r   Ú_rj   Úverbose_namer   ÚmethodÚchange_password_formrp   Úis_validÚsaveÚconstruct_change_messageÚ
log_changer   r   Úsuccessr   Úuserr   r   rU   r   Ú_metaÚ	app_labelÚ
model_nameÚpkÚlistÚbase_fieldsr   ÚhelpersÚ	AdminFormÚget_usernamer   ÚGETÚeach_contextÚcurrent_appr   Úchange_user_password_template)r)   r!   Úidrb   r‡   rO   Úchange_messageÚmsgÚ	fieldsetsÚ
admin_formÚcontextr/   r/   r0   rW   —   sx   þÿÿ
ýÿùÿù
ñ
ð
ü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.
        Ú_addanotheré   Ú	_continue)rp   r   Úcopyr'   Úresponse_add)r)   r!   rN   Úpost_url_continuer-   r/   r0   rŸ   Ú   s   
zUserAdmin.response_addr1   )r]   N)r]   )r2   r3   r4   Úadd_form_templater”   r~   r˜   rL   r	   rO   r
   rP   r   r�   Úlist_displayÚlist_filterr5   r6   r7   rM   rR   rX   rZ   Úsensitive_post_parameters_mÚcsrf_protect_mrd   ra   rW   rŸ   r8   r/   r/   r-   r0   r9   +   sH    
ÿþñþþÿ	
Br9   N)1Údjango.confr   Údjango.contribr   r   Údjango.contrib.admin.optionsr   Údjango.contrib.admin.utilsr   Údjango.contrib.authr   Údjango.contrib.auth.formsr   r	   r
   Údjango.contrib.auth.modelsr   r   Údjango.core.exceptionsr   Ú	django.dbr   r   Údjango.httpr   r   Údjango.template.responser   Údjango.urlsr   r   Údjango.utils.decoratorsr   Údjango.utils.htmlr   Údjango.utils.translationr   r   r~   Údjango.views.decorators.csrfr   Údjango.views.decorators.debugr   r¥   r¤   ÚregisterÚ
ModelAdminr   r9   r/   r/   r/   r0   Ú<module>   s0    
