def browse(request): files = get_files_browse_urls(request.user) if request.method == "POST": form = SearchForm(request.POST) if form.is_valid(): query = form.cleaned_data.get("q", "").lower() files = list( filter(lambda d: query in d["visible_filename"].lower(), files)) else: form = SearchForm() show_dirs = getattr(settings, "CKEDITOR_BROWSE_SHOW_DIRS", False) dir_list = sorted(set(os.path.dirname(f["src"]) for f in files), reverse=True) # Ensures there are no objects created from Thumbs.db files - ran across # this problem while developing on Windows if os.name == "nt": files = [f for f in files if os.path.basename(f["src"]) != "Thumbs.db"] context = { "show_dirs": show_dirs, "dirs": dir_list, "files": files, "form": form } return render(request, "ckeditor/browse.html", context)
def browse(request): files = get_files_browse_urls(request.user) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): query = form.cleaned_data.get('q', '').lower() files = list( filter(lambda d: query in d['visible_filename'].lower(), files)) else: form = SearchForm() show_dirs = getattr(settings, 'CKEDITOR_BROWSE_SHOW_DIRS', False) dir_list = sorted(set(os.path.dirname(f['src']) for f in files), reverse=True) # Ensures there are no objects created from Thumbs.db files - ran across # this problem while developing on Windows if os.name == 'nt': files = [f for f in files if os.path.basename(f['src']) != 'Thumbs.db'] context = { 'show_dirs': show_dirs, 'dirs': dir_list, 'files': files, 'form': form } return render(request, 'ckeditor/browse.html', context)
def get_context_data(self, **kwargs): context = super(BrowseView, self).get_context_data(**kwargs) files = get_files_browse_urls(self.request.user) if self.request.method == 'POST': form = SearchForm(self.request.POST) if form.is_valid(): query = form.cleaned_data.get('q', '').lower() files = list(filter(lambda d: query in d['visible_filename'].lower(), files)) else: form = SearchForm() show_dirs = getattr(settings, 'CKEDITOR_BROWSE_SHOW_DIRS', False) dir_list = sorted(set(os.path.dirname(f['src']) for f in files), reverse=True) # Ensures there are no objects created from Thumbs.db files - ran across this problem while developing on Windows if os.name == 'nt': files = [f for f in files if os.path.basename(f['src']) != 'Thumbs.db'] context.update({ 'show_dirs': show_dirs, 'dirs': dir_list, 'files': files, 'form': form }) return context
def accommodation_search(request): current_user = request.user if current_user.is_active: current_user = UserProfile.objects.get(user_id=current_user.id) if request.method == 'POST': # form post edildiyse form = SearchForm(request.POST) if form.is_valid(): setting = Settings.objects.get(pk=1) category = Category.objects.all() query = form.cleaned_data['query'] # formdan bilgiyi al catid = form.cleaned_data['catid'] if catid == 0: accommodations = Accommodation.objects.filter( title__icontains=query) # select * from accom... where title like %query% else: accommodations = Accommodation.objects.filter( title__icontains=query, category_id=catid) context = { 'setting': setting, 'accommodations': accommodations, 'category': category, 'current_user': current_user, 'page': 'konaklama' } return render(request, 'accommodation_search.html', context) return HttpResponseRedirect('/')
def custom_browse(request): files = get_files_browse_urls(request.user) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): query = form.cleaned_data.get('q', '').lower() files = list(filter(lambda d: query in d['visible_filename'].lower(), files)) else: form = SearchForm() show_dirs = getattr(settings, 'CKEDITOR_BROWSE_SHOW_DIRS', False) dir_list = sorted(set(os.path.dirname(f['src']) for f in files), reverse=True) # Ensures there are no objects created from Thumbs.db files - ran across this problem while developing on Windows if os.name == 'nt': files = [f for f in files if os.path.basename(f['src']) != 'Thumbs.db'] context = RequestContext(request, { 'show_dirs': show_dirs, 'dirs': dir_list, 'files': files, 'form': form }) return render_to_response('board/ckeditor/custom_browse.html', context)
def browse(request): files = get_files_browse_urls(request.user) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): files = filter( lambda d: form.cleaned_data.get('q', '').lower() in d[ 'visible_filename'].lower(), files) else: form = SearchForm() context = RequestContext(request, {'files': files, 'form': form}) return render_to_response('ckeditor/browse.html', context)
def browse(request): files = get_files_browse_urls(request.user) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): files = filter(lambda d: form.cleaned_data.get('q', '').lower() in d['visible_filename'].lower(), files) else: form = SearchForm() context = RequestContext(request, { 'files': files, 'form': form }) return render_to_response('ckeditor/browse.html', context)
def vehicle_search(request): if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): category = Category.objects.all() query = form.cleaned_data['q'] vehicles = Vehicle.objects.filter(title__icontains=query) context = {'vehicles': vehicles, 'category': category, } return render(request, 'vehicles_search.html', context) return HttpResponseRedirect('/')
def browse(request): logger.debug('in browse...') file_type = 'File' param_type = request.GET.get('type', '') if param_type == 'image': file_type = 'Image' # dirs = get_directories(request.user) # get our directory # path = '' # browse_path = os.path.join(settings.MEDIA_ROOT, settings.CKEDITOR_UPLOAD_PATH, path) # # thumbnail_path = os.path.join(settings.DATA_DIR, settings.CKEDITOR_THUMBNAIL_PATH, path) # logger.debug("browse_path: %s", browse_path) # i=0 # img_files = [] # for root, dirs, files in os.walk(browse_path): # # for name in dirs: # # logger.debug(os.path.join(root, name)) # if (i>=100): # break # for name in files: # i=i+1 # if i>=100: # break # logger.debug(name) # src = get_relative_path(os.path.join(root, name)) # img_files.append({ # 'thumb': src.replace(settings.CKEDITOR_UPLOAD_PATH, settings.CKEDITOR_THUMBNAIL_PATH), # 'src': src, # 'is_image': is_image(src), # 'visible_filename': name, # }) # # logger.debug("image count: %s", i) # path = '' browse_path = os.path.join(settings.MEDIA_ROOT, settings.CKEDITOR_UPLOAD_PATH, path) # thumbnail_path = os.path.join(settings.DATA_DIR, settings.CKEDITOR_THUMBNAIL_PATH, path) logger.debug("browse_path: %s", browse_path) img_files = [] i=0 for root, dirs, files in os.walk(browse_path): # for name in dirs: # logger.debug(os.path.join(root, name)) for name in files: i=i+1 logger.debug(name) full_filename = os.path.join(root, name) src = get_relative_path(full_filename) img_files.append({ 'thumb': src.replace(settings.CKEDITOR_UPLOAD_PATH, settings.CKEDITOR_THUMBNAIL_PATH), 'src': src, 'is_image': is_image(src), 'visible_filename': name, 'modified': os.path.getmtime(full_filename) }) logger.debug("image count: %s", i) # for name in os.listdir(browse_path): # # print all dirs # if os.path.isdir(name): # logger.debug(name) # # for name in os.listdir(browse_path): # # print all files # if not os.path.isdir(name): # logger.debug(name) # img_files = get_files_browse_urls(request.user) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): query = form.cleaned_data.get('q', '').lower() img_files = list(filter(lambda d: query in d['visible_filename'].lower(), img_files)) else: form = SearchForm() show_dirs = getattr(settings, 'CKEDITOR_BROWSE_SHOW_DIRS', False) dir_list = sorted(set(os.path.dirname(f['src']) for f in img_files), reverse=True) logger.debug("sorting...") # sort our list by last modified date so we can pull the last 25 files # sorted(img_files, key=itemgetter(4), reverse=True) sorted(img_files, key=lambda image_props: image_props.get('modified', 0), reverse=True) # sort by modified mtime logger.debug("sorted...") # grab the first 25 files in the sorted list to return to the view i=0 show_files = [] for img in img_files: if i >= 25: break if file_type == 'Image': if img.get('is_image') == True: # only move over images logger.debug("moving image: %s [%s]", img.get('src', ''), img.get('modified', '')) i = i + 1 show_files.append(img) else: logger.debug("file [%s] is not an image skipping...", img.get('src', '')) else: # file type is File if img.get('is_image') == False: # only move over files that are not images logger.debug("moving file: %s [%s]", img.get('src', ''), img.get('modified', '')) i = i + 1 show_files.append(img) else: logger.debug("file [%s] is an image skipping...", img.get('src', '')) logger.debug("moved %s files", i) # Ensures there are no objects created from Thumbs.db files - ran across this problem while developing on Windows # if os.name == 'nt': # files = [f for f in files if os.path.basename(f['src']) != 'Thumbs.db'] context = RequestContext(request, { 'file_type': file_type, 'show_dirs': show_dirs, 'dirs': dir_list, 'files': show_files, 'form': form }) return render_to_response('ckeditor/browse.html', context)