コード例 #1
0
ファイル: episode.py プロジェクト: Mic92/mygpo
def parse_new_chapters(user, chapters):
    for c in chapters:
        if not 'start' in c:
            raise ParameterMissing('start parameter missing')
        start = parse_time(c['start'])

        if not 'end' in c:
            raise ParameterMissing('end parameter missing')
        end = parse_time(c['end'])

        label = c.get('label', '')
        adv = c.get('advertisement', False)

        device_uid = c.get('device', None)
        if device_uid:
            device_id = get_device(user, device_uid,
                    request.META.get('HTTP_USER_AGENT', ''), undelete=True).id
        else:
            device_id = None

        chapter = Chapter()
        chapter.device = device_id
        chapter.created = timestamp
        chapter.start = start
        chapter.end = end
        chapter.label = label
        chapter.advertisement = adv

        yield chapter
コード例 #2
0
ファイル: episode.py プロジェクト: Mic92/mygpo
def add_chapter(request, episode):
    e_state = episode.get_user_state(request.user)

    podcast = Podcast.get(episode.podcast)

    try:
        start = parse_time(request.POST.get('start', '0'))

        if request.POST.get('end', '0'):
            end = parse_time(request.POST.get('end', '0'))
        else:
            end = start

        adv = 'advertisement' in request.POST
        label = request.POST.get('label')

    except Exception as e:
        # FIXME: when using Django's messaging system, set error message

        return HttpResponseRedirect(get_episode_link_target(episode, podcast))


    chapter = Chapter()
    chapter.start = start
    chapter.end = end
    chapter.advertisement = adv
    chapter.label = label

    e_state.update_chapters(add=[chapter])

    return HttpResponseRedirect(get_episode_link_target(episode, podcast))