Beispiel #1
0
def set_marker(request, id, name):
    if request.method == "POST":
        index = request.POST['index']
        time = request.POST['time']
        if index and time:
            record = Record.filter_one_by_access(request.user, id)
            can_edit = record.editable_by(request.user)
            markers = get_markers(record)
            m = dict(map(lambda v: v.split(','), markers.value.split())) if markers.value else dict()
            m[index] = time
            to_remove = []
            prev_val = None
            for key in sorted(m.keys()):
                if prev_val:
                    if prev_val >= m[key]:
                        to_remove.append(key)
                else:
                    prev_val = m[key]
            for key in to_remove:
                del m[key]
            markers.value = '\n'.join('%s,%s' % (v,k) for v,k in m.iteritems())
            markers.save()
            return dict(message="Marker saved.")
        else:
            return dict(result="Error", message="Missing parameters")
    else:
        return dict(result="Error", message="Invalid method. Use POST.")
Beispiel #2
0
def set_marker(request, id, name):
    if request.method == "POST":
        index = request.POST['index']
        time = request.POST['time']
        if index and time:
            record = Record.filter_one_by_access(request.user, id)
            can_edit = record.editable_by(request.user)
            markers = get_markers(record)
            m = dict(map(lambda v: v.split(','),
                         markers.value.split())) if markers.value else dict()
            m[index] = time
            to_remove = []
            prev_val = None
            for key in sorted(m.keys()):
                if prev_val:
                    if prev_val >= m[key]:
                        to_remove.append(key)
                else:
                    prev_val = m[key]
            for key in to_remove:
                del m[key]
            markers.value = '\n'.join('%s,%s' % (v, k)
                                      for v, k in m.iteritems())
            markers.save()
            return dict(message="Marker saved.")
        else:
            return dict(result="Error", message="Missing parameters")
    else:
        return dict(result="Error", message="Invalid method. Use POST.")
Beispiel #3
0
    def view(self, request, template='audiotextsync_view.html'):
        next = request.GET.get('next')
        can_edit = self.obj.editable_by(request.user)

        textmedia = audiomedia = None
        for media in self.obj.media_set.filter(
            storage__in=filter_by_access(request.user, Storage)):
            if not audiomedia and media.mimetype == 'audio/mpeg':
                audiomedia = media
            elif not textmedia and media.mimetype == 'text/plain':
                textmedia = media
        if not textmedia or not audiomedia:
            raise Http404()
        transcript = textmedia.load_file().readlines()
        markers = get_markers(self.obj)

        return render_to_response(template,
                                  {'record': self.obj,
                                   'next': next,
                                   'transcript': transcript,
                                   'markers': dict(map(lambda v: v.split(','), markers.value.split())) if markers.value else dict(),
                                   'mp3url': audiomedia.get_absolute_url(),
                                   'edit': can_edit,
                                   },
                                  context_instance=RequestContext(request))