a
    Dgo&                     @   s   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 d dlmZ G dd	 d	ZG d
d deZG dd deZG dd deZdS )    )settings)format_html)	mark_safe)capfirst)gettext)get_latest_strget_user_display_name)render_timestampc                   @   sJ   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dddZ
dS )BaseLockzv
    Holds information about a lock on an object.

    Returned by LockableMixin.get_lock() (or Page.get_lock()).
    c                 C   s6   ddl m} || _t||| _| jr(|n|jj| _d S )Nr   )Page)Zwagtail.modelsr   object
isinstanceZis_pageZ_metaZverbose_name
model_name)selfr   r    r   L/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/locks.py__init__   s    zBaseLock.__init__c                 C   s   t S )zE
        Returns True if the lock applies to the given user.
        )NotImplementedr   userr   r   r   for_user   s    zBaseLock.for_userc                 C   s   dS )zU
        Returns a message to display to the given user describing the lock.
        Nr   r   r   r   r   get_message    s    zBaseLock.get_messagec                 C   s   dS )zC
        Returns the name of the icon to use for the lock.
        lockr   r   r   r   r   get_icon&   s    zBaseLock.get_iconc                 C   s   t dS )z`
        Returns a string that represents the user or mechanism that locked the object.
        Locked_r   r   r   r   get_locked_by,   s    zBaseLock.get_locked_byc                 C   s   t tdd| ji S )zQ
        Returns a description of the lock to display to the given user.
        z:No one can make changes while the %(model_name)s is lockedr   r   r   r   r   r   r   r   get_description2   s
    zBaseLock.get_descriptionNc                 C   s.   |  || || || || |dS )zV
        Returns a context dictionary to use in templates for the given user.
        )lockedmessageicon	locked_bydescription)r   r   r   r   r   )r   r   parent_contextr   r   r   get_context_for_user;   s    zBaseLock.get_context_for_user)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r&   r   r   r   r   r
      s   	r
   c                       s<   e Zd ZdZdd Zdd Z fddZ fdd	Z  ZS )
	BasicLockz
    A lock that is enabled when the "locked" attribute of an object is True.

    The object may be editable by a user depending on whether the locked_by field is set
    and if WAGTAILADMIN_GLOBAL_EDIT_LOCK is not set to True.
    c                 C   s   t tdd }|p|j| jjkS )NZWAGTAILADMIN_GLOBAL_EDIT_LOCK)getattrr   pkr   locked_by_id)r   r   Zglobal_edit_lockr   r   r   r   P   s    zBasicLock.for_userc                 C   s   t | j}| jj|jkrL| jjr:ttd|t| jjdS ttd|dS nD| jjr| jjrttd|t	| jjt| jjdS ttd|dS d S )Nz?<b>'{title}' was locked</b> by <b>you</b> on <b>{datetime}</b>.)titledatetimez)<b>'{title}' is locked</b> by <b>you</b>.)r/   zB<b>'{title}' was locked</b> by <b>{user}</b> on <b>{datetime}</b>.)r/   r   r0   z<b>'{title}' is locked</b>.)
r   r   r.   r-   Z	locked_atr   r   r	   r#   r   )r   r   r/   r   r   r   r   T   s6    




zBasicLock.get_messagec                    s2   | j j|jkrtdS | j jr&tdS t |S )NzLocked by youzLocked by another user)r   r.   r-   r   superr   r   	__class__r   r   r   {   s
    zBasicLock.get_locked_byc                    sX   | j j|jkr$ttdd| ji S | j jrLttdt| j j| jd S t 	|S )Nz<Only you can make changes while the %(model_name)s is lockedr   zAOnly %(user)s can make changes while the %(model_name)s is locked)r   r   )
r   r.   r-   r   r   r   r   r#   r1   r   r   r2   r   r   r      s    
zBasicLock.get_description)	r'   r(   r)   r*   r   r   r   r   __classcell__r   r   r2   r   r+   H   s
   'r+   c                       s`   e Zd ZdZ fddZdd Zdd Zd fd	d
	ZdddZdddZ	d fdd	Z
  ZS )WorkflowLockzi
    A lock that requires the user to pass the Task.locked_for_user test on the given workflow task.
    c                    s   t  | || _d S N)r1   r   task)r   r   r7   r2   r   r   r      s    zWorkflowLock.__init__c                 C   s   | j | j|S r6   )r7   Zlocked_for_userr   r   r   r   r   r      s    zWorkflowLock.for_userc                 C   s   |  |r| jj}|r>t| dkr>ttdd| ji }n*ttd| j| j	j
|jj
d}tt|}ttdd| ji }t|d | S d S )N   z5This %(model_name)s is currently awaiting moderation.r   z\This {model_name} is awaiting <b>'{task_name}'</b> in the <b>'{workflow_name}'</b> workflow.)r   Z	task_nameZworkflow_namez9Only reviewers for this task can edit the %(model_name)s. )r   r   current_workflow_statelenZall_tasks_with_statusr   r   r   r   r7   nameZworkflowr   )r   r   r:   Zworkflow_infoZreviewers_infor   r   r   r      s4    
zWorkflowLock.get_messageFc                    s   |rdS t  |S )Nz	lock-open)r1   r   r   r   can_lockr2   r   r   r      s    zWorkflowLock.get_iconc                 C   s   |rt dS t dS )NZUnlockedzLocked by workflowr   r=   r   r   r   r      s    zWorkflowLock.get_locked_byc                 C   s0   |rt tdd| ji S t tdd| ji S )NuZ   Reviewers can edit this %(model_name)s – lock it to prevent other reviewers from editingr   z6Only reviewers can edit and approve the %(model_name)sr   r=   r   r   r   r      s    zWorkflowLock.get_descriptionNc                    sT   t  ||}|rPd|v rP|dd}|| ||| ||| ||d |S )NZuser_can_lockF)r"   r#   r$   )r1   r&   getupdater   r   r   )r   r   r%   contextr>   r2   r   r   r&      s    


z!WorkflowLock.get_context_for_user)F)F)F)N)r'   r(   r)   r*   r   r   r   r   r   r   r&   r4   r   r   r2   r   r5      s   !

r5   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ScheduledForPublishLockz
    A lock that occurs when something is scheduled to be published.

    This prevents it becoming difficult for users to see which version is going to be published.
    Nobody can edit something that's scheduled for publish.
    c                 C   s   dS )NTr   r   r   r   r   r      s    z ScheduledForPublishLock.for_userc                 C   s2   | j j}ttd| j|jt|jd}tt	|S )NzP{model_name} '{title}' is locked and has been scheduled to go live at {datetime})r   r/   r0   )
r   scheduled_revisionr   r   r   Z
object_strr	   Zapproved_go_live_atr   r   )r   r   rC   r!   r   r   r   r      s    	z#ScheduledForPublishLock.get_messagec                 C   s   t dS )NzLocked by scheduler   r   r   r   r   r     s    z%ScheduledForPublishLock.get_locked_byc                 C   s   t dS )Nz7Currently locked and will go live on the scheduled dater   r   r   r   r   r     s    z'ScheduledForPublishLock.get_descriptionN)r'   r(   r)   r*   r   r   r   r   r   r   r   r   rB      s
   rB   N)Zdjango.confr   Zdjango.utils.htmlr   Zdjango.utils.safestringr   Zdjango.utils.textr   Zdjango.utils.translationr   r   Zwagtail.admin.utilsr   r   Zwagtail.utils.timestampsr	   r
   r+   r5   rB   r   r   r   r   <module>   s   =KW