<commit_before># -*- coding: utf-8 -*-
""" Print out a listing of accepted talks.

"""
from django.core.management.base import BaseCommand, CommandError
from django.core import urlresolvers
from conference import models
from conference import utils

from collections import defaultdict
from optparse import make_option
import operator

### Globals

TYPE_NAMES = (
    ('keynote', 'Keynotes', ''),
    ('t', 'Talks', ''),
    ('r', 'Training sessions', ''),
    ('p', 'Poster sessions', ''),
    ('i', 'Interactive sessions', ''),
    ('n', 'Panels', ''),
    ('h', 'Help desks', 'Help desks provide slots for attendees to discuss their problems one-on-one with experts from the projects.'),
    ('europython', 'EuroPython sessions', 'The EuroPython sessions are intended for anyone interested in helping with the EuroPython organization in the coming years.'),
    )

def _check_talk_types(type_names):
    d = set(x[0] for x in type_names)
    for code, entry in models.TALK_TYPE:
        assert code[0] in d, 'Talk type code %r is missing' % code[0]
_check_talk_types(TYPE_NAMES)

### Helpers

def profile_url(user):

    return urlresolvers.reverse('conference-profile',
                                args=[user.attendeeprofile.slug])

def speaker_listing(talk):

    return u', '.join(
        u'<a href="%s"><i>%s %s</i></a>' % (
            profile_url(speaker.user),
            speaker.user.first_name,
            speaker.user.last_name)
        for speaker in talk.get_all_speakers())

def talk_title(talk):

    # Remove whitespace
    title = talk.title.strip()

    # Remove quotes
    if title[0] == '"' and title[-1] == '"':
        title = title[1:-1]

    return title

###

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        # make_option('--option',
        #     action='store',
        #     dest='option_attr',
        #     default=0,
        #     type='int',
        #     help='Help text',
        # ),
    )
    def handle(self, *args, **options):
        try:
            conference = args[0]
        except IndexError:
            raise CommandError('conference not specified')

        talks = (models.Talk.objects
                 .filter(conference=conference,
                         status='accepted'))

        # Group by types
        talk_types = {}
        for talk in talks:
            if 'EPS' in talk.title or 'EuroPython 20' in talk.title:
                type = 'europython'
            elif talk.title.lower().startswith('keynote'):
                type = 'keynote'
            else:
                type = talk.type[0]
            if type in talk_types:
                talk_types[type].append(talk)
            else:
                talk_types[type] = [talk]

        # Print list of submissions
        print ('<h2>Accepted submissions</h2>')
        for type, type_name, description in TYPE_NAMES:
            bag = talk_types.get(type, [])
            if not bag:
                continue
            # Sort by talk title using title case
            bag.sort(key=lambda talk: talk_title(talk).title())
            print ('')
            print ('<h3>%s</h3>' % type_name)
            if description:
                print ('<p>%s</p>' % description)
            print ('<ul>')
            for talk in bag:
                print ((u'<li><a href="%s">%s</a> by %s</li>' % (
                    talk.get_absolute_url(),
                    talk_title(talk),
                    speaker_listing(talk))
                    ).encode('utf-8'))
            print ('</ul>')<commit_msg>Update talk listing script to also use the .admin_type for grouping talks.<commit_after># -*- coding: utf-8 -*-
""" Print out a listing of accepted talks.

"""
from django.core.management.base import BaseCommand, CommandError
from django.core import urlresolvers
from conference import models
from conference import utils

from collections import defaultdict
from optparse import make_option
import operator

### Globals

# These must match the talk .type or .admin_type
TYPE_NAMES = (
    ('k', 'Keynotes', ''),
    ('t', 'Talks', ''),
    ('r', 'Training sessions', ''),
    ('p', 'Poster sessions', ''),
    ('i', 'Interactive sessions', ''),
    ('n', 'Panels', ''),
    ('h', 'Help desks', 'Help desks provide slots for attendees to discuss their problems one-on-one with experts from the projects.'),
    ('m', 'EuroPython sessions', 'The EuroPython sessions are intended for anyone interested in helping with the EuroPython organization in the coming years.'),
    )

def _check_talk_types(type_names):
    d = set(x[0] for x in type_names)
    for code, entry in models.TALK_TYPE:
        assert code[0] in d, 'Talk type code %r is missing' % code[0]
_check_talk_types(TYPE_NAMES)

### Helpers

def profile_url(user):

    return urlresolvers.reverse('conference-profile',
                                args=[user.attendeeprofile.slug])

def speaker_listing(talk):

    return u', '.join(
        u'<a href="%s"><i>%s %s</i></a>' % (
            profile_url(speaker.user),
            speaker.user.first_name,
            speaker.user.last_name)
        for speaker in talk.get_all_speakers())

def talk_title(talk):

    # Remove whitespace
    title = talk.title.strip()

    # Remove quotes
    if title[0] == '"' and title[-1] == '"':
        title = title[1:-1]

    return title

###

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        # make_option('--option',
        #     action='store',
        #     dest='option_attr',
        #     default=0,
        #     type='int',
        #     help='Help text',
        # ),
    )
    def handle(self, *args, **options):
        try:
            conference = args[0]
        except IndexError:
            raise CommandError('conference not specified')

        talks = (models.Talk.objects
                 .filter(conference=conference,
                         status='accepted'))

        # Group by types
        talk_types = {}
        for talk in talks:
            talk_type = talk.type[:1]
            admin_type = talk.admin_type[:1]
            if (admin_type == 'm' or 
               'EPS' in talk.title or 
               'EuroPython 20' in talk.title):
                type = 'm'
            elif (admin_type == 'k' or 
                  talk.title.lower().startswith('keynote')):
                print ('found keynote: %r' % talk)
                type = 'k'
            else:
                type = talk_type
            if type in talk_types:
                talk_types[type].append(talk)
            else:
                talk_types[type] = [talk]

        # Print list of submissions
        print ('<h2>Accepted submissions</h2>')
        for type, type_name, description in TYPE_NAMES:
            bag = talk_types.get(type, [])
            if not bag:
                continue
            # Sort by talk title using title case
            bag.sort(key=lambda talk: talk_title(talk).title())
            print ('')
            print ('<h3>%s</h3>' % type_name)
            if description:
                print ('<p>%s</p>' % description)
            print ('<ul>')
            for talk in bag:
                print ((u'<li><a href="%s">%s</a> by %s</li>' % (
                    talk.get_absolute_url(),
                    talk_title(talk),
                    speaker_listing(talk))
                    ).encode('utf-8'))
            print ('</ul>')
{'fraction_non_alphanumeric': 0.1299138395261174, 'fraction_numerical': 0.00498115239633818, 'mean_word_length': 1.9468464894882982, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6332038', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2128, 'n_words': 579}