Esempio n. 1
0
def index(request, sel_event_id):
    # Handle form data, if any
    if request.method == 'POST':
        # Check for permissions
        if not request.user.has_perm('admin_upload.add_uploadedfile'):
            raise Http403
        
        # Handle form
        uploadform = UploadForm(request.POST, request.FILES)
        if uploadform.is_valid():
            data = uploadform.save(commit=False)
            data.user = request.user
            data.date = timezone.now()
            data.event_id = int(sel_event_id)
            data.save()
            logger.info('File "{}" uploaded.'.format(data.file.name),
                        extra={'user': request.user, 'event_id': sel_event_id})
            return HttpResponseRedirect(reverse('manage-uploads:index', args=(sel_event_id,)))
    else:
        uploadform = UploadForm()
    
    # Get filelist
    files = UploadedFile.objects.filter(event_id=sel_event_id)
    
    # Render response
    return admin_render(request, "admin_upload/index.html", {
        'files': files,
        'uploadform': uploadform,
        'selected_event_id': int(sel_event_id),
    })
Esempio n. 2
0
def editfile(request, sel_event_id, file_id):
    # Check for permissions
    if not request.user.has_perm('admin_upload.change_uploadedfile'):
        raise Http403

    # Get previously uploaded file
    uploadedfile = get_object_or_404(UploadedFile, pk=file_id)

    # Handle form data
    if request.method == 'POST':
        uploadform = UploadForm(request.POST,
                                request.FILES,
                                instance=uploadedfile)
        if uploadform.is_valid():
            data = uploadform.save()
            logger.info('File "{}" edited.'.format(data.file.name),
                        extra={
                            'user': request.user,
                            'event_id': sel_event_id
                        })
            return HttpResponseRedirect(
                reverse('manage-uploads:index', args=(sel_event_id, )))
    else:
        uploadform = UploadForm(instance=uploadedfile)

    # Render response
    return admin_render(request, "admin_upload/edit.html", {
        'uploadform': uploadform,
        'selected_event_id': int(sel_event_id),
    })
Esempio n. 3
0
def index(request, sel_event_id):
    # Handle form data, if any
    if request.method == 'POST':
        # Check for permissions
        if not request.user.has_perm('admin_upload.add_uploadedfile'):
            raise Http403

        # Handle form
        uploadform = UploadForm(request.POST, request.FILES)
        if uploadform.is_valid():
            data = uploadform.save(commit=False)
            data.user = request.user
            data.date = timezone.now()
            data.event_id = int(sel_event_id)
            data.save()
            logger.info('File "{}" uploaded.'.format(data.file.name),
                        extra={
                            'user': request.user,
                            'event_id': sel_event_id
                        })
            return HttpResponseRedirect(
                reverse('manage-uploads:index', args=(sel_event_id, )))
    else:
        uploadform = UploadForm()

    # Get filelist
    files = UploadedFile.objects.filter(event_id=sel_event_id)

    # Render response
    return admin_render(
        request, "admin_upload/index.html", {
            'files': files,
            'uploadform': uploadform,
            'selected_event_id': int(sel_event_id),
        })
Esempio n. 4
0
def editfile(request, sel_event_id, file_id):
    # Check for permissions
    if not request.user.has_perm('admin_upload.change_uploadedfile'):
        raise Http403
    
    # Get previously uploaded file
    uploadedfile = get_object_or_404(UploadedFile, pk=file_id)
    
    # Handle form data
    if request.method == 'POST':
        uploadform = UploadForm(request.POST, request.FILES, instance=uploadedfile)
        if uploadform.is_valid():
            data = uploadform.save()
            logger.info('File "'+data.file.name+'" edited.', extra={'user': request.user, 'event_id': sel_event_id})
            return HttpResponseRedirect(reverse('manage-uploads:index', args=(sel_event_id)))
    else:
        uploadform = UploadForm(instance=uploadedfile)
    
    # Render response
    return admin_render(request, "admin_upload/edit.html", {
        'uploadform': uploadform,
        'selected_event_id': int(sel_event_id),
    })