diff options
Diffstat (limited to 'packages/views.py')
-rw-r--r-- | packages/views.py | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/packages/views.py b/packages/views.py index 4f7c3b93..59779fe4 100644 --- a/packages/views.py +++ b/packages/views.py @@ -8,9 +8,10 @@ from django.core.mail import send_mail from django.db.models import Q from django.http import HttpResponse, Http404 from django.shortcuts import get_object_or_404, redirect -from django.template import loader, Context, RequestContext +from django.template import loader, Context from django.utils import simplejson from django.views.decorators.cache import never_cache +from django.views.decorators.http import require_POST from django.views.decorators.vary import vary_on_headers from django.views.generic import list_detail from django.views.generic.simple import direct_to_template @@ -23,7 +24,7 @@ from main.models import Arch, Repo, Signoff from main.utils import make_choice from mirrors.models import MirrorUrl from .models import PackageRelation -from .utils import get_group_info, get_differences_info +from .utils import get_group_info, get_differences_info, get_wrong_permissions def opensearch(request): if request.is_secure(): @@ -36,6 +37,7 @@ def opensearch(request): mimetype='application/opensearchdescription+xml') @permission_required('main.change_package') +@require_POST def update(request): ids = request.POST.getlist('pkgid') count = 0 @@ -104,8 +106,7 @@ def group_details(request, arch, name): arch = get_object_or_404(Arch, name=arch) arches = [ arch ] arches.extend(Arch.objects.filter(agnostic=True)) - pkgs = Package.objects.filter(packagegroup__name=name, - arch__in=arches) + pkgs = Package.objects.filter(groups__name=name, arch__in=arches) pkgs = pkgs.order_by('pkgname') if len(pkgs) == 0: raise Http404 @@ -126,8 +127,8 @@ def getmaintainer(request, name, repo, arch): return HttpResponse(str('\n'.join(names)), mimetype='text/plain') class PackageSearchForm(forms.Form): - repo = forms.ChoiceField(required=False) - arch = forms.ChoiceField(required=False) + repo = forms.MultipleChoiceField(required=False) + arch = forms.MultipleChoiceField(required=False) q = forms.CharField(required=False) maintainer = forms.ChoiceField(required=False) last_update = forms.DateField(required=False, widget=AdminDateWidget(), @@ -156,9 +157,9 @@ class PackageSearchForm(forms.Form): def __init__(self, *args, **kwargs): super(PackageSearchForm, self).__init__(*args, **kwargs) - self.fields['repo'].choices = [('', 'All')] + make_choice( + self.fields['repo'].choices = make_choice( [repo.name for repo in Repo.objects.all()]) - self.fields['arch'].choices = [('', 'All')] + make_choice( + self.fields['arch'].choices = make_choice( [arch.name for arch in Arch.objects.all()]) self.fields['q'].widget.attrs.update({"size": "30"}) maints = User.objects.filter(is_active=True).order_by('username') @@ -177,11 +178,11 @@ def search(request, page=None): if form.is_valid(): if form.cleaned_data['repo']: packages = packages.filter( - repo__name=form.cleaned_data['repo']) + repo__name__in=form.cleaned_data['repo']) if form.cleaned_data['arch']: packages = packages.filter( - arch__name=form.cleaned_data['arch']) + arch__name__in=form.cleaned_data['arch']) if form.cleaned_data['maintainer'] == 'orphan': inner_q = PackageRelation.objects.all().values('pkgbase') @@ -235,7 +236,7 @@ def search(request, page=None): def files(request, name, repo, arch): pkg = get_object_or_404(Package, pkgname=name, repo__name__iexact=repo, arch__name=arch) - fileslist = PackageFile.objects.filter(pkg=pkg).order_by('path') + fileslist = PackageFile.objects.filter(pkg=pkg).order_by('directory', 'filename') template = 'packages/files.html' if request.is_ajax(): template = 'packages/files-list.html' @@ -402,4 +403,32 @@ def arch_differences(request): } return direct_to_template(request, 'packages/differences.html', context) +@permission_required('main.change_package') +def stale_relations(request): + relations = PackageRelation.objects.select_related('user') + pkgbases = Package.objects.all().values('pkgbase') + + inactive_user = relations.filter(user__is_active=False) + missing_pkgbase = relations.exclude( + pkgbase__in=pkgbases).order_by('pkgbase') + wrong_permissions = get_wrong_permissions() + + context = { + 'inactive_user': inactive_user, + 'missing_pkgbase': missing_pkgbase, + 'wrong_permissions': wrong_permissions, + } + return direct_to_template(request, 'packages/stale_relations.html', context) + +@permission_required('packages.delete_packagerelation') +@require_POST +def stale_relations_update(request): + ids = set(request.POST.getlist('relation_id')) + + if ids: + PackageRelation.objects.filter(id__in=ids).delete() + + messages.info(request, "%d package relations deleted." % len(ids)) + return redirect('/packages/stale_relations/') + # vim: set ts=4 sw=4 et: |