def upload_file(request): selected_theme = request.GET.get("theme_edit", get_theme()) if not is_valid_theme(selected_theme): raise Http404(_('Specified theme does not exist')) if is_theme_read_only(selected_theme): raise Http403 if request.method == 'POST': form = UploadForm(request.POST, request.FILES) if form.is_valid(): file_dir = form.cleaned_data['file_dir'] overwrite = form.cleaned_data['overwrite'] def callback(file_path, uuid, selected_theme=selected_theme, file_dir=file_dir, overwrite=overwrite): theme_root = get_theme_root(selected_theme) file_name = os.path.basename(file_path) full_filename = os.path.join(file_dir, file_name) if (not is_valid_path(theme_root, file_dir) or not is_valid_path(theme_root, full_filename)): raise Http403 if os.path.isfile(os.path.join(theme_root, full_filename)) and not overwrite: msg_string = 'File %s already exists in that folder.' % (file_name) raise uploader.CallbackError(msg_string) copy_file_to_theme(file_path, selected_theme, file_dir, file_name) EventLog.objects.log() return uploader.post(request, callback) else: # not valid messages.add_message(request, messages.ERROR, form.errors) return HttpResponse('invalid', content_type="text/plain") return HttpResponseRedirect('/theme-editor/editor/')
def upload_file(request): if not has_perm(request.user, 'theme_editor.add_themefileversion'): raise Http403 if request.method == 'POST': form = UploadForm(request.POST, request.FILES) if form.is_valid(): file_dir = form.cleaned_data['file_dir'] overwrite = form.cleaned_data['overwrite'] def callback(file_path, uuid, file_dir=file_dir, overwrite=overwrite): file_name = os.path.basename(file_path) full_filename = os.path.join(file_dir, file_name) if os.path.isfile(full_filename) and not overwrite: msg_string = 'File %s already exists in that folder.' % (file_name) raise uploader.CallbackError(msg_string) else: handle_uploaded_file(file_path, file_dir) EventLog.objects.log() return uploader.post(request, callback) else: # not valid messages.add_message(request, messages.ERROR, form.errors) return HttpResponse('invalid', content_type="text/plain") return HttpResponseRedirect('/theme-editor/editor/')
def upload_file(request): if not has_perm(request.user, 'theme_editor.add_themefileversion'): raise Http403 if request.method == 'POST': form = UploadForm(request.POST, request.FILES) if form.is_valid(): file_dir = form.cleaned_data['file_dir'] overwrite = form.cleaned_data['overwrite'] def callback(file_path, uuid, file_dir=file_dir, overwrite=overwrite): file_name = os.path.basename(file_path) full_filename = os.path.join(file_dir, file_name) if os.path.isfile(full_filename) and not overwrite: msg_string = 'File %s already exists in that folder.' % (file_name) raise uploader.CallbackError(msg_string) else: handle_uploaded_file(file_path, file_dir) EventLog.objects.log() return uploader.post(request, callback) else: # not valid messages.add_message(request, messages.ERROR, form.errors) return HttpResponse('invalid', content_type="text/plain") return HttpResponseRedirect('/theme-editor/editor/')
def photos_batch_add(request, photoset_id=0): """ params: request, photoset_id returns: HttpResponse """ from tendenci.libs.uploader import uploader # photoset permission required to add photos if not has_perm(request.user, 'photos.add_photoset'): raise Http403 if request.method == 'POST': def callback(file_path, uuid, request=request, photoset_id=photoset_id): handle_uploaded_photo(request, photoset_id, file_path) return uploader.post(request, callback) else: if not photoset_id: HttpResponseRedirect(reverse('photoset_latest')) photo_set = get_object_or_404(PhotoSet, id=photoset_id) photo_limit = get_setting('module', 'photos', 'photolimit') try: photo_limit = int(photo_limit) except ValueError: # default limit for photo set images 150 photo_limit = 150 image_slot_left = photo_limit - photo_set.image_set.count() # show the upload UI return render_to_resp(request=request, template_name='photos/batch-add.html', context={ "photoset_id": photoset_id, "photo_set": photo_set, "csrf_token": csrf_get_token(request), "image_slot_left": image_slot_left, })
def photos_batch_add(request, photoset_id=0): """ params: request, photoset_id returns: HttpResponse """ from tendenci.libs.uploader import uploader # photoset permission required to add photos if not has_perm(request.user, 'photos.add_photoset'): raise Http403 if request.method == 'POST': def callback(file_path, uuid, request=request, photoset_id=photoset_id): handle_uploaded_photo(request, photoset_id, file_path) return uploader.post(request, callback) else: if not photoset_id: HttpResponseRedirect(reverse('photoset_latest')) photo_set = get_object_or_404(PhotoSet, id=photoset_id) photo_limit = get_setting('module', 'photos', 'photolimit') try: photo_limit = int(photo_limit) except ValueError: # default limit for photo set images 150 photo_limit = 150 image_slot_left = photo_limit - photo_set.image_set.count() # show the upload UI return render_to_response('photos/batch-add.html', { "photoset_id": photoset_id, "photo_set": photo_set, "csrf_token": csrf_get_token(request), "image_slot_left": image_slot_left, }, context_instance=RequestContext(request))