Ejemplo n.º 1
0
def episode(request, episode_id, episode_slug=None, edit_key=None):

    episode=get_object_or_404(Episode,id=episode_id)
    show=episode.show
    location=episode.location
    client=show.client

    try:
        # why Start/End can't be null:
        # http://code.djangoproject.com/ticket/13611
        # prev_episode = episode.get_previous_by_start(show=show)
        prev_episode = episode.get_previous_by_start(show=show)
    except Episode.DoesNotExist:
        # at edge of the set of nulls or values.  
        prev_episode = None
           
    try:
        next_episode = episode.get_next_by_start(show=show)
    except Episode.DoesNotExist:
        next_episode = None

    cuts = Cut_List.objects.filter(episode=episode).order_by('sequence','raw_file__start','start')

    # If this episode doesn't have a cut list yet, try to create one.
    if not cuts:
        cuts = mk_cuts(episode)

    if cuts:
        offset =  abs( cuts[0].raw_file.start - episode.start )
    else:
        offset = None

    # start times of chapters (included cuts)
    start_chap = (0,"00:00") # frame, timestamp
    chaps,frame_total = [],0 
    for cut in cuts:
        if cut.apply:
            frame_total+=int(cut.duration())
            end_chap = (int(frame_total*29.27), "%s:%02i:%02i" %  
              (frame_total//3600, (frame_total%3600)//60, frame_total%60) )
            chaps.append((start_chap,end_chap,cut))
            # setup for next chapter
            start_chap=end_chap
        else:
            chaps.append(('',''))

    clrfFormSet = formset_factory(clrfForm, extra=0)
    if request.method == 'POST' and \
            (request.user.is_authenticated() or 
                    episode.edit_key == edit_key): 
        episode_form = Episode_Form_small(request.POST, instance=episode) 
        clrfformset = clrfFormSet(request.POST) 
        add_cutlist_to_ep = Add_CutList_to_Ep(request.POST)
        if episode_form.is_valid() \
              and clrfformset.is_valid() \
              and add_cutlist_to_ep.is_valid(): 
            # if the state got bumpped, move to the next episode
            if episode.state:
                bump_ep = episode.state+1 == episode_form.cleaned_data['state']
            else:
                bump_ep = None
            episode_form.save()
            for form in clrfformset.forms:
                cl=get_object_or_404(Cut_List,id=form.cleaned_data['clid'])

                cl.raw_file.trash=form.cleaned_data['trash']
                cl.raw_file.comment=form.cleaned_data['rf_comment']
                cl.raw_file.save()

                cl.sequence=form.cleaned_data['sequence']
                cl.start=form.cleaned_data['start']
                cl.end=form.cleaned_data['end']
                cl.apply=form.cleaned_data['apply']

                cl.comment=form.cleaned_data['cl_comment']
                cl.save()
                if form.cleaned_data['split']:
                    cl.id=None
                    cl.sequence+=1
                    cl.save(force_insert=True)

            rf_pathnames = add_cutlist_to_ep.cleaned_data['rf_pathname']
            # print "#1", rf_pathnames
            if rf_pathnames:
              sequence = add_cutlist_to_ep.cleaned_data['sequence']
              for rf_pathname in rf_pathnames.split():
                # rf_pathname = "pycon13-t4-%s.dv" % (rf_pathname,)
                # print "#2", rf_pathname
                rfs = Raw_File.objects.filter(filename=rf_pathname)
                for rf in rfs:
                    cl = Cut_List.objects.create(
		           episode=episode,
                           raw_file=rf,
                           apply = True,
                           sequence = sequence, )
                    cl.save()
                    sequence +=1
                    print rf, cl


            # if trash got touched, 
            # need to requery to get things in the right order.  I think.
            if bump_ep:
               episode = nextepisode
               episode_form = Episode_Form_small(instance=episode) 

            cuts = Cut_List.objects.filter(
                episode=episode).order_by(
                        'sequence', 'raw_file__trash','raw_file__start')

            init = [{'clid':cut.id,
                'trash':cut.raw_file.trash,
                'sequence':cut.sequence,
                'start':cut.start, 'end':cut.end,
                'apply':cut.apply,
                'cl_comment':cut.comment, 'rf_comment':cut.raw_file.comment,
                 } for cut in cuts]
            clrfformset = clrfFormSet(initial=init)

        else:
            # pass
            print "ep errors:", episode_form.errors
            print "clrf errors:", clrfformset.errors
            print add_cutlist_to_ep.errors
    else:
        # hide emails if user is not logged n
        if not request.user.is_authenticated(): 
            episode.emails = None
        episode_form = Episode_Form_small(instance=episode) 
        # init data with things in the queryset that need editing
        # this part seems to work.
        init = [{'clid':cut.id,
                'trash':cut.raw_file.trash,
                'sequence':cut.sequence,
                'start':cut.start, 'end':cut.end,
                'apply':cut.apply,
                'cl_comment':cut.comment, 'rf_comment':cut.raw_file.comment,
        } for cut in cuts]
        clrfformset = clrfFormSet(initial=init)

    # blank out previous valuse so we don't keep adding the same thing
    add_cutlist_to_ep=Add_CutList_to_Ep(initial = {'sequence':1})

# If all the dates are the same, don't bother displaying them
    if episode.start is None or episode.end is None:
      same_dates = False
    else:
      talkdate = episode.start.date()
      same_dates = talkdate==episode.end.date()
      if same_dates:
        for cut in cuts:
            same_dates = same_dates and \
               talkdate==cut.raw_file.start.date()==cut.raw_file.end.date()

    return render_to_response('episode.html',
        {'episode':episode,
        'offset':offset,
        'chaps':chaps,
        'client':client, 'show':show, 'location':location,
        'prev_episode':prev_episode,
        'next_episode':next_episode,
        'same_dates':same_dates,
        'episode_form':episode_form,
        'clrffs':zip(cuts,chaps,clrfformset.forms),
        'clrfformset':clrfformset,
        'add_cutlist_to_ep':add_cutlist_to_ep,
        },
    	context_instance=RequestContext(request) )
Ejemplo n.º 2
0
def episode(request, episode_no):

    episode=get_object_or_404(Episode,id=episode_no)
    show=episode.show
    location=episode.location
    client=show.client

    try:
        # why Start/End can't be null:
        # http://code.djangoproject.com/ticket/13611
        prev_episode = episode.get_previous_by_start(show=show)
    except Episode.DoesNotExist:
        # at edge of the set of nulls or values.  
        prev_episode = None
           
    try:
        next_episode = episode.get_next_by_start(show=show)
    except Episode.DoesNotExist:
        next_episode = None

    cuts = Cut_List.objects.filter(episode=episode).order_by('sequence','raw_file__start','start')

    if not cuts:
        cuts = mk_cuts(episode)

    clrfFormSet = formset_factory(clrfForm, extra=0)
    if request.user.is_authenticated() and request.method == 'POST': 
        episode_form = Episode_Form_small(request.POST, instance=episode) 
        clrfformset = clrfFormSet(request.POST) 
        if episode_form.is_valid() and clrfformset.is_valid(): 
            # if the state got bumpped, move to the next episode
            if episode.state:
                bump_ep = episode.state+1 == episode_form.cleaned_data['state']
            else:
                bump_ep = None
            episode_form.save()
            for form in clrfformset.forms:
                cl=get_object_or_404(Cut_List,id=form.cleaned_data['clid'])

                cl.raw_file.trash=form.cleaned_data['trash']
                cl.raw_file.comment=form.cleaned_data['rf_comment']
                cl.raw_file.save()

                cl.sequence=form.cleaned_data['sequence']
                cl.start=form.cleaned_data['start']
                cl.end=form.cleaned_data['end']
                cl.apply=form.cleaned_data['apply']

                cl.comment=form.cleaned_data['cl_comment']
                cl.save()
                if form.cleaned_data['split']:
                    cl.id=None
                    cl.sequence+=1
                    cl.save(force_insert=True)

            # if trash got touched, 
            # need to requery to get things in the right order.  I think.
            if bump_ep:
               episode = nextepisode
               episode_form = Episode_Form_small(instance=episode) 
            cuts = Cut_List.objects.filter(
                episode=episode).order_by('raw_file__trash','raw_file__start')
            init = [{'clid':cut.id,
                'trash':cut.raw_file.trash,
                'sequence':cut.sequence,
                'start':cut.start, 'end':cut.end,
                'apply':cut.apply,
                'cl_comment':cut.comment, 'rf_comment':cut.raw_file.comment,
                 } for cut in cuts]
            clrfformset = clrfFormSet(initial=init)

        else:
            pass
            # print "ep errors:", episode_form.errors
            # print clrfformset.errors
    else:
        episode_form = Episode_Form_small(instance=episode) 
        # init data with things in the queryset that need editing
        # this part seems to work.
        init = [{'clid':cut.id,
                'trash':cut.raw_file.trash,
                'sequence':cut.sequence,
                'start':cut.start, 'end':cut.end,
                'apply':cut.apply,
                'cl_comment':cut.comment, 'rf_comment':cut.raw_file.comment,
        } for cut in cuts]
        clrfformset = clrfFormSet(initial=init)

# If all the dates are the same, don't bother displaying them
    if episode.start is None or episode.end is None:
      same_dates = False
    else:
      talkdate = episode.start.date()
      same_dates = talkdate==episode.end.date()
      if same_dates:
        for cut in cuts:
            same_dates = same_dates and \
               talkdate==cut.raw_file.start.date()==cut.raw_file.end.date()

    return render_to_response('episode.html',
        {'episode':episode,
        'client':client, 'show':show, 'location':location,
        'prev_episode':prev_episode,
        'next_episode':next_episode,
        'same_dates':same_dates,
        'episode_form':episode_form,
        'clrffs':zip(cuts,clrfformset.forms),
        'clrfformset':clrfformset,
        },
    	context_instance=RequestContext(request) )