3

\                 @   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 G dd dejZG d	d
 d
ejZdS )    )models)reverse)get_random_string)gettext_lazy)pgettext_lazy)AUTH_USER_MODELc                   s  e Zd ZdZejedejeddZ	ej
ededddZej
ed	d
ddddZd)\ZZZeedfeedfeedffZej
eddeedZejeddddZdd Z fddZed*ddZdd  Zd!d" ZG d#d$ d$Zd%d& Zd'd( Z  ZS )+AbstractWishListz
    Represents a user's wish lists of products.

    A user can have multiple wish lists, move products between them, etc.
    	wishlistsOwner)related_name	on_deleteverbose_nameNameDefault   )r   default
max_lengthKey   TF)r   db_indexuniqueeditablePublicPrivateSharedz.Private - Only the owner can see the wish listz[Shared - Only the owner and people with access to the obfuscated link can see the wish listz(Public - Everybody can see the wish listZ
Visibility   )r   r   choiceszDate created)auto_now_addr   c             C   s   d| j | jf S )Nz%s's Wish List '%s')ownername)self r!   ?/var/www/html/oscar2019/oscar/apps/wishlists/abstract_models.py__str__4   s    zAbstractWishList.__str__c                s2   | j  s|jddr | jj | _t j|| d S )Nforce_insertF)pkget	__class__
random_keykeysupersave)r    argskwargs)r'   r!   r"   r+   7   s    zAbstractWishList.savec             C   s,   x&t |dd}| jj|dj s|S qW dS )z3
        Get a unique random generated key
        $abcdefghijklmnopqrstuvwxyz0123456789)lengthallowed_chars)r)   N)r   _default_managerfilterexists)clsr/   r)   r!   r!   r"   r(   <   s
    zAbstractWishList.random_keyc             C   s$   | j | j| jfkrdS || jkS d S )NT)
visibilityPUBLICSHAREDr   )r    userr!   r!   r"   is_allowed_to_seeG   s    z"AbstractWishList.is_allowed_to_seec             C   s
   || j kS )N)r   )r    r8   r!   r!   r"   is_allowed_to_editM   s    z#AbstractWishList.is_allowed_to_editc               @   s    e Zd ZdZdZdZedZdS )zAbstractWishList.MetaTr	   r   date_createdz	Wish ListN)r   r;   )__name__
__module____qualname__abstract	app_labelordering_r   r!   r!   r!   r"   MetaQ   s   rC   c             C   s   t dd| jidS )Nzcustomer:wishlists-detailr)   )r-   )r   r)   )r    r!   r!   r"   get_absolute_urlW   s    z!AbstractWishList.get_absolute_urlc             C   sR   | j j|d}t|dkr0| j j||j d n|d }| jd7  _|j  dS )z0
        Add a product to this wishlist
        )productr   )rE   title   N)linesr2   lencreate	get_titlequantityr+   )r    rE   rH   liner!   r!   r"   add[   s    zAbstractWishList.add)r   r   r   )r   )r<   r=   r>   __doc__r   
ForeignKeyr   CASCADErB   r   	CharFieldr   r)   r6   ZPRIVATEr7   ZVISIBILITY_CHOICESr5   DateTimeFieldr;   r#   r+   classmethodr(   r9   r:   rC   rD   rN   __classcell__r!   r!   )r'   r"   r   
   s6   




r   c               @   s   e Zd ZdZejdejdeddZejdeddej	d	d	d
Z
ejedddZejeddddZdd Zdd ZG dd dZdS )AbstractLinezK
    One entry in a wish list. Similar to order lines or basket lines.
    zwishlists.WishListrH   z	Wish List)r   r   r   zcatalogue.ProductProductZwishlists_linesT)r   r   r   blanknullQuantityrG   )r   zProduct titleTitler   )r   c             C   s   d| j | j| jjf S )Nz%sx %s on %s)rL   rF   wishlistr   )r    r!   r!   r"   r#   {   s    zAbstractLine.__str__c             C   s   | j r| j j S | jS d S )N)rE   rK   rF   )r    r!   r!   r"   rK   ~   s    
zAbstractLine.get_titlec               @   s&   e Zd ZdZdZdgZd	ZedZdS )
zAbstractLine.MetaTr	   r%   r\   rE   zWish list lineNr\   rE   )r]   )	r<   r=   r>   r?   r@   rA   unique_togetherrB   r   r!   r!   r!   r"   rC      s
   rC   N)r<   r=   r>   rO   r   rP   rQ   rB   r\   SET_NULLrE   PositiveIntegerFieldrL   rR   r   rF   r#   rK   rC   r!   r!   r!   r"   rV   i   s    
rV   N)	django.dbr   django.urlsr   django.utils.cryptor   django.utils.translationr   rB   r   oscar.core.compatr   Modelr   rV   r!   r!   r!   r"   <module>   s   _