summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--devel/views.py29
-rw-r--r--main/models.py100
-rw-r--r--packages/views.py15
-rwxr-xr-xscripts/reporead.py15
-rw-r--r--templates/devel/index.html4
-rw-r--r--todolists/views.py1
6 files changed, 78 insertions, 86 deletions
diff --git a/devel/views.py b/devel/views.py
index cbeaf156..539309b4 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -4,6 +4,7 @@ from django.contrib.auth.models import User
from django.core import validators
from archweb_dev.main.utils import render_response, validate
from archweb_dev.main.models import Package, Todolist, TodolistPkg
+from archweb_dev.main.models import Arch, Repo
from archweb_dev.main.models import UserProfile, News, Donor, Mirror
from django.http import HttpResponse
from django.template import Context, loader
@@ -30,26 +31,22 @@ def index(request):
pkgs = None
arch_stats = []
- for arch_name in Package.ARCHES:
- arch = Package.ARCHES[arch_name]
+ for xarch in Arch.objects.all():
arch_stats.append({
- 'name': arch_name,
- 'count': Package.objects.filter(arch__exact = arch).count(),
- 'flagged': Package.objects.filter(
- arch__exact = arch).filter(needupdate=True).count(),
- 'flagnotest': Package.objects.filter(
- arch__exact = arch).filter(needupdate=True).exclude(
- repo=Package.REPOS['testing']).count()
+ 'name': xarch.name,
+ 'count': Package.objects.filter(arch=xarch).count(),
+ 'flagged': Package.objects.filter(arch=xarch).filter(
+ needupdate=True).exclude(
+ repo__name__iexact='testing').count()
})
repo_stats = []
- for repo_name in Package.REPOS:
- repo = Package.REPOS[repo_name]
+ for xrepo in Repo.objects.all():
repo_stats.append({
- 'name': repo_name,
- 'count': Package.objects.filter(repo__exact = repo).count(),
+ 'name': xrepo.name,
+ 'count': Package.objects.filter(repo=xrepo).count(),
'flagged': Package.objects.filter(
- repo__exact = repo).filter(needupdate=True).count()
+ repo=xrepo).filter(needupdate=True).count()
})
return render_response(
@@ -99,8 +96,8 @@ def guide(request):
def siteindex(request):
# get the most recent 10 news items
news = News.objects.order_by('-postdate', '-id')[:10]
- pkgs = Package.objects.exclude(repo = Package.REPOS.testing).order_by('-last_update')[:15]
- repos = Package.REPOS
+ pkgs = Package.objects.exclude(repo__name__iexact='testing').order_by('-last_update')[:15]
+ repos = Repo.objects.all()
return render_response(
request, 'devel/siteindex.html',
{'news_updates': news, 'pkg_updates': pkgs, 'repos': repos})
diff --git a/main/models.py b/main/models.py
index a1314f8b..e54fa502 100644
--- a/main/models.py
+++ b/main/models.py
@@ -4,34 +4,6 @@ from django.contrib.auth.models import User
import re
###########################
-### Model help classes ###
-###########################
-class Container(dict):
- def __init__(self, dict_entries=None, **entries):
- if dict_entries:
- self.update(dict_entries)
- if entries:
- self.update(entries)
-
- def __iter__(self):
- rev_items = [(v, k) for k, v in self.items()]
- rev_items.sort()
- items = [k for v, k in rev_items]
- return items.__iter__()
-
- def itertransp(self):
- rev_items = [(v, k) for k, v in self.items()]
- rev_items.sort()
- return rev_items.__iter__()
-
- def __getattr__(self,name):
- return self[name]
-
- def __setattr__(self,name,val):
- self[name] = val
-
-
-###########################
### User Profile Class ####
###########################
class UserProfile(models.Model):
@@ -49,7 +21,11 @@ class UserProfile(models.Model):
roles = models.CharField(maxlength=255, null=True, blank=True)
favorite_distros = models.CharField(maxlength=255, null=True, blank=True)
picture = models.FileField(upload_to='devs', default='devs/silhouette.png')
- user = models.ForeignKey(User, related_name='userprofile_user', edit_inline=models.STACKED, num_in_admin=1, min_num_in_admin=1, max_num_in_admin=1, num_extra_on_change=0, unique=True)
+ user = models.ForeignKey(
+ User, related_name='userprofile_user',
+ edit_inline=models.STACKED, num_in_admin=1,
+ min_num_in_admin=1, max_num_in_admin=1,
+ num_extra_on_change=0, unique=True)
class Meta:
db_table = 'user_profiles'
verbose_name = 'Additional Profile Data'
@@ -63,7 +39,8 @@ class TodolistManager(models.Manager):
def get_incomplete(self):
results = []
for l in self.all().order_by('-date_added'):
- if TodolistPkg.objects.filter(list=l.id).filter(complete=False).count() > 0:
+ if TodolistPkg.objects.filter(list=l.id).filter(
+ complete=False).count() > 0:
results.append(l)
return results
@@ -72,21 +49,18 @@ class PackageManager(models.Manager):
results = []
# first the orphans
noflag = self.filter(maintainer=0).count()
- flagged = self.filter(maintainer=0).filter(needupdate=True).count()
- flagnotest = self.filter(maintainer=0).filter(
- needupdate=True).exclude(
- repo=Package.REPOS['testing']).count()
+ flagged = self.filter(maintainer=0).filter(
+ needupdate=True).exclude(
+ repo__name__iexact='testing').count()
results.append(
- (User(id=0,first_name='Orphans'), noflag, flagged, flagnotest))
+ (User(id=0,first_name='Orphans'), noflag, flagged))
# now the rest
for maint in User.objects.all().order_by('first_name'):
noflag = self.filter(maintainer=maint.id).count()
flagged = self.filter(maintainer=maint.id).filter(
- needupdate=True).count()
- flagnotest = self.filter(maintainer=maint.id).filter(
needupdate=True).exclude(
- repo=Package.REPOS['testing']).count()
- results.append((maint, noflag, flagged, flagnotest))
+ repo__name__iexact='testing').count()
+ results.append((maint, noflag, flagged))
return results
@@ -160,6 +134,8 @@ class News(models.Model):
postdate = models.DateField(auto_now_add=True)
title = models.CharField(maxlength=255)
content = models.TextField()
+ def __str__(self):
+ return self.title
class Meta:
db_table = 'news'
verbose_name_plural = 'news'
@@ -169,19 +145,34 @@ class News(models.Model):
def get_absolute_url(self):
return '/news/%i/' % self.id
-class Package(models.Model):
- ## note: purposefully inlining arch and repo.
- ## they don't change very often (rarely), and it should help compact
- ## the general model
- # architectures
- ARCHES = Container(any=1, i686=2, x86_64=3)
- # repositories
- REPOS = Container(core=1, extra=2, testing=3, unstable=4)
+class Arch(models.Model):
+ id = models.AutoField(primary_key=True)
+ name = models.CharField(maxlength=255,unique=True)
+ def __str__(self):
+ return self.name
+ class Meta:
+ db_table = 'arches'
+ ordering = ['name']
+ verbose_name_plural = 'arches'
+ class Admin:
+ pass
+
+class Repo(models.Model):
+ id = models.AutoField(primary_key=True)
+ name = models.CharField(maxlength=255,unique=True)
+ def __str__(self):
+ return self.name
+ class Meta:
+ db_table = 'repos'
+ ordering = ['name']
+ verbose_name_plural = 'repos'
+ class Admin:
+ pass
+class Package(models.Model):
id = models.AutoField(primary_key=True)
- ## note: the arch and repo elements might need to be indexed. not sure.
- repo = models.IntegerField(choices=REPOS.itertransp())
- arch = models.IntegerField(choices=ARCHES.itertransp())
+ repo = models.ForeignKey(Repo)
+ arch = models.ForeignKey(Arch)
maintainer = models.ForeignKey(User, related_name='package_maintainer')
needupdate = models.BooleanField(default=False)
pkgname = models.CharField(maxlength=255)
@@ -195,6 +186,9 @@ class Package(models.Model):
db_table = 'packages'
get_latest_by = 'last_update'
+ def __str__(self):
+ return self.pkgname
+
def get_absolute_url(self):
return '/packages/%i/' % self.id
@@ -213,7 +207,7 @@ class Package(models.Model):
try:
# we only need depend on same-arch-packages
p = Package.objects.get(
- Q(arch=Package.ARCHES['any']) | Q(arch=self.arch),
+ Q(arch__name__iexact='any') | Q(arch=self.arch),
pkgname=dep.depname)
except Package.DoesNotExist, IndexError:
# couldn't find a package in the DB
@@ -247,6 +241,8 @@ class Todolist(models.Model):
description = models.TextField()
date_added = models.DateField(auto_now_add=True)
objects = TodolistManager()
+ def __str__(self):
+ return self.name
class Meta:
db_table = 'todolists'
@@ -270,7 +266,7 @@ class Wikipage(models.Model):
def editurl(self):
return "/wiki/edit/" + self.title + "/"
- def __repr__(self):
+ def __str__(self):
return self.title
# vim: set ts=4 sw=4 et:
diff --git a/packages/views.py b/packages/views.py
index 867bf0fb..fc19e444 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -8,6 +8,7 @@ from django.contrib.auth.models import User
from datetime import datetime
from archweb_dev.main.utils import validate, render_response
from archweb_dev.main.models import Package, PackageFile, PackageDepend
+from archweb_dev.main.models import Arch, Repo
from django.core.exceptions import ObjectDoesNotExist
@@ -37,7 +38,7 @@ def update(request):
def details(request, pkgid=0, name='', repo=''):
if pkgid == 0:
p = Package.objects.filter(pkgname=name)
- if repo: p = p.filter(repo=Package.REPOS[repo])
+ if repo: p = p.filter(repo__name__iexact=repo)
# if more then one result, send to the search view
if len(p) > 1: return search(request, name)
if len(p) < 1: return render_response(request, 'error_page.html',
@@ -63,8 +64,8 @@ def search(request, query=''):
flagged_only = request.GET.get('flagged_only', 'n')
# build the form lists
- repos = Package.REPOS
- arches = Package.ARCHES
+ repos = Repo.objects.all()
+ arches = Arch.objects.all()
# copy GET data over and add the lists
c = request.GET.copy()
c['repos'], c['arches'] = repos, arches
@@ -89,10 +90,10 @@ def search(request, query=''):
results = res1 | res2
else:
results = Package.objects.all()
- if repo != 'all' and repo in Package.REPOS:
- results = results.filter(repo=Package.REPOS[repo])
- if arch != 'all' and arch in Package.ARCHES:
- results = results.filter(arch=Package.ARCHES[arch])
+ if repo != 'all' and repo in [x.name for x in repos]:
+ results = results.filter(repo__name__iexact=repo)
+ if arch != 'all' and arch in [x.name for x in arches]:
+ results = results.filter(arch__name__iexact=arch)
if maint != 'all':
results = results.filter(maintainer=maint)
if flagged_only != 'n':
diff --git a/scripts/reporead.py b/scripts/reporead.py
index 525cb1ef..68c77ebe 100755
--- a/scripts/reporead.py
+++ b/scripts/reporead.py
@@ -48,7 +48,7 @@ setup_environ(settings)
from pprint import pprint as pp
from cStringIO import StringIO
from logging import CRITICAL,ERROR,WARNING,INFO,DEBUG
-from main.models import Package, PackageFile, PackageDepend
+from main.models import Arch, Package, PackageFile, PackageDepend, Repo
###
### Initialization
@@ -148,8 +148,8 @@ def db_update(archname, pkgs):
"""
logger.info('Updating Arch: %s' % archname)
- repository = Package.REPOS[pkgs[0].repo.lower()]
- architecture = Package.ARCHES[archname.lower()]
+ repository = Repo.objects.get(name__iexact=pkgs[0].repo)
+ architecture = Arch.objects.get(name__iexact=archname)
dbpkgs = Package.objects.filter(arch=architecture, repo=repository)
now = datetime.now()
@@ -310,7 +310,8 @@ def main(argv=None):
usage()
return 0
# check if arch is valid
- if argv[1] not in Package.ARCHES:
+ available_arches = Arch.objects.all()
+ if argv[1] not in [x.name for x in available_arches]:
usage()
return 0
else:
@@ -321,11 +322,11 @@ def main(argv=None):
# sort packages by arch -- to handle noarch stuff
packages_arches = {}
- for arch in Package.ARCHES:
- packages_arches[arch] = []
+ for arch in available_arches:
+ packages_arches[arch.name] = []
for package in packages:
- if package.arch not in Package.ARCHES:
+ if package.arch not in [x.name for x in available_arches]:
logger.warning("Package %s has missing or invalid arch" % (package.name))
package.arch = primary_arch
packages_arches[package.arch].append(package)
diff --git a/templates/devel/index.html b/templates/devel/index.html
index d993e3b8..91055376 100644
--- a/templates/devel/index.html
+++ b/templates/devel/index.html
@@ -29,14 +29,12 @@
<th width="50%">Arch</th>
<th># Packages</th>
<th># Flagged</th>
- <th># Flagnotest</th>
</tr>
{% for arch in arches %}
<tr class="{% cycle pkgr2,pkgr1 %}">
<td><strong>{{ arch.name }}</strong></td>
<td><a href="/packages/?arch={{ arch.name }}"><strong>{{ arch.count }}</strong> packages</a></td>
<td><a href="/packages/?arch={{ arch.name }}&flagged_only=y"><strong>{{ arch.flagged }}</strong> packages</a></td>
- <td><a href="/packages/?arch={{ arch.name }}&flagged_only=y"><strong>{{ arch.flagnotest }}</strong> packages</a></td>
</tr>
{% endfor %}
</table>
@@ -68,14 +66,12 @@
<th width="50%">Maintainer</th>
<th># Packages</th>
<th># Flagged</th>
- <th># Flagnotest</th>
</tr>
{% for maint in stats %}
<tr class="{% cycle pkgr2,pkgr1 %}">
<td><strong>{{ maint.0.get_full_name }}</strong></td>
<td><a href="/packages/?maint={{ maint.0.id }}"><strong>{{ maint.1 }}</strong> packages</a></td>
<td><a href="/packages/?maint={{ maint.0.id }}&flagged_only=y"><strong>{{ maint.2 }}</strong> packages</a></td>
- <td><a href="/packages/?maint={{ maint.0.id }}&flagged_only=y"><strong>{{ maint.3 }}</strong> packages</a></td>
</tr>
{% endfor %}
</table>
diff --git a/todolists/views.py b/todolists/views.py
index 9a4fdb95..fe8b1d42 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from archweb_dev.main.utils import render_response
from archweb_dev.main.models import Todolist, TodolistPkg, Package
+from archweb_dev.main.models import Arch, Repo
# FIXME: ugly hackery. http://code.djangoproject.com/ticket/3450
import django.db