def search(request, page): # Recherche q, method, distro # Construire le début de la requete packages = Package.objects \ .select_related('arch', 'distribution') \ .order_by('-distribution', 'name') # Récupérer les variables q = request.GET['q'] method = request.GET['method'] distro = request.GET['distro'] # Filtrer pour la distro (dans ce cas le order_by est ignoré) di = None if distro != 'all': packages = packages.filter(distribution=int(distro)) di = get_object_or_404(Distribution, pk=distro) # Filtrer suivant le critère de recherche if method == 'match': packages = packages.filter(name__exact=q) elif method == 'contains': packages = packages.filter(name__contains=q) elif method == 'starts': packages = packages.filter(name__startswith=q) elif method == 'ends': packages = packages.filter(name__endswith=q) else: raise Http404 # Paginer paginator = Paginator(packages, 20) try: page = int(page) except ValueError: page = 1 try: packages = paginator.page(page).object_list except (EmptyPage, InvalidPage): packages = paginator.page(paginator.num_pages).object_list # Rendre la template return tpl( 'packages/list.html', { 'packages': packages, 'list_pages': get_list_page(page, paginator.num_pages, 4), 'q': q, 'method': method, 'udistro': distro, 'distro': di }, request)
def online(request, page): # Afficher les utilisateurs en ligne page = int(page) # Récupérer les informations du cache des connectés activities = Activity.objects \ .select_related('user') \ .order_by('-date') # Compter anon = 0 users = 0 connected_users = [] for act in activities: if act.user_id: users += 1 else: anon += 1 if act.template in actnames: act.activity = actnames[act.template] else: act.activity = _('Page privée') # Paginer paginator = Paginator(activities, 30) # 30 utilisateurs par page try: pg = paginator.page(page) except (EmptyPage, InvalidPage): pg = paginator.page(paginator.num_pages) # Rendre la template return tpl( 'users/list.html', { 'list_pages': get_list_page(page, paginator.num_pages, 4), 'profiles': pg.object_list, 'is_connected': True, 'anons': anon, 'pindex': 4, 'regs': users }, request)
def list(request, page): # Lister les membres, par pseudo page = int(page) members = Profile.objects.select_related('user').order_by( '-main_group', 'user__username') paginator = Paginator(members, 30) # 30 utilisateurs par page try: pg = paginator.page(page) except (EmptyPage, InvalidPage): pg = paginator.page(paginator.num_pages) return tpl( 'users/list.html', { 'list_pages': get_list_page(page, paginator.num_pages, 4), 'profiles': pg.object_list, 'pindex': 2, 'is_staff': False }, request)
def changelog(request, package_id, page): # Afficher les changements d'un paquet package_id = int(package_id) # Récupérer le paquet package = get_object_or_404(Package, pk=package_id) # Récupérer les éléments de changelog de ce paquet entries = ChangeLog.objects \ .filter(package=package_id) \ .select_related('distribution') \ .order_by('-date') # Pour chaque entrée, récupérer la chaîne traduite strings = String.objects.filter(package=package) for entry in entries: entry.content = str_of_package(package, request.LANGUAGE_CODE.split('-')[0], 3, strings, entry).content # Paginer paginator = Paginator(entries, 20) try: page = int(page) except ValueError: page = 1 try: entries = paginator.page(page).object_list except (EmptyPage, InvalidPage): entries = paginator.page(paginator.num_pages).object_list # Afficher dans la template return tpl( 'packages/changelog.html', { 'package': package, 'list_pages': get_list_page(page, paginator.num_pages, 4), 'entries': entries }, request)
def listsection(request, distro_id, section_id, page): # Affichage des paquets d'une section distro_id = int(distro_id) section_id = int(section_id) # Récupérer la distribution distro = get_object_or_404(Distribution, pk=distro_id) # Récupérer la section section = get_object_or_404(Section, pk=section_id) # Récupérer les versions (et leurs paquets) de la distribution dans la bonne section packages = Package.objects \ .select_related('arch') \ .filter(distribution=distro, section=section) \ .order_by('name') # Paginer paginator = Paginator(packages, 20) try: page = int(page) except ValueError: page = 1 try: packages = paginator.page(page).object_list except (EmptyPage, InvalidPage): packages = paginator.page(paginator.num_pages).object_list # Rendre la template return tpl( 'packages/list.html', { 'distro': distro, 'section': section, 'list_pages': get_list_page(page, paginator.num_pages, 4), 'packages': packages }, request)
def viewsource(request, source_id, topic_page, list_page): source_id = int(source_id) # Prendre le paquet source try: source = SourcePackage.objects.select_related('topic').get( pk=source_id) except: raise Http404 # Prendre les paquets binaires qu'elle construit packages = Package.objects \ .select_related('arch', 'distribution', 'section') \ .filter(sourcepkg=source) \ .order_by('name') # Prendre l'historique de la source logs = SourceLog.objects \ .select_related('distribution') \ .filter(source=source) \ .order_by('-id') # Paginer le tout paginator = Paginator(logs, 25) try: list_page = int(list_page) except ValueError: list_page = 1 try: plogs = paginator.page(list_page) except (EmptyPage, InvalidPage): plogs = paginator.page(paginator.num_pages) # Dernier log pour les informations intéressantes if list_page == 1: # Première page, lastlog est le premier log, on peut économiser une requête logs = list(plogs.object_list) lastlog = logs[0] else: # Pas première page, il faut aller chercher le premier log lastlog = logs[0] logs = plogs.object_list lastlog.depends = lastlog.depends.split(';') lastlog.conflicts = lastlog.conflicts.split(';') lastlog.suggests = lastlog.suggests.split(';') # Flags de chaque log for log in logs: log.flag_latest = ((log.flags & 1) != 0) log.flag_automatic = ((log.flags & 2) == 0) # Le flag est MANUAL log.flag_failed = ((log.flags & 4) != 0) log.flag_warnings = ((log.flags & 64) != 0) log.flag_building = ((log.flags & 128) != 0) # Rendre la template config = { 'source': source, 'packages': packages, 'logs': logs, 'lastlog': lastlog, 'topic_p': topic_page, 'list_p': list_page, 'list_list_page': get_list_page(list_page, paginator.num_pages, 4), 'is_comments': True } return list_posts(request, source.topic, topic_page, config, 'packages/viewsource.html')