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   Zquerysetcontent_typerequest)r   getZremote_fieldmodelobjectsZselect_relatedsuperformfield_for_manytomany)selfZdb_fieldr    kwargsqs	__class__ /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/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)   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usable_passwordZ	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   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   Zatomicr   Zdb_for_writer"   )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$   r[   )r&   r    rY   rZ   Zusername_fieldrI   r)   r+   r,   rX   ~   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POSTZ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)argsr6   zChange password: %szSet password: %sTF)titleZ	adminFormrY   rE   Zis_popupZis_popup_varaddZchangeZhas_delete_permissionr\   Zhas_absolute_urlr^   originalZsave_asZ	show_savez$admin/auth/user/change_password.html)-Z
get_objectr   r\   r   r   _r^   Zverbose_namer   rW   change_password_formrb   Zis_validZcleaned_datar   r   errorr   Zget_full_pathsaveZconstruct_change_messageZ
log_changeZhas_usable_passwordsuccessr   userr   rJ   r   _metaZ	app_labelZ
model_namepklistbase_fieldsr   ZhelpersZ	AdminFormZget_usernamer   rR   Zeach_contextZcurrent_appr   change_user_password_template)r&   r    idrY   rl   rE   Zvalid_submissionmsgZchange_message	fieldsetsZ
admin_formrd   contextr+   r+   r,   rK      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.
        Z_addanother   Z	_continue)rb   r   copyr$   response_add)r&   r    rD   Zpost_url_continuer)   r+   r,   rx      s   
zUserAdmin.response_addr-   )rQ   N)rQ   )r.   r/   r0   Zadd_form_templaterq   rg   rt   rB   r
   rE   r	   rF   r   rh   Zlist_displayZlist_filterr1   r2   r3   rC   rH   rL   rN   sensitive_post_parameters_mcsrf_protect_mr[   rX   rK   rx   r4   r+   r+   r)   r,   r5   +   sH    
	
Wr5   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   rg   Zdjango.views.decorators.csrfr   Zdjango.views.decorators.debugr   rz   ry   registerZ
ModelAdminr   r5   r+   r+   r+   r,   <module>   s0    
