<commit_before># -*- coding: utf-8 -*-

from django.contrib.auth.decorators import permission_required
from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.http import HttpResponse, HttpResponseNotFound
from vz_backup.models import BackupArchive

import mimetypes
import os

@permission_required(lambda u: u.has_perm('backuparchive.can_change'))
def download_archive(request, id):
    try:
        archive = BackupArchive.objects.select_related().get(id__exact=id)
    except BackupArchive.DoesNotExist:
        return HttpResponseNotFound('Archive with this ID does not exist.')

    if not os.path.exists(archive.path):
        return HttpResponseNotFound('Archive path does not exist.')

    send_file = getattr(settings,'VZ_BACKUP_SEND_FILE', None)

    headers = dict()
    headers['Content-Length'] = archive.size
    headers['Content-Disposition'] = 'attachment; filename=%s'%archive.name

    if send_file == 'x-accel-redirect' or send_file == 'x-send-file':
        response = HttpResponse()
        if send_file == 'x-accel-redirect':
            headers['Content-Type'] = ''
            headers['X-Accel-Redirect'] = archive.path
        else:<commit_msg>added docstring to download_archive view<commit_after># -*- coding: utf-8 -*-

from django.contrib.auth.decorators import permission_required
from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.http import HttpResponse, HttpResponseNotFound
from vz_backup.models import BackupArchive

import mimetypes
import os

@permission_required(lambda u: u.has_perm('backuparchive.can_change'))
def download_archive(request, id):
    """
    Download Archive
    
    If backup archive with *id* exists and user had change permissions
    download file based on *send_file* setting.
    """
    try:
        archive = BackupArchive.objects.select_related().get(id__exact=id)
    except BackupArchive.DoesNotExist:
        return HttpResponseNotFound('Archive with this ID does not exist.')

    if not os.path.exists(archive.path):
        return HttpResponseNotFound('Archive path does not exist.')

    send_file = getattr(settings,'VZ_BACKUP_SEND_FILE', None)

    headers = dict()
    headers['Content-Length'] = archive.size
    headers['Content-Disposition'] = 'attachment; filename=%s'%archive.name

    if send_file == 'x-accel-redirect' or send_file == 'x-send-file':
        response = HttpResponse()
        if send_file == 'x-accel-redirect':
            headers['Content-Type'] = ''
            headers['X-Accel-Redirect'] = archive.path
        else:
{'fraction_non_alphanumeric': 0.10689655172413794, 'fraction_numerical': 0.0007662835249042146, 'mean_word_length': 3.835185185185185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5857342', 'n_tokens_mistral': 749, 'n_tokens_neox': 729, 'n_words': 184}