<commit_before>from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.db import models
from django.utils.translation import ugettext_lazy as _
from userena.models import UserenaLanguageBaseProfile

import datetime
# from dateutil import relativedelta
import hashlib
import httplib
import os
import urllib
import vobject
import xml.etree.ElementTree as ET

# Parse dates, times, DRY
def parse_datetime(date_str, format='%Y-%m-%d'):
    return datetime.datetime.strptime(date_str, format)

def parse_date(date_str, format='%Y-%m-%d'):
    return parse_datetime(date_str, format).date()

def parse_time(date_str, format='%H:%M'):
    return parse_datetime(date_str, format).time()

# More DRY: given a start hour and duration, return start and end time.
def parse_hour_duration(start_str, duration_str, format='%H:%M'):
    start = datetime.datetime.strptime(start_str, format)
    dur_tm = datetime.datetime.strptime(duration_str, format)
    duration = datetime.timedelta(hours=dur_tm.hour, minutes=dur_tm.minute, seconds=dur_tm.second)
    end = start + duration
    start_tm = datetime.time(hour=start.hour, minute=start.minute, second=start.second)
    end_tm = datetime.time(hour=end.hour, minute=end.minute, second=end.second)
    return(start_tm, end_tm)


# Helper model
class HasLinkField():
    def link(self):
        return 'Link'


# Create your models here.

class Edition(models.Model):
    class Meta:
        verbose_name = _('Edition')
        verbose_name_plural = _('Editions')
        ordering = ['-start_date']

    def __unicode__(self):
        return self.name

    name = models.CharField(max_length=128)
    start_date = models.DateField()
    end_date = models.DateField()
    visible_from = models.DateField()
    visible_until = models.DateField()

    @classmethod
    def get_current(cls):
        retval = False
        today = datetime.date.today()
        current = cls.objects.filter(visible_from__lte=today, visible_until__gte=today)
        if current:
            retval = current[0]
        return retval

    @classmethod
    def penta_create_or_update(cls, xml):
        ed_name = xml.find('title').text
        start_date = parse_date(xml.find('start').text)
        end_date = parse_date(xml.find('end').text)
        visible_from = datetime.date(year=start_date.year - 1, month=8, day=1)
        visible_until = datetime.date(year=start_date.year, month=7, day=31)
        editions = cls.objects.filter(name=ed_name)
        if len(editions):
            edition = editions[0]
        else:
            edition = cls(name=ed_name)  # create if required
        edition.start_date = start_date
        edition.end_date = end_date
        edition.visible_from = visible_from
        edition.visible_until = visible_until
        edition.save()
        return edition

    @classmethod
    def init_generic_tasks(cls):
        edition = cls.get_current()
        if edition:
            generic_task_tree = ET.parse('volunteers/init_data/generic_tasks.xml')
            generic_task_root = generic_task_tree.getroot()
            for task in generic_task_root.findall('task'):
                Task.create_from_xml(task, edition)

    @classmethod
    def sync_with_penta(cls):
        penta_url = settings.SCHEDULE_SYNC_URI
        response = urllib.urlopen(penta_url)
        penta_xml = response.read()
        root = ET.fromstring(penta_xml)
        ###########
        # Edition #
        ###########
        ed = root.find('conference')
        edition = cls.penta_create_or_update(ed)

        #########
        # Talks #
        #########
        days = root.findall('day')
        for day in days:
            day_date = parse_date(day.get('date'))
            rooms = day.findall('room')
            for room in rooms:
                room_name = room.get('name')
                # Lightning talks are done manually since the time slots are so small.
                needs_heralding = needs_video = room_name in ['Janson', 'K.1.105 (La Fontaine)']
                events = room.findall('event')
                for event in events:
                    talk = Talk.penta_create_or_update(event, edition, day_date)
                    ######################
                    # Tasks, if required #
                    ######################
                    if needs_heralding:
                        Task.create_or_update_from_talk(edition, talk, 'Heralding', [3, 2, 5])
                    if needs_video:
                        Task.create_or_update_from_talk(edition, talk, 'Video', [1, 1, 1])


"""
A track is a collection of talks, grouped around one single
concept or subject.
"""
class Track(models.Model):<commit_msg>Add setting turning off auto video task creation<commit_after>from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.db import models
from django.utils.translation import ugettext_lazy as _
from userena.models import UserenaLanguageBaseProfile

import datetime
# from dateutil import relativedelta
import hashlib
import httplib
import os
import urllib
import vobject
import xml.etree.ElementTree as ET

# Parse dates, times, DRY
def parse_datetime(date_str, format='%Y-%m-%d'):
    return datetime.datetime.strptime(date_str, format)

def parse_date(date_str, format='%Y-%m-%d'):
    return parse_datetime(date_str, format).date()

def parse_time(date_str, format='%H:%M'):
    return parse_datetime(date_str, format).time()

# More DRY: given a start hour and duration, return start and end time.
def parse_hour_duration(start_str, duration_str, format='%H:%M'):
    start = datetime.datetime.strptime(start_str, format)
    dur_tm = datetime.datetime.strptime(duration_str, format)
    duration = datetime.timedelta(hours=dur_tm.hour, minutes=dur_tm.minute, seconds=dur_tm.second)
    end = start + duration
    start_tm = datetime.time(hour=start.hour, minute=start.minute, second=start.second)
    end_tm = datetime.time(hour=end.hour, minute=end.minute, second=end.second)
    return(start_tm, end_tm)


# Helper model
class HasLinkField():
    def link(self):
        return 'Link'


# Create your models here.

class Edition(models.Model):
    class Meta:
        verbose_name = _('Edition')
        verbose_name_plural = _('Editions')
        ordering = ['-start_date']

    def __unicode__(self):
        return self.name

    name = models.CharField(max_length=128)
    start_date = models.DateField()
    end_date = models.DateField()
    visible_from = models.DateField()
    visible_until = models.DateField()

    @classmethod
    def get_current(cls):
        retval = False
        today = datetime.date.today()
        current = cls.objects.filter(visible_from__lte=today, visible_until__gte=today)
        if current:
            retval = current[0]
        return retval

    @classmethod
    def penta_create_or_update(cls, xml):
        ed_name = xml.find('title').text
        start_date = parse_date(xml.find('start').text)
        end_date = parse_date(xml.find('end').text)
        visible_from = datetime.date(year=start_date.year - 1, month=8, day=1)
        visible_until = datetime.date(year=start_date.year, month=7, day=31)
        editions = cls.objects.filter(name=ed_name)
        if len(editions):
            edition = editions[0]
        else:
            edition = cls(name=ed_name)  # create if required
        edition.start_date = start_date
        edition.end_date = end_date
        edition.visible_from = visible_from
        edition.visible_until = visible_until
        edition.save()
        return edition

    @classmethod
    def init_generic_tasks(cls):
        edition = cls.get_current()
        if edition:
            generic_task_tree = ET.parse('volunteers/init_data/generic_tasks.xml')
            generic_task_root = generic_task_tree.getroot()
            for task in generic_task_root.findall('task'):
                Task.create_from_xml(task, edition)

    @classmethod
    def sync_with_penta(cls):
        penta_url = settings.SCHEDULE_SYNC_URI
        response = urllib.urlopen(penta_url)
        penta_xml = response.read()
        root = ET.fromstring(penta_xml)
        ###########
        # Edition #
        ###########
        ed = root.find('conference')
        edition = cls.penta_create_or_update(ed)

        #########
        # Talks #
        #########
        days = root.findall('day')
        for day in days:
            day_date = parse_date(day.get('date'))
            rooms = day.findall('room')
            for room in rooms:
                room_name = room.get('name')
                # Lightning talks are done manually since the time slots are so small.
                needs_heralding = False
                needs_video = False

                if room_name in ['Janson', 'K.1.105 (La Fontaine)']:
                    needs_heralding = True
                    needs_video = settings.IMPORT_VIDEO_TASKS

                events = room.findall('event')
                for event in events:
                    talk = Talk.penta_create_or_update(event, edition, day_date)
                    ######################
                    # Tasks, if required #
                    ######################
                    if needs_heralding:
                        Task.create_or_update_from_talk(edition, talk, 'Heralding', [3, 2, 5])
                    if needs_video:
                        Task.create_or_update_from_talk(edition, talk, 'Video', [1, 1, 1])


"""
A track is a collection of talks, grouped around one single
concept or subject.
"""
class Track(models.Model):
{'fraction_non_alphanumeric': 0.11218808001649824, 'fraction_numerical': 0.004330789853578057, 'mean_word_length': 2.610945644080417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2602019', 'n_tokens_mistral': 2932, 'n_tokens_neox': 2868, 'n_words': 645}