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__© úY/var/www/html/premium_crap/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 )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_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 ¡}
| ¡ r°tdƒ}n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Ú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    
