o
    {,h(                     @   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AdminUserCreationFormUserChangeForm)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__ O/var/www/html/rh/venv/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;   usable_password	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   rN   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!   rO   r+   defaultsr-   r/   r0   rS   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   rY   d   s   zUserAdmin.get_urlsc                    s   | d ot |||S )Nr<   )
startswithr'   lookup_allowed)r)   lookupvaluer!   r-   r/   r0   r[   o   s   zUserAdmin.lookup_allowed c                 C   s^   |j dv r| |||S tjt| jd | |||W  d    S 1 s(w   Y  d S )N)GETHEADOPTIONSTRACE)using)method	_add_viewr   atomicr   db_for_writer$   )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 )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/   )auto_populated_fieldsusername_help_text)has_change_permissionhas_add_permissionr   DEBUGr   r   opts	get_fieldr$   USERNAME_FIELD	help_textrR   r'   rj   )r)   r!   rh   ri   username_fieldrT   r-   r/   r0   re   ~   s   

zUserAdmin._add_viewc                 C   s  |  |t|}| ||st|d u r#ttd| jjt|d |j	dkr| 
||j}| r|jd p<d|jv }|sOtd}t|| t| S | }| ||d }| ||| | rjtd}n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 }
| rtd}n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POSTset_usable_passwordzunset-passwordz2Conflicting form data submitted. Please try again.zPassword changed successfully.z+Password-based authentication was disabled.z%s:%s_%s_change)argsr:   zChange password: %szSet password: %sTF)title	adminFormrh   rP   is_popupis_popup_varaddchangehas_delete_permissionrm   has_absolute_urlrp   originalsave_as	show_savez$admin/auth/user/change_password.html)-
get_objectr   rm   r   r   _rp   verbose_namer   rd   change_password_formrv   is_validcleaned_datar   r   errorr   get_full_pathsaveconstruct_change_message
log_changehas_usable_passwordsuccessr   userr   rV   r   _meta	app_label
model_namepklistbase_fieldsr   helpers	AdminFormget_usernamer   r_   each_contextcurrent_appr   change_user_password_template)r)   r!   idrh   r   rP   valid_submissionmsgchange_message	fieldsets
admin_formry   contextr/   r/   r0   rX      s   



$


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)rv   r   copyr'   response_add)r)   r!   rO   post_url_continuer-   r/   r0   r      s   
zUserAdmin.response_addr1   )r^   N)r^   )r2   r3   r4   add_form_templater   r   r   rM   r
   rP   r	   rQ   r   r   list_displaylist_filterr5   r6   r7   rN   rS   rY   r[   sensitive_post_parameters_mcsrf_protect_mrj   re   rX   r   r8   r/   r/   r-   r0   r9   +   sH    
	
Wr9   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    
