<commit_before>from ct.models import *
from fsmspec import FSMSpecification

def next_lesson(self, edge, fsmStack, request, useCurrent=False, **kwargs):
    'edge method that moves us to right state for next lesson (or END)'
    fsm = edge.fromNode.fsm
    unitStatus = fsmStack.state.get_data_attr('unitStatus')
    if useCurrent:
        nextUL = unitStatus.get_lesson()
    else:
        nextUL = unitStatus.start_next_lesson()
    if not nextUL:
        return fsm.get_node('END')
    else: # just show it as a LESSON slide
        fsmStack.state.unitLesson = nextUL # set the lesson to display
        return edge.toNode

class START(object):
    '''Initialize data for viewing a courselet, and go immediately
    to first lesson. '''
    def start_event(self, node, fsmStack, request, **kwargs):
        'event handler for START node'
        unit = fsmStack.state.get_data_attr('unit')
        fsmStack.state.title = 'Slideshow: %s' % unit.title
        unitStatus = UnitStatus(unit=unit, user=request.user)
        unitStatus.save()
        fsmStack.state.set_data_attr('unitStatus', unitStatus)
        return fsmStack.state.transition(fsmStack, request, 'next',
                                         useCurrent=True, **kwargs)
    next_edge = next_lesson
    # node specification data goes here
    title = 'Start This Courselet'
    edges = (
            dict(name='next', toNode='LESSON', title='View Next Lesson'),
        )

class LESSON(object):
    '''View a lesson explanation. '''
    def next_edge(self, edge, fsmStack, request, **kwargs):
        'go to ANSWER if present, or just call next_lesson()'
        fsm = edge.fromNode.fsm
        unitStatus = fsmStack.state.get_data_attr('unitStatus')
        ul = unitStatus.get_lesson()
        answers = ul.get_answers()
        if ul.is_question() and len(answers) > 0: # get the answer
            fsmStack.state.unitLesson = answers[0]
            return fsm.get_node(name='ANSWER')
        else:
            return next_lesson(self, edge, fsmStack, request, **kwargs)
    # node specification data goes here
    path = 'ct:lesson'
    title = 'View an explanation or question'
    edges = (
            dict(name='next', toNode='LESSON', title='View Next Slide'),
        )
    
class ANSWER(object):
    next_edge = next_lesson
    # node specification data goes here
    path = 'ct:lesson'
    title = 'View an answer'
    edges = (
            dict(name='next', toNode='LESSON', title='View Next Slide'),
        )

class END(object):
    # node specification data goes here
    path = 'ct:unit_concepts_student'
    title = 'Courselet slide show completed'
    help = '''Thanks for viewing this slide show.
    See below for suggested next steps on concepts you can study in
    this courselet.'''

        <commit_msg>slideshow FSM no longer uses UnitStatus<commit_after>from ct.models import *
from fsmspec import FSMSpecification

def next_lesson(self, edge, fsmStack, request, unit=None, **kwargs):
    'edge method that moves us to right state for next lesson (or END)'
    fsm = edge.fromNode.fsm
    if unit: # get first lesson
        nextUL = unit.get_exercises()[0]
    else:
        try:
            nextUL = fsmStack.state.unitLesson.get_next_lesson()
        except UnitLesson.DoesNotExist:
            return fsm.get_node('END')
    fsmStack.state.unitLesson = nextUL # set the lesson to display
    return edge.toNode # just show it as a LESSON slide

class START(object):
    '''Initialize data for viewing a courselet, and go immediately
    to first lesson. '''
    def start_event(self, node, fsmStack, request, **kwargs):
        'event handler for START node'
        unit = fsmStack.state.get_data_attr('unit')
        fsmStack.state.title = 'Slideshow: %s' % unit.title
        return fsmStack.state.transition(fsmStack, request, 'next',
                                         unit=unit, **kwargs)
    next_edge = next_lesson
    # node specification data goes here
    title = 'Start This Courselet'
    edges = (
            dict(name='next', toNode='LESSON', title='View Next Lesson'),
        )

class LESSON(object):
    '''View a lesson explanation. '''
    def next_edge(self, edge, fsmStack, request, **kwargs):
        'go to ANSWER if present, or just call next_lesson()'
        fsm = edge.fromNode.fsm
        ul = fsmStack.state.unitLesson
        answers = ul.get_answers()
        if ul.is_question() and len(answers) > 0: # get the answer
            fsmStack.state.unitLesson = answers[0]
            return fsm.get_node(name='ANSWER')
        else:
            return next_lesson(self, edge, fsmStack, request, **kwargs)
    # node specification data goes here
    path = 'ct:lesson'
    title = 'View an explanation or question'
    edges = (
            dict(name='next', toNode='LESSON', title='View Next Slide'),
        )
    
class ANSWER(object):
    '''View answer slide '''
    def next_edge(self, edge, fsmStack, request, **kwargs):
        fsmStack.state.unitLesson = fsmStack.state.unitLesson.parent
        return next_lesson(self, edge, fsmStack, request, **kwargs)
    # node specification data goes here
    path = 'ct:lesson'
    title = 'View an answer'
    edges = (
            dict(name='next', toNode='LESSON', title='View Next Slide'),
        )

class END(object):
    # node specification data goes here
    path = 'ct:unit_concepts_student'
    title = 'Courselet slide show completed'
    help = '''Thanks for viewing this slide show.
    See below for suggested next steps on concepts you can study in
    this courselet.'''

        
{'fraction_non_alphanumeric': 0.10315186246418338, 'fraction_numerical': 0.0008954154727793697, 'mean_word_length': 2.6913417052214146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1059380', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1665, 'n_words': 498}