Exemplo n.º 1
0
def extract_mission_upload(request):
    # Initialize data array and some default values.
    data = {}
    data['unpack_form'] = forms.ExtractUploadForm()
    data['unpack_success'] = False
    data['what_was_wrong_with_the_extracted_file'] = ''
    if request.method == 'POST':
        form = forms.ExtractUploadForm(request.POST, request.FILES)
        if form.is_valid():
            if form.cleaned_data['extracted_file'].read() == controllers.UntarMission.get_contents_we_want():
                data['unpack_success'] = True
                controllers.set_mission_completed(request.user.get_profile(), 'tar_extract')
            else:
                data['what_was_wrong_with_the_extracted_file'] = 'The uploaded file does not have the correct contents.'
        data['unpack_form'] = form
    return unpacking(request, data)
Exemplo n.º 2
0
def upload(request):
    # Initialize data array and some default values.
    data = {}
    data['create_form'] = forms.UploadForm()
    data['create_success'] = False
    data['what_was_wrong_with_the_tarball'] = ''
    if request.method == 'POST':
        form = forms.UploadForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                controllers.TarMission.check_tarfile(form.cleaned_data['tarfile'].read())
                data['create_success'] = True
                controllers.set_mission_completed(request.user.get_profile(), 'tar')
            except controllers.IncorrectTarFile, e:
                data['what_was_wrong_with_the_tarball'] = str(e)
        data['create_form'] = form