def package_list(request): packages = PackageName.objects.select_related() if 'arch' in request.GET: packages = packages.filter( package__arch=int(request.GET['arch'])).distinct() if 'packagetype' in request.GET: packages = packages.filter( package__packagetype=request.GET['packagetype']).distinct() if 'search' in request.GET: terms = request.GET['search'].lower() query = Q() for term in terms.split(' '): q = Q(name__icontains=term) query = query & q packages = packages.filter(query) else: terms = '' page_no = request.GET.get('page') paginator = Paginator(packages, 50) try: page = paginator.page(page_no) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) filter_list = [] filter_list.append( Filter(request, 'arch', PackageArchitecture.objects.all())) # Disabled due to being a huge slowdown # filter_list.append( # Filter( # request, 'packagetype', # Package.objects.values_list('packagetype', flat=True).distinct())) filter_bar = FilterBar(request, filter_list) return render( request, 'packages/package_list.html', { 'page': page, 'filter_bar': filter_bar, 'terms': terms }, )
def report_list(request): reports = Report.objects.select_related() if 'host_id' in request.GET: reports = reports.filter(hostname=int(request.GET['host_id'])) if 'processed' in request.GET: processed = request.GET['processed'] == 'True' reports = reports.filter(processed=processed) if 'search' in request.GET: terms = request.GET['search'].lower() query = Q() for term in terms.split(' '): q = Q(host__icontains=term) query = query & q reports = reports.filter(query) else: terms = '' page_no = request.GET.get('page') paginator = Paginator(reports, 50) try: page = paginator.page(page_no) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) filter_list = [] filter_list.append(Filter(request, 'processed', { False: 'No', True: 'Yes' })) filter_bar = FilterBar(request, filter_list) return render( request, 'reports/report_list.html', { 'page': page, 'filter_bar': filter_bar, 'terms': terms }, )
def host_list(request): hosts = Host.objects.select_related() if 'domain' in request.GET: hosts = hosts.filter(domain=int(request.GET['domain'])) if 'package_id' in request.GET: hosts = hosts.filter(packages=int(request.GET['package_id'])) if 'package' in request.GET: hosts = hosts.filter(packages__name__name=request.GET['package']) if 'repo' in request.GET: hosts = hosts.filter(repos=int(request.GET['repo'])) if 'arch' in request.GET: hosts = hosts.filter(arch=int(request.GET['arch'])) if 'os' in request.GET: hosts = hosts.filter(os=int(request.GET['os'])) if 'osgroup' in request.GET: hosts = hosts.filter(os__osgroup=int(request.GET['osgroup'])) if 'tag' in request.GET: hosts = TaggedItem.objects.get_by_model(hosts, request.GET['tag']) if 'reboot_required' in request.GET: reboot_required = request.GET['reboot_required'] == 'True' hosts = hosts.filter(reboot_required=reboot_required) if 'search' in request.GET: terms = request.GET['search'].lower() query = Q() for term in terms.split(' '): q = Q(hostname__icontains=term) query = query & q hosts = hosts.filter(query) else: terms = '' page_no = request.GET.get('page') paginator = Paginator(hosts, 50) try: page = paginator.page(page_no) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) filter_list = [] mytags = {} for tag in Tag.objects.usage_for_model(Host): mytags[tag.name] = tag.name filter_list.append(Filter(request, 'tag', mytags)) filter_list.append(Filter(request, 'domain', Domain.objects.all())) filter_list.append(Filter(request, 'os', OS.objects.all())) filter_list.append(Filter(request, 'osgroup', OSGroup.objects.all())) filter_list.append( Filter(request, 'arch', MachineArchitecture.objects.all())) filter_list.append( Filter(request, 'reboot_required', { False: 'No', True: 'Yes' })) filter_bar = FilterBar(request, filter_list) return render( request, 'hosts/host_list.html', { 'page': page, 'filter_bar': filter_bar, 'terms': terms }, )
def repo_list(request): repos = Repository.objects.select_related().order_by('name') if 'repotype' in request.GET: repos = repos.filter(repotype=request.GET['repotype']) if 'arch' in request.GET: repos = repos.filter(arch=request.GET['arch']) if 'osgroup' in request.GET: repos = repos.filter(osgroup=request.GET['osgroup']) if 'security' in request.GET: security = request.GET['security'] == 'True' repos = repos.filter(security=security) if 'enabled' in request.GET: enabled = request.GET['enabled'] == 'True' repos = repos.filter(enabled=enabled) if 'package_id' in request.GET: repos = repos.filter(mirror__packages=int(request.GET['package_id'])) if 'search' in request.GET: terms = request.GET['search'].lower() query = Q() for term in terms.split(' '): q = Q(name__icontains=term) query = query & q repos = repos.filter(query) else: terms = '' repos = repos.distinct() page_no = request.GET.get('page') paginator = Paginator(repos, 50) try: page = paginator.page(page_no) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) filter_list = [] filter_list.append( Filter( request, 'repotype', Repository.objects.values_list('repotype', flat=True).distinct())) filter_list.append( Filter(request, 'arch', MachineArchitecture.objects.all())) filter_list.append(Filter(request, 'enabled', {False: 'No', True: 'Yes'})) filter_list.append(Filter(request, 'security', {False: 'No', True: 'Yes'})) filter_list.append(Filter(request, 'osgroup', OSGroup.objects.all())) filter_bar = FilterBar(request, filter_list) return render( request, 'repos/repo_list.html', { 'page': page, 'filter_bar': filter_bar, 'terms': terms }, )