# Path: gitcms/conferences/models.py
# class Conference(models.Model):
#     name = models.CharField(u'Name', max_length=255)
#     short_name = models.CharField(u'Short Name', max_length=255)
#     location = models.CharField(u'Location', max_length=255)
#     start = models.DateField(u'Start')
#     end = models.DateField(u'End')
#     submission_deadline = models.DateField(u'Submission Deadline', blank=True, null=True)
#     url = models.URLField(u'URL', blank=True, null=True)
#     comment = models.TextField(u'Comment')
#     def __unicode__(self):
#         return self.name
# 
#     def summary(self):
#         return '%s (%s)' % (self.name, self.short_name)


import datetime
import yaml
import os
from .models import Conference
    'August',
    'September',
    'October',
    'November',
    'December',
    ]

def _parsedate(s):
    month, day, year = s.strip().split()
    month_idx = None
    day = int(day)
    year = int(year)
    for i,m in enumerate(_months):
        if m.startswith(month):
            if month_idx is not None:
                raise IOError('Month %s is ambiguous' % month)
            month_idx = i
    if month_idx is None:
        raise IOError("Could not parse month '%s'" % month)
    return datetime.date(year, month_idx + 1, day)


def loaddir(directory, clear=False):
    if clear:
        Conference.objects.all().delete()
    for conffile in os.listdir(directory):
        if conffile[0] == '.': continue
        for conf in yaml.load_all(file(directory + '/' + conffile)):
            for dfield in ('start', 'end', 'submission_deadline'):
                conf[dfield] = _parsedate(conf[dfield])

# Path: gitcms/conferences/models.py
# class Conference(models.Model):
#     name = models.CharField(u'Name', max_length=255)
#     short_name = models.CharField(u'Short Name', max_length=255)
#     location = models.CharField(u'Location', max_length=255)
#     start = models.DateField(u'Start')
#     end = models.DateField(u'End')
#     submission_deadline = models.DateField(u'Submission Deadline', blank=True, null=True)
#     url = models.URLField(u'URL', blank=True, null=True)
#     comment = models.TextField(u'Comment')
#     def __unicode__(self):
#         return self.name
# 
#     def summary(self):
#         return '%s (%s)' % (self.name, self.short_name)


# Path: gitcms/conferences/load.py
import datetime
import yaml
import os
from .models import Conference

    'August',
    'September',
    'October',
    'November',
    'December',
    ]

def _parsedate(s):
    month, day, year = s.strip().split()
    month_idx = None
    day = int(day)
    year = int(year)
    for i,m in enumerate(_months):
        if m.startswith(month):
            if month_idx is not None:
                raise IOError('Month %s is ambiguous' % month)
            month_idx = i
    if month_idx is None:
        raise IOError("Could not parse month '%s'" % month)
    return datetime.date(year, month_idx + 1, day)


def loaddir(directory, clear=False):
    if clear:
        Conference.objects.all().delete()
    for conffile in os.listdir(directory):
        if conffile[0] == '.': continue
        for conf in yaml.load_all(file(directory + '/' + conffile)):
            for dfield in ('start', 'end', 'submission_deadline'):
                conf[dfield] = _parsedate(conf[dfield])

            C = Conference(**conf)