o
    `Zh#                     @   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__ P/var/www/html/lang_env/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)   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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emailZPermissions)	is_activeis_staffis_superusergroupsuser_permissionszImportant dates)Z
last_loginZdate_joined)Zwide)r7   Z	password1Z	password2)classesr6   )r7   r;   r9   r:   r=   )r=   r>   r<   r?   )r7   r9   r:   r;   )r7   )r?   r@   c                    s   |s| j S t ||S r-   )add_fieldsetsr$   get_fieldsets)r&   r    objr)   r+   r,   rC   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    rD   r'   defaultsr)   r+   r,   rH   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,   rL   d   s   zUserAdmin.get_urlsc                    s   | d ot |||S )Nr8   )
startswithr$   lookup_allowed)r&   lookupvaluer    r)   r+   r,   rN   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   Zatomicr   Zdb_for_writer"   	_add_view)r&   r    form_urlextra_contextr+   r+   r,   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 )NzYour 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_textrG   r$   rV   )r&   r    rT   rU   Zusername_fieldrI   r)   r+   r,   rS   {   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 pt#|j$v t#d	d
d
d	d
| j|d
d	d| j%|}
| jj|_&t'|| j(pd|
S )Nz8%(name)s object with primary key %(key)r does not exist.)r   keyPOSTzPassword changed successfully.z%s:%s_%s_change)argsr6   zChange password: %sTF)titleZ	adminFormrT   rE   Zis_popupZis_popup_varaddZchangeZhas_delete_permissionrW   Zhas_absolute_urlrY   originalZsave_asZ	show_savez$admin/auth/user/change_password.html))Z
get_objectr   rW   r   r   _rY   Zverbose_namer   methodchange_password_formr]   Zis_validsaveZconstruct_change_messageZ
log_changer   r   successr   userr   r   rJ   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    idrT   rg   rE   Zchange_messagemsg	fieldsetsZ
admin_formcontextr+   r+   r,   rK      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.
        Z_addanother   Z	_continue)r]   r   copyr$   response_add)r&   r    rD   Zpost_url_continuer)   r+   r,   ru      s   
zUserAdmin.response_addr-   )rQ   N)rQ   )r.   r/   r0   Zadd_form_templatern   rb   rq   rB   r	   rE   r
   rF   r   rd   Zlist_displayZlist_filterr1   r2   r3   rC   rH   rL   rN   sensitive_post_parameters_mcsrf_protect_mrV   rS   rK   ru   r4   r+   r+   r)   r,   r5   +   sH    
	
Br5   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   rb   Zdjango.views.decorators.csrfr   Zdjango.views.decorators.debugr   rw   rv   registerZ
ModelAdminr   r5   r+   r+   r+   r,   <module>   s0    
