diff options
author | Dusty Phillips <buchuki@gmail.com> | 2008-07-06 02:28:29 +0200 |
---|---|---|
committer | Dusty Phillips <buchuki@gmail.com> | 2008-07-06 02:55:58 +0200 |
commit | 91b3ddd47f15851cd1686adbf9181fc46b9730a3 (patch) | |
tree | 6106296094b5b2552700ea8c07e84f015ed45f4c | |
parent | b8221328c8de2dd2c673d4b0fd9a89d6d164d1d4 (diff) | |
download | archweb-91b3ddd47f15851cd1686adbf9181fc46b9730a3.tar.gz archweb-91b3ddd47f15851cd1686adbf9181fc46b9730a3.tar.xz |
#10213 make package urls be pretty cool, if not awesome
-rw-r--r-- | main/models.py | 3 | ||||
-rw-r--r-- | packages/views.py | 18 | ||||
-rw-r--r-- | templates/packages/details.html | 4 | ||||
-rw-r--r-- | urls.py | 5 |
4 files changed, 20 insertions, 10 deletions
diff --git a/main/models.py b/main/models.py index 12821f7..d4dee97 100644 --- a/main/models.py +++ b/main/models.py @@ -223,7 +223,8 @@ class Package(models.Model): _maintainername.short_description = 'Maintainer' def get_absolute_url(self): - return '/packages/%i/' % self.id + return '/packages/%s/%s/%s/' % (self.repo.name.lower(), + self.arch.name, self.pkgname) def get_requiredby(self): """ diff --git a/packages/views.py b/packages/views.py index 0fa781c..d971d7c 100644 --- a/packages/views.py +++ b/packages/views.py @@ -35,19 +35,25 @@ def update(request): pkg.save() return render_response(request, 'status_page.html', {'message':message}) -def details(request, pkgid=0, name='', repo=''): - if pkgid == 0: +def details(request, pkgid=0, name='', repo='', arch=''): + if pkgid != 0: + pkg = get_object_or_404(Package, id=pkgid) + elif all([name, repo, arch]): + pkg= get_object_or_404(Package, + pkgname=name, repo__name__iexact=repo, arch__name=arch) + else: p = Package.objects.filter(pkgname=name) if repo: p = p.filter(repo__name__iexact=repo) + lenp = p.count() # 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', + if lenp > 1: return search(request, name) + if lenp < 1: return render_response(request, 'error_page.html', {'errmsg': 'No matching packages.'}) - pkgid = p[0].id + pkg = p[0] - pkg = get_object_or_404(Package, id=pkgid) return render_response(request, 'packages/details.html', {'pkg': pkg}) + # @TODO: replace search form with a newform def search(request, query=''): if request.GET.has_key('q'): diff --git a/templates/packages/details.html b/templates/packages/details.html index c3b214e..b115de8 100644 --- a/templates/packages/details.html +++ b/templates/packages/details.html @@ -57,7 +57,7 @@ {% ifequal depend.pkg None %} <li>{{ depend.dep.depname }} (virtual)</li> {% else %} - <li><a href="/packages/{{ depend.pkg.id }}/">{{ depend.dep.depname }}</a>{{ depend.dep.depvcmp }}</li> + <li><a href="{{ depend.pkg.get_absolute_url }}">{{ depend.dep.depname }}</a>{{ depend.dep.depvcmp }}</li> {% endifequal %} {% endfor %} </ul> @@ -68,7 +68,7 @@ <h4>Required By:</h4> <ul style="font-size:small;list-style:none"> {% for req in pkg.get_requiredby %} - <li><a href="/packages/{{ req.id }}/">{{ req.pkgname }}{% ifequal req.repo.name "Testing" %} (testing){% endifequal %}{% ifequal req.repo.name "Unstable" %} (unstable){% endifequal %}</a></li> + <li><a href="{{req.get_absolute_url}}">{{ req.pkgname }}{% ifequal req.repo.name "Testing" %} (testing){% endifequal %}{% ifequal req.repo.name "Unstable" %} (unstable){% endifequal %}</a></li> {% endfor %} </ul> </div> @@ -14,7 +14,10 @@ urlpatterns = patterns('', (r'^packages/update/$', 'archweb_dev.packages.views.update'), (r'^packages/(?P<pkgid>\d+)/$', 'archweb_dev.packages.views.details'), (r'^packages/(?P<name>[A-z0-9]+)/$', 'archweb_dev.packages.views.details'), - (r'^packages/(?P<repo>[A-z0-9]+)/(?P<name>[A-z0-9]+)/$', 'archweb_dev.packages.views.details'), + (r'^packages/(?P<repo>[A-z0-9]+)/(?P<name>[A-z0-9]+)/$', + 'archweb_dev.packages.views.details'), + (r'^packages/(?P<repo>[A-z0-9]+)/(?P<arch>[A-z0-9]+)/(?P<name>[A-z0-9-]+)/$', + 'archweb_dev.packages.views.details'), (r'^packages/$', 'archweb_dev.packages.views.search'), (r'^todo/(\d+)/$', 'archweb_dev.todolists.views.view'), |