summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-03-06 11:05:57 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-03-06 11:05:57 -0300
commit3aa14c9fbec24f5049e12a8dbb5ce059d2c8f5f3 (patch)
tree28755cf0ae66b145d752358c1f722c2d095e877a /packages
parentc738e2c8f687f3417b90c951254121cce491843a (diff)
parent65e965c8f76677904f5d98965e13bf89726247d4 (diff)
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts: media/archweb.css public/views.py urls.py
Diffstat (limited to 'packages')
-rw-r--r--packages/admin.py11
-rw-r--r--packages/migrations/0004_auto__add_license.py118
-rw-r--r--packages/migrations/0005_move_license_data.py120
-rw-r--r--packages/models.py42
-rw-r--r--packages/urls.py2
-rw-r--r--packages/urls_groups.py9
-rw-r--r--packages/utils.py24
-rw-r--r--packages/views.py51
8 files changed, 364 insertions, 13 deletions
diff --git a/packages/admin.py b/packages/admin.py
new file mode 100644
index 00000000..3ecfdbb1
--- /dev/null
+++ b/packages/admin.py
@@ -0,0 +1,11 @@
+from django.contrib import admin
+
+from .models import PackageRelation
+
+class PackageRelationAdmin(admin.ModelAdmin):
+ list_display = ('user', 'pkgbase', 'type')
+ list_filter = ('type', 'user')
+
+admin.site.register(PackageRelation, PackageRelationAdmin)
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/migrations/0004_auto__add_license.py b/packages/migrations/0004_auto__add_license.py
new file mode 100644
index 00000000..001440fe
--- /dev/null
+++ b/packages/migrations/0004_auto__add_license.py
@@ -0,0 +1,118 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'License'
+ db.create_table('packages_license', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('pkg', self.gf('django.db.models.fields.related.ForeignKey')(related_name='licenses', to=orm['main.Package'])),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ))
+ db.send_create_signal('packages', ['License'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'License'
+ db.delete_table('packages_license')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'main.arch': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Arch', 'db_table': "'arches'"},
+ 'agnostic': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+ },
+ 'main.package': {
+ 'Meta': {'ordering': "('pkgname',)", 'object_name': 'Package', 'db_table': "'packages'"},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Arch']"}),
+ 'build_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'compressed_size': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'files_last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'flag_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'installed_size': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
+ 'last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'license': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+ 'packager': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+ 'packager_str': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgdesc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+ 'pkgname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Repo']"}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
+ },
+ 'main.repo': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Repo', 'db_table': "'repos'"},
+ 'bugs_project': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+ 'svn_root': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'packages.license': {
+ 'Meta': {'object_name': 'License'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'licenses'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagegroup': {
+ 'Meta': {'object_name': 'PackageGroup'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'groups'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagerelation': {
+ 'Meta': {'unique_together': "(('pkgbase', 'user', 'type'),)", 'object_name': 'PackageRelation'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'type': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'package_relations'", 'to': "orm['auth.User']"})
+ }
+ }
+
+ complete_apps = ['packages']
diff --git a/packages/migrations/0005_move_license_data.py b/packages/migrations/0005_move_license_data.py
new file mode 100644
index 00000000..1c1e689a
--- /dev/null
+++ b/packages/migrations/0005_move_license_data.py
@@ -0,0 +1,120 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+ depends_on = (
+ # the last structural change to the package model
+ ('main', '0026_auto__add_field_package_packager_str__add_field_package_packager'),
+ )
+
+ def forwards(self, orm):
+ "Migrate the flat license text to a seperate relation."
+ for pkg in orm['main.Package'].objects.all():
+ licenses = pkg.license.split(u', ')
+ for license in licenses:
+ pkg.licenses.create(name=license)
+
+ def backwards(self, orm):
+ for pkg in orm['main.Package'].objects.all():
+ pkg.license = u', '.join([l.name for l in pkg.licenses.all()])
+ pkg.save()
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'main.arch': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Arch', 'db_table': "'arches'"},
+ 'agnostic': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+ },
+ 'main.package': {
+ 'Meta': {'ordering': "('pkgname',)", 'object_name': 'Package', 'db_table': "'packages'"},
+ 'arch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Arch']"}),
+ 'build_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'compressed_size': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'files_last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'flag_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'installed_size': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
+ 'last_update': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'license': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+ 'packager': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+ 'packager_str': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgdesc': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+ 'pkgname': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'pkgrel': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkgver': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'repo': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'packages'", 'to': "orm['main.Repo']"}),
+ 'url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
+ },
+ 'main.repo': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Repo', 'db_table': "'repos'"},
+ 'bugs_project': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+ 'svn_root': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'testing': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'packages.license': {
+ 'Meta': {'object_name': 'License'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'licenses'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagegroup': {
+ 'Meta': {'object_name': 'PackageGroup'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'groups'", 'to': "orm['main.Package']"})
+ },
+ 'packages.packagerelation': {
+ 'Meta': {'unique_together': "(('pkgbase', 'user', 'type'),)", 'object_name': 'PackageRelation'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkgbase': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'type': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'package_relations'", 'to': "orm['auth.User']"})
+ }
+ }
+
+ complete_apps = ['packages']
diff --git a/packages/models.py b/packages/models.py
index 70ac4fe5..5dbdea45 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.db.models.signals import post_save
from django.contrib.auth.models import User
class PackageRelation(models.Model):
@@ -17,6 +18,21 @@ class PackageRelation(models.Model):
pkgbase = models.CharField(max_length=255)
user = models.ForeignKey(User, related_name="package_relations")
type = models.PositiveIntegerField(choices=TYPE_CHOICES, default=MAINTAINER)
+
+ def get_associated_packages(self):
+ # TODO: delayed import to avoid circular reference
+ from main.models import Package
+ return Package.objects.filter(pkgbase=self.pkgbase).select_related(
+ 'arch', 'repo')
+
+ def repositories(self):
+ packages = self.get_associated_packages()
+ return sorted(set([p.repo for p in packages]))
+
+ def __unicode__(self):
+ return "%s: %s (%s)" % (
+ self.pkgbase, self.user, self.get_type_display())
+
class Meta:
unique_together = (('pkgbase', 'user', 'type'),)
@@ -25,7 +41,31 @@ class PackageGroup(models.Model):
Represents a group a package is in. There is no actual group entity,
only names that link to given packages.
'''
- pkg = models.ForeignKey('main.Package')
+ pkg = models.ForeignKey('main.Package', related_name='groups')
+ name = models.CharField(max_length=255)
+
+ def __unicode__(self):
+ return "%s: %s" % (name, pkg)
+
+class License(models.Model):
+ pkg = models.ForeignKey('main.Package', related_name='licenses')
name = models.CharField(max_length=255)
+ def __unicode__(self):
+ return self.name
+
+ class Meta:
+ ordering = ['name']
+
+def remove_inactive_maintainers(sender, instance, created, **kwargs):
+ # instance is an auth.models.User; we want to remove any existing
+ # maintainer relations if the user is no longer active
+ if not instance.is_active:
+ maint_relations = PackageRelation.objects.filter(user=instance,
+ type=PackageRelation.MAINTAINER)
+ maint_relations.delete()
+
+post_save.connect(remove_inactive_maintainers, sender=User,
+ dispatch_uid="packages.models")
+
# vim: set ts=4 sw=4 et:
diff --git a/packages/urls.py b/packages/urls.py
index b7ce5c74..638a370a 100644
--- a/packages/urls.py
+++ b/packages/urls.py
@@ -25,6 +25,8 @@ urlpatterns = patterns('packages.views',
(r'^(?P<page>\d+)/$', 'search'),
(r'^differences/$', 'arch_differences'),
+ (r'^stale_relations/$', 'stale_relations'),
+ (r'^stale_relations/update/$','stale_relations_update'),
(r'^(?P<name>[A-z0-9\-+.]+)/$',
'details'),
diff --git a/packages/urls_groups.py b/packages/urls_groups.py
new file mode 100644
index 00000000..c561e50d
--- /dev/null
+++ b/packages/urls_groups.py
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import patterns
+
+urlpatterns = patterns('packages.views',
+ (r'^$', 'groups', {}, 'groups-list'),
+ (r'^(?P<arch>[A-z0-9]+)/$', 'groups'),
+ (r'^(?P<arch>[A-z0-9]+)/(?P<name>[A-z0-9\-+.]+)/$', 'group_details'),
+)
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/utils.py b/packages/utils.py
index aaec0ec4..8d9f13ab 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -5,7 +5,7 @@ from operator import itemgetter
from main.models import Package
from main.utils import cache_function
-from .models import PackageGroup
+from .models import PackageGroup, PackageRelation
@cache_function(300)
def get_group_info(include_arches=None):
@@ -128,4 +128,26 @@ SELECT p.id, q.id
differences.sort(key=lambda a: (a.repo.name, a.pkgname))
return differences
+def get_wrong_permissions():
+ sql = """
+SELECT DISTINCT id
+ FROM (
+ SELECT pr.id, p.repo_id, pr.user_id
+ FROM packages p
+ JOIN packages_packagerelation pr ON p.pkgbase = pr.pkgbase
+ WHERE pr.type = %s
+ ) pkgs
+ WHERE pkgs.repo_id NOT IN (
+ SELECT repo_id FROM user_profiles_allowed_repos ar
+ INNER JOIN user_profiles up ON ar.userprofile_id = up.id
+ WHERE up.user_id = pkgs.user_id
+ )
+"""
+ cursor = connection.cursor()
+ cursor.execute(sql, [PackageRelation.MAINTAINER])
+ to_fetch = [row[0] for row in cursor.fetchall()]
+ relations = PackageRelation.objects.select_related('user').filter(
+ id__in=to_fetch)
+ return relations
+
# vim: set ts=4 sw=4 et:
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: