Exemplo n.º 1
0
def addphotos(request):
    libraries = get_libraries('photo')
    if request.method == 'POST':
        form = PhotosForm(request.POST, request.FILES)
        if form.is_valid():
            library = form.cleaned_data['library']
            ctime = time.strftime("%Y%m%d%H%M%S")
            for count, x in enumerate(request.FILES.getlist('files')):
                def process_file(f):
                    fname, fext = os.path.splitext(f.name)
                    newname = '%s_%s%s' % (ctime, str(count), fext)
                    with open('%s%s/%s' % (settings.BASE_DIR, settings.MEDIA_ROOT, newname), 'wb+') as destination:
                        for chunk in f.chunks():
                            destination.write(chunk)
                    photo = Photo.objects.get_or_create(
                            library = Library.objects.get(id=library),
                            author = 'user',
                            title = f.name,
                            oldname = f,
                            newname = newname
                        )
                process_file(x)
        return redirect('/internal/library/photo/list/')
    else:
        form = PhotosForm()
    context = {
        'libraries': get_libraries('photo')
    }
    return render(request, 'addphotos.html', context=context)
Exemplo n.º 2
0
def index(request):
    context = {
        'plibraries': get_libraries('photo'),
        'alibraries': get_libraries('audio'),
        'photos': Photo.objects.all(),
        'audios': Audio.objects.all(),
    }
    return render(request, "index_library.html", context=context)
Exemplo n.º 3
0
def index(request):
    context = {
        'categories': get_categories(),
        'plibraries': get_libraries('photo'),
        'alibraries': get_libraries('audio'),
        'articles': Article.objects.all(),
        'photos': Photo.objects.all(),
    }
    return render(request, 'index_home.html', context=context)
Exemplo n.º 4
0
def addphoto(request):
    libraries = get_libraries('photo')
    if request.method == 'POST':
        form = PhotoForm(request.POST, request.FILES)
        if form.is_valid():
            print('is valid')
            library = form.cleaned_data['library']
            author = form.cleaned_data['author']
            title = form.cleaned_data['title']
            ctime = time.strftime("%Y%m%d%H%M%S")
            file = request.FILES['file']
            fname, fext = os.path.splitext(file.name)
            newname = '%s_0%s' % (ctime, fext)
            with open('%s%s/%s' % (settings.BASE_DIR, settings.MEDIA_ROOT, newname), 'wb+') as destination:
                for chunk in file.chunks():
                    destination.write(chunk)
            photo = Photo.objects.get_or_create(
                    library = Library.objects.get(id=library),
                    author = author,
                    title = title,
                    oldname = file,
                    newname = newname
                )
            return redirect('/internal/library/photo/list/')
        else:
            return HttpResponse('error during upload')
    else:
        form = PhotoForm()
    context = {
        'libraries': libraries
    }
    return render(request, 'addphoto.html', context=context)