U
    {hV                     @   sP  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 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mZmZmZ d dlmZ d dlmZmZ dd Z e!ddd Z"e!ddd Z#e$eddre!ddd Z%e!ddd Z&e!ddd  Z'e!d!d"d# Z(e!d!d$d% Z)d&S )'    )settings)
Permission)redirect_to_login)models)reverse)capfirst)gettext_lazy)ngettext)hooks)get_content_languages)LogFormatter)ModelLogEntryPagePageLogEntryPageViewRestriction)PageLinkHandler)parse_datetime_localizedrender_timestampc                 C   s   t tdtd}t| |S )NZWAGTAIL_FRONTEND_LOGIN_URLZwagtailcore_login)getattrr   r   r   )nextZ	login_url r   ]/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/wagtail_hooks.pyrequire_wagtail_login   s      r   Zbefore_serve_pagec                 C   s   |   D ]}||s|jtjkrhddlm} ||d| id}td|j	| j	gd}| 
|||  S |jtjtjfkrt| d  S qdS )	a[  
    Check whether there are any view restrictions on this page which are
    not fulfilled by the given request object. If there are, return an
    HttpResponse that will notify the user of that restriction (and possibly
    include a password / login form that will allow them to proceed). If
    there are no such restrictions, return None
    r   )PasswordViewRestrictionFormZ
return_url)instanceinitialZ&wagtailcore_authenticate_with_password)args)r   N)Zget_view_restrictionsZaccept_requestZrestriction_typer   ZPASSWORDZwagtail.formsr   Zget_full_pathr   idZ serve_password_required_responseZLOGINZGROUPSr   )pagerequestZ
serve_argsZserve_kwargsrestrictionr   formZ
action_urlr   r   r   check_view_restrictions   s$    	


r"   Zregister_rich_text_featuresc                 C   sh   | j d | j d | t | j d | j d | j dddg | j d | j d	 d S )
NhrlinkbolditalicZh2Zh3Zh4olZul)Zdefault_featuresappendZregister_link_typer   extend)featuresr   r   r   register_core_features8   s    
r+   ZWAGTAIL_WORKFLOW_ENABLEDTZregister_permissionsc                   C   s   t jjddddgdS )NwagtailcoreZadd_workflowZchange_workflowZdelete_workflowZcontent_type__app_labelZcodename__inr   objectsfilterr   r   r   r   register_workflow_permissionsL   s    r1   c                   C   s   t jjddddgdS )Nr,   add_taskZchange_taskZdelete_taskr-   r.   r   r   r   r   register_task_permissionsS   s    r3   Zdescribe_collection_contentsc                 C   s8   |    }|r4td}|tdd|d|i |dS d S )Nzwagtailadmin_collections:indexz%(count)s descendant collectionz %(count)s descendant collectionscount)r4   Z
count_texturl)Zget_descendantsr4   r   r	   )Z
collectionZdescendant_countr5   r   r   r   describe_collection_children[   s    r6   Zregister_log_actionsc                 C   s(  |  tjt |  tt | dtdtd | dtdtd | dtdtd	 | d
tdtd | dtdtd | dtdtd | dtdtd | dtdtd | dtdtd | dtdtd | dtd td! | d"G d#d$ d$t}| d%G d&d' d't}| d(G d)d* d*t}| d+G d,d- d-t}| d.G d/d0 d0t}| d1G d2d3 d3t}| d4G d5d6 d6t}| d7G d8d9 d9t}| d:G d;d< d<t}	| d=G d>d? d?t}
| d@G dAdB dBt}| dCG dDdE dEt}| dFG dGdH dHt}G dIdJ dJt}| dKG dLdM dM|}| dNG dOdP dP|}| dQG dRdS dS|}| dTG dUdV dV|}| dWG dXdY dY|}| dZG d[d\ d\|}| d]G d^d_ d_|}d S )`Nzwagtail.createZCreateCreatedzwagtail.editZEditZEditedzwagtail.deleteDeleteDeletedzwagtail.publishZPublishZ	Publishedzwagtail.publish.scheduledzPublish scheduled draftzPublished scheduled draftzwagtail.unpublishZ	UnpublishZUnpublishedzwagtail.unpublish.scheduledzUnpublish scheduled draftzUnpublished scheduled draftzwagtail.lockLockLockedzwagtail.unlockZUnlockZUnlockedzwagtail.moderation.approveZApproveZApprovedzwagtail.moderation.rejectZRejectZRejectedzwagtail.renamec                   @   s   e Zd ZedZdd ZdS )z8register_core_log_actions.<locals>.RenameActionFormatterZRenamec                 S   sJ   z(t d|jd d |jd d d W S  tk
rD   t d Y S X d S )Nz#Renamed from '%(old)s' to '%(new)s'titleoldnew)r=   r>   ZRenamed_dataKeyErrorselfZ	log_entryr   r   r   format_message   s    
zGregister_core_log_actions.<locals>.RenameActionFormatter.format_messageN__name__
__module____qualname__r@   labelrE   r   r   r   r   RenameActionFormatter   s   rK   zwagtail.revertc                   @   s   e Zd ZedZdd ZdS )z8register_core_log_actions.<locals>.RevertActionFormatterZRevertc                 S   sR   z0t d|jd d tt|jd d d W S  tk
rL   t d Y S X d S )NzIReverted to previous revision with id %(revision_id)s from %(created_at)srevisionr   created)revision_id
created_atzReverted to previous revision)r@   rA   r   r   rB   rC   r   r   r   rE      s    
zGregister_core_log_actions.<locals>.RevertActionFormatter.format_messageNrF   r   r   r   r   RevertActionFormatter   s   rP   zwagtail.copyc                   @   s   e Zd ZedZdd ZdS )z6register_core_log_actions.<locals>.CopyActionFormatterZCopyc                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )NzCopied from %(title)sr<   sourceZCopiedr?   rC   r   r   r   rE      s     zEregister_core_log_actions.<locals>.CopyActionFormatter.format_messageNrF   r   r   r   r   CopyActionFormatter   s   rR   zwagtail.copy_for_translationc                   @   s   e Zd ZedZdd ZdS )zDregister_core_log_actions.<locals>.CopyForTranslationActionFormatterzCopy for translationc                 S   sV   z4t d|jd d t |jd d p,dd W S  tk
rP   t d Y S X d S )	Nz2Copied for translation from %(title)s (%(locale)s)rQ   r<   Zsource_localeZlanguage_code )r<   localezCopied for translation)r@   rA   r   getrB   rC   r   r   r   rE      s    
zSregister_core_log_actions.<locals>.CopyForTranslationActionFormatter.format_messageNrF   r   r   r   r   !CopyForTranslationActionFormatter   s   rV   zwagtail.create_aliasc                   @   s   e Zd ZedZdd ZdS )z=register_core_log_actions.<locals>.CreateAliasActionFormatterzCreate aliasc                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )NzCreated an alias of %(title)sr<   rQ   zCreated an aliasr?   rC   r   r   r   rE      s     zLregister_core_log_actions.<locals>.CreateAliasActionFormatter.format_messageNrF   r   r   r   r   CreateAliasActionFormatter   s   rW   zwagtail.convert_aliasc                   @   s   e Zd ZedZdd ZdS )z>register_core_log_actions.<locals>.ConvertAliasActionFormatterz Convert alias into ordinary pagec                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )Nz5Converted the alias '%(title)s' into an ordinary pager<   r   z(Converted an alias into an ordinary pager?   rC   r   r   r   rE      s     zMregister_core_log_actions.<locals>.ConvertAliasActionFormatter.format_messageNrF   r   r   r   r   ConvertAliasActionFormatter   s   rX   zwagtail.movec                   @   s   e Zd ZedZdd ZdS )z6register_core_log_actions.<locals>.MoveActionFormatterZMovec                 S   sJ   z(t d|jd d |jd d d W S  tk
rD   t d Y S X d S )Nz/Moved from '%(old_parent)s' to '%(new_parent)s'rQ   r<   destination)Z
old_parentZ
new_parentZMovedr?   rC   r   r   r   rE      s    
zEregister_core_log_actions.<locals>.MoveActionFormatter.format_messageNrF   r   r   r   r   MoveActionFormatter   s   rZ   zwagtail.reorderc                   @   s   e Zd ZedZdd ZdS )z9register_core_log_actions.<locals>.ReorderActionFormatterZReorderc                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )NzReordered under '%(parent)s'parentrY   r<   Z	Reorderedr?   rC   r   r   r   rE      s     zHregister_core_log_actions.<locals>.ReorderActionFormatter.format_messageNrF   r   r   r   r   ReorderActionFormatter   s   r\   zwagtail.publish.schedulec                   @   s   e Zd ZedZdd ZdS )zAregister_core_log_actions.<locals>.SchedulePublishActionFormatterzSchedule publicationc                 S   s   zz|j d d rTtd|j d d tt|j d d tt|j d d d W S tddtt|j d d i W S W n tk
r   td	 Y S X d S )
NrL   has_live_versionzXRevision %(revision_id)s from %(created_at)s scheduled for publishing at %(go_live_at)s.r   rM   
go_live_atrN   rO   r^   z/Page scheduled for publishing at %(go_live_at)szPage scheduled for publishingrA   r@   r   r   rB   rC   r   r   r   rE      s8     zPregister_core_log_actions.<locals>.SchedulePublishActionFormatter.format_messageNrF   r   r   r   r   SchedulePublishActionFormatter   s   ra   zwagtail.schedule.cancelc                   @   s   e Zd ZedZdd ZdS )zGregister_core_log_actions.<locals>.UnschedulePublicationActionFormatterzUnschedule publicationc                 S   s   z|j d d rftd|j d d tt|j d d |j d d rZtt|j d d nd d W S tdd|j d d rtt|j d d nd i W S W n tk
r   td	 Y S X d S )
NrL   r]   z[Revision %(revision_id)s from %(created_at)s unscheduled from publishing at %(go_live_at)s.r   rM   r^   r_   z1Page unscheduled for publishing at %(go_live_at)sz Page unscheduled from publishingr`   rC   r   r   r   rE     s@    
	zVregister_core_log_actions.<locals>.UnschedulePublicationActionFormatter.format_messageNrF   r   r   r   r   $UnschedulePublicationActionFormatter  s   rb   zwagtail.view_restriction.createc                   @   s   e Zd ZedZdd ZdS )zDregister_core_log_actions.<locals>.AddViewRestrictionActionFormatterzAdd view restrictionsc                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )Nz,Added the '%(restriction)s' view restrictionr    r<   zAdded view restrictionr?   rC   r   r   r   rE   >  s     zSregister_core_log_actions.<locals>.AddViewRestrictionActionFormatter.format_messageNrF   r   r   r   r   !AddViewRestrictionActionFormatter:  s   rc   zwagtail.view_restriction.editc                   @   s   e Zd ZedZdd ZdS )zEregister_core_log_actions.<locals>.EditViewRestrictionActionFormatterzUpdate view restrictionsc                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )Nz1Updated the view restriction to '%(restriction)s'r    r<   zUpdated view restrictionr?   rC   r   r   r   rE   J  s     zTregister_core_log_actions.<locals>.EditViewRestrictionActionFormatter.format_messageNrF   r   r   r   r   "EditViewRestrictionActionFormatterF  s   rd   zwagtail.view_restriction.deletec                   @   s   e Zd ZedZdd ZdS )zGregister_core_log_actions.<locals>.DeleteViewRestrictionActionFormatterzRemove view restrictionsc                 S   s>   zt dd|jd d i W S  tk
r8   t d Y S X d S )NzCRemoved the '%(restriction)s' view restriction. The page is public.r    r<   zRemoved view restrictionr?   rC   r   r   r   rE   V  s     zVregister_core_log_actions.<locals>.DeleteViewRestrictionActionFormatter.format_messageNrF   r   r   r   r   $DeleteViewRestrictionActionFormatterR  s   re   c                   @   s   e Zd Zedd ZdS )z6register_core_log_actions.<locals>.CommentLogFormatterc                 S   s    | dd }t| j|jS )z
            Finds the translated field label for the given model and content path

            Raises LookupError if not found
            .r   )splitr   _meta	get_fieldZverbose_name)modelZcontent_path
field_namer   r   r   _field_label_from_content_patha  s    zUregister_core_log_actions.<locals>.CommentLogFormatter._field_label_from_content_pathN)rG   rH   rI   staticmethodrl   r   r   r   r   CommentLogFormatter`  s   rn   zwagtail.comments.createc                   @   s   e Zd ZedZdd ZdS )z?register_core_log_actions.<locals>.CreateCommentActionFormatterzAdd commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz.Added a comment on field %(field)s: "%(text)s"commentcontentpathtextfieldrq   zAdded a commentr@   rl   r   Zspecific_classrA   rB   rC   r   r   r   rE   o  s    
zNregister_core_log_actions.<locals>.CreateCommentActionFormatter.format_messageNrF   r   r   r   r   CreateCommentActionFormatterk  s   ru   zwagtail.comments.editc                   @   s   e Zd ZedZdd ZdS )z=register_core_log_actions.<locals>.EditCommentActionFormatterzEdit commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz/Edited a comment on field %(field)s: "%(text)s"ro   rp   rq   rr   zEdited a commentrt   rC   r   r   r   rE     s    
zLregister_core_log_actions.<locals>.EditCommentActionFormatter.format_messageNrF   r   r   r   r   EditCommentActionFormatter{  s   rv   zwagtail.comments.deletec                   @   s   e Zd ZedZdd ZdS )z?register_core_log_actions.<locals>.DeleteCommentActionFormatterzDelete commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz0Deleted a comment on field %(field)s: "%(text)s"ro   rp   rq   rr   zDeleted a commentrt   rC   r   r   r   rE     s    
zNregister_core_log_actions.<locals>.DeleteCommentActionFormatter.format_messageNrF   r   r   r   r   DeleteCommentActionFormatter  s   rw   zwagtail.comments.resolvec                   @   s   e Zd ZedZdd ZdS )z@register_core_log_actions.<locals>.ResolveCommentActionFormatterzResolve commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz1Resolved a comment on field %(field)s: "%(text)s"ro   rp   rq   rr   zResolved a commentrt   rC   r   r   r   rE     s    
zOregister_core_log_actions.<locals>.ResolveCommentActionFormatter.format_messageNrF   r   r   r   r   ResolveCommentActionFormatter  s   rx   zwagtail.comments.create_replyc                   @   s   e Zd ZedZdd ZdS )z=register_core_log_actions.<locals>.CreateReplyActionFormatterzReply to commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz1Replied to comment on field %(field)s: "%(text)s"ro   rp   replyrq   rr   zReplied to a commentrt   rC   r   r   r   rE     s    
zLregister_core_log_actions.<locals>.CreateReplyActionFormatter.format_messageNrF   r   r   r   r   CreateReplyActionFormatter  s   rz   zwagtail.comments.edit_replyc                   @   s   e Zd ZedZdd ZdS )z;register_core_log_actions.<locals>.EditReplyActionFormatterzEdit reply to commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz:Edited a reply to a comment on field %(field)s: "%(text)s"ro   rp   ry   rq   rr   zEdited a replyrt   rC   r   r   r   rE     s    	zJregister_core_log_actions.<locals>.EditReplyActionFormatter.format_messageNrF   r   r   r   r   EditReplyActionFormatter  s   r{   zwagtail.comments.delete_replyc                   @   s   e Zd ZedZdd ZdS )z=register_core_log_actions.<locals>.DeleteReplyActionFormatterzDelete reply to commentc                 S   sV   z4t d| |jj|jd d |jd d d W S  tk
rP   t d Y S X d S )Nz;Deleted a reply to a comment on field %(field)s: "%(text)s"ro   rp   ry   rq   rr   zDeleted a replyrt   rC   r   r   r   rE     s    	zLregister_core_log_actions.<locals>.DeleteReplyActionFormatter.format_messageNrF   r   r   r   r   DeleteReplyActionFormatter  s   r|   )	Zregister_modelr   ZModelr   r   r   register_actionr@   r   )actionsrK   rP   rR   rV   rW   rX   rZ   r\   ra   rb   rc   rd   re   rn   ru   rv   rw   rx   rz   r{   r|   r   r   r   register_core_log_actionsl   s|     $r   c                 C   s   G dd dt }| dG dd d|}| dG dd d|}| d	G d
d d|}| dG dd d|}| dG dd d|}d S )Nc                   @   s   e Zd Zdd ZdS )z;register_workflow_log_actions.<locals>.WorkflowLogFormatterc                 S   s   |j ddS )Nro   rS   )rA   rU   rC   r   r   r   format_comment  s    zJregister_workflow_log_actions.<locals>.WorkflowLogFormatter.format_commentN)rG   rH   rI   r   r   r   r   r   WorkflowLogFormatter  s   r   zwagtail.workflow.startc                   @   s   e Zd ZedZdd ZdS )zCregister_workflow_log_actions.<locals>.StartWorkflowActionFormatterzWorkflow: startc              	   S   sR   z,t d|jd d |jd d d d W S  ttfk
rL   t d Y S X d S )Nz,'%(workflow)s' started. Next step '%(task)s'workflowr<   r   r   taskzWorkflow startedr@   rA   rB   	TypeErrorrC   r   r   r   rE     s    
zRregister_workflow_log_actions.<locals>.StartWorkflowActionFormatter.format_messageNrF   r   r   r   r   StartWorkflowActionFormatter  s   r   zwagtail.workflow.approvec                   @   s   e Zd ZedZdd ZdS )zEregister_workflow_log_actions.<locals>.ApproveWorkflowActionFormatterzWorkflow: approve taskc              	   S   s   zn|j d d r@td|j d d d |j d d d d W S td|j d d d |j d d d W S W n  ttfk
r   td	 Y S X d S )
Nr   r   z1Approved at '%(task)s'. Next step '%(next_task)s'r   r<   )r   Z	next_taskz/Approved at '%(task)s'. '%(workflow)s' complete)r   r   zWorkflow task approved)rA   r@   rB   r   rC   r   r   r   rE     s    
zTregister_workflow_log_actions.<locals>.ApproveWorkflowActionFormatter.format_messageNrF   r   r   r   r   ApproveWorkflowActionFormatter  s   r   zwagtail.workflow.rejectc                   @   s   e Zd ZedZdd ZdS )zDregister_workflow_log_actions.<locals>.RejectWorkflowActionFormatterzWorkflow: reject taskc              	   S   sF   z t dd|jd d d i W S  ttfk
r@   t d Y S X d S )Nz)Rejected at '%(task)s'. Changes requestedr   r   r<   z)Workflow task rejected. Workflow completer   rC   r   r   r   rE   
  s     zSregister_workflow_log_actions.<locals>.RejectWorkflowActionFormatter.format_messageNrF   r   r   r   r   RejectWorkflowActionFormatter  s   r   zwagtail.workflow.resumec                   @   s   e Zd ZedZdd ZdS )zDregister_workflow_log_actions.<locals>.ResumeWorkflowActionFormatterzWorkflow: resume taskc              	   S   sF   z t dd|jd d d i W S  ttfk
r@   t d Y S X d S )Nz(Resubmitted '%(task)s'. Workflow resumedr   r   r<   z+Workflow task resubmitted. Workflow resumedr   rC   r   r   r   rE     s     zSregister_workflow_log_actions.<locals>.ResumeWorkflowActionFormatter.format_messageNrF   r   r   r   r   ResumeWorkflowActionFormatter  s   r   zwagtail.workflow.cancelc                   @   s   e Zd ZedZdd ZdS )zDregister_workflow_log_actions.<locals>.CancelWorkflowActionFormatterzWorkflow: cancelc              	   S   sR   z,t d|jd d |jd d d d W S  ttfk
rL   t d Y S X d S )Nz&Cancelled '%(workflow)s' at '%(task)s'r   r<   r   r   zWorkflow cancelledr   rC   r   r   r   rE   "  s    
zSregister_workflow_log_actions.<locals>.CancelWorkflowActionFormatter.format_messageNrF   r   r   r   r   CancelWorkflowActionFormatter  s   r   )r   r}   )r~   r   r   r   r   r   r   r   r   r   register_workflow_log_actions  s    r   N)*Zdjango.confr   Zdjango.contrib.auth.modelsr   Zdjango.contrib.auth.viewsr   Z	django.dbr   Zdjango.urlsr   Zdjango.utils.textr   Zdjango.utils.translationr   r@   r	   Zwagtailr
   Zwagtail.coreutilsr   Zwagtail.log_actionsr   Zwagtail.modelsr   r   r   r   Zwagtail.rich_text.pagesr   Zwagtail.utils.timestampsr   r   r   registerr"   r+   r   r1   r3   r6   r   r   r   r   r   r   <module>   s>   





  u