B
    `                 @   sP   d dl mZ d dlmZ d dlmZ d dlmZ ddd	Z	dddZ
dd ZdS )    )zip_longest)get_random_string)gettext_lazy)	get_model ABCDEFGHJKLMNPQRSTUVWXYZ23456789   -c             C   s4   dd t | |dD }|dd t|g|  D S )z/Create a string of 16 chars grouped by 4 chars.c             s   s   | ]
}|V  qd S )N ).0ir	   r	   G/home/dcms/DCMS/lib/python3.7/site-packages/oscar/apps/voucher/utils.py	<genexpr>   s    z generate_code.<locals>.<genexpr>)lengthallowed_charsc             s   s   | ]}d  td|V  qdS ) N)joinfilter)r
   ar	   r	   r   r      s   )r   r   r   )r   charsgroup_length	separatorZrandom_stringr	   r	   r   generate_code	   s    r      c             C   s8   t dd}x(t| ||d}|jj|d s|S qW dS )aq  Generate a code, check in the db if it already exists and return it.

    i.e. ASDA-QWEE-DFDF-KFGG

    :param int length: the number of characters in the code
    :param int group_length: length of character groups separated by separator kwarg ('-' by default)
    :param str separator: separator string for voucher code
    :return: voucher code
    :rtype: str

    ZvoucherVoucher)r   r   )codeN)r   r   Zobjectsr   exists)r   r   r   r   r   r	   r	   r   get_unused_code   s    
r   c             C   s   t d|  S )zx
    Return the name used for the auto-generated offer created
    when a voucher is created through the dashboard.
    zOffer for voucher '%s')_)Zvoucher_namer	   r	   r   get_offer_name'   s    r   N)r   r   r   )r   r   r   )	itertoolsr   Zdjango.utils.cryptor   Zdjango.utils.translationr   r   Zoscar.core.loadingr   r   r   r   r	   r	   r	   r   <module>   s    
	
