# Path: statirator/blog/utils.py
# def get_blog_dir():
#     "Returns the blog directory from settings, or default one if not found"
# 
#     from django.conf import settings
# 
#     return getattr(settings, 'BLOG_DIR',
#                    os.path.join(settings.ROOT_DIR, 'blog'))


import codecs
import os
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.template.defaultfilters import slugify
from django.template.loader import render_to_string
from django.utils import translation
from optparse import make_option
from statirator.blog.utils import get_blog_dir




class Command(BaseCommand):

    args = '<english title or slug>'
    help = 'Create a new rst blog post'

    option_list = (
        make_option(
            '--draft', '-d', dest='draft', default=False, action='store_true',
            help='Is is a draft (unpublished) ? [Default: "%default"]'),
    ) + BaseCommand.option_list

    def handle(self, *args, **options):

        if len(args) != 1:
            raise CommandError('Single argument of English title or slug '
                               'is required')

        title_or_slug = args[0]
        slug = slugify(title_or_slug)
        draft = int(options['draft'])

        ctx = {
            'slug': slug,
            'draft': draft,
        }


# Path: statirator/blog/utils.py
# def get_blog_dir():
#     "Returns the blog directory from settings, or default one if not found"
# 
#     from django.conf import settings
# 
#     return getattr(settings, 'BLOG_DIR',
#                    os.path.join(settings.ROOT_DIR, 'blog'))


# Path: statirator/blog/management/commands/create_post.py
import codecs
import os
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.template.defaultfilters import slugify
from django.template.loader import render_to_string
from django.utils import translation
from optparse import make_option
from statirator.blog.utils import get_blog_dir





class Command(BaseCommand):

    args = '<english title or slug>'
    help = 'Create a new rst blog post'

    option_list = (
        make_option(
            '--draft', '-d', dest='draft', default=False, action='store_true',
            help='Is is a draft (unpublished) ? [Default: "%default"]'),
    ) + BaseCommand.option_list

    def handle(self, *args, **options):

        if len(args) != 1:
            raise CommandError('Single argument of English title or slug '
                               'is required')

        title_or_slug = args[0]
        slug = slugify(title_or_slug)
        draft = int(options['draft'])

        ctx = {
            'slug': slug,
            'draft': draft,
        }


        filename = os.path.join(get_blog_dir(), slug + '.rst')