Esempio n. 1
0
def browse(request, viewer, key=None, type_='file'):
    form = forms.FileCompareForm(request.POST or None,
                                 addon=viewer.addon,
                                 initial={'left': viewer.file})
    response = check_compare_form(request, form)
    if response:
        return response

    data = setup_viewer(request, viewer.file)
    data['viewer'] = viewer
    data['poll_url'] = reverse('mkt.files.poll', args=[viewer.file.id])
    data['form'] = form

    if (not waffle.switch_is_active('delay-file-viewer')
            and not viewer.is_extracted()):
        extract_file(viewer)

    if viewer.is_extracted():
        data.update({'status': True, 'files': viewer.get_files()})
        key = viewer.get_default(key)
        if key not in data['files']:
            raise http.Http404

        viewer.select(key)
        data['key'] = key

        binary = viewer.is_binary()
        if (not viewer.is_directory() and (not binary or binary != 'image')):
            data['content'] = viewer.read_file()

    else:
        extract_file.delay(viewer)

    tmpl = 'content' if type_ == 'fragment' else 'viewer'
    return render(request, 'fileviewer/%s.html' % tmpl, data)
Esempio n. 2
0
def compare(request, diff, key=None, type_='file'):
    form = forms.FileCompareForm(request.POST or None,
                                 addon=diff.addon,
                                 initial={
                                     'left': diff.left.file,
                                     'right': diff.right.file
                                 })
    response = check_compare_form(request, form)
    if response:
        return response

    data = setup_viewer(request, diff.left.file)
    data['diff'] = diff
    data['poll_url'] = reverse('mkt.files.compare.poll',
                               args=[diff.left.file.id, diff.right.file.id])
    data['form'] = form

    if (not waffle.switch_is_active('delay-file-viewer')
            and not diff.is_extracted()):
        extract_file(diff.left)
        extract_file(diff.right)

    if diff.is_extracted():
        data.update({
            'status': True,
            'files': diff.get_files(),
            'files_deleted': diff.get_deleted_files()
        })
        key = diff.left.get_default(key)
        if key not in data['files'] and key not in data['files_deleted']:
            raise http.Http404

        diff.select(key)
        data['key'] = key
        if diff.is_diffable():
            data['left'], data['right'] = diff.read_file()

    else:
        extract_file.delay(diff.left)
        extract_file.delay(diff.right)

    tmpl = 'content' if type_ == 'fragment' else 'viewer'
    return render(request, 'fileviewer/%s.html' % tmpl, data)