B
    `	                 @   s`   d dl 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 G dd deZdS )	    N)settings)User)BaseCommand)IntegrityError)AreaSectionGroupc               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Commandz#Setup Django Classified applicationc             C   s\   d}d}d}yt jj|||d W n  tk
rB   | jd d S X | jd|| d S )Nadminzadmin@example.com)usernamepasswordemailzAdmin user already createdz)Superuser {}/{} was created successfully.)r   objectscreate_superuserr   stdoutwriteformat)selfr   r   r    r   B/home/dcms/DCMS/dcf_demo/demo/management/commands/setup_project.pycreate_admin   s    zCommand.create_adminc             C   s  | j d ttd}t }x.|D ]&}tjj|d d\}}|||d < q&W | j d ttd}x4|D ],}t	jj|d t||d  |d d	d
 qpW d}| j d|  ttd}	x<|	D ]4}
|

d|krtjj|

dt|

ddd
 qW d S )NzLoading Sectionszdemo/craigslist_data/Types.jsonZDescription)titleTypezLoading Groupsz$demo/craigslist_data/Categories.jsonZAbbreviation)sectionr   )slugdefaultsGBzLoading Areas for %szdemo/craigslist_data/Areas.jsonZCountryZShortDescription)r   r   jsonloadopendictr   r   get_or_creater   getr   )r   sectionsZsections_dictr   obj_
categoriescategoryZcountry_codeareasarear   r   r   populate_craigslist_data"   s0    



z Command.populate_craigslist_datac             O   s   |    |   d S )N)r   r*   )r   argsoptionsr   r   r   handleE   s    zCommand.handleN)__name__
__module____qualname__helpr   r*   r-   r   r   r   r   r	   
   s   #r	   )r   django.confr   django.contrib.auth.modelsr   django.core.management.baser   	django.dbr   Zdjango_classified.modelsr   r   r   r	   r   r   r   r   <module>   s   