From 5a68ee32fe6ec7a381a16245f85fde210500dfd7 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Thu, 27 May 2010 01:14:08 -0400 Subject: Adding channel support --- chishop/templates/djangopypi/pypi_show_links.html | 3 +- chishop/templates/djangopypi/show_channel.html | 7 ++++ djangopypi/admin.py | 10 ++++- djangopypi/models.py | 19 +++++++++ djangopypi/urls/__init__.py | 1 + djangopypi/urls/channel.py | 12 ++++++ djangopypi/views/channel.py | 48 +++++++++++++++++++++++ 7 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 chishop/templates/djangopypi/show_channel.html create mode 100644 djangopypi/urls/channel.py create mode 100644 djangopypi/views/channel.py diff --git a/chishop/templates/djangopypi/pypi_show_links.html b/chishop/templates/djangopypi/pypi_show_links.html index 6e46635..13fc2e5 100644 --- a/chishop/templates/djangopypi/pypi_show_links.html +++ b/chishop/templates/djangopypi/pypi_show_links.html @@ -8,7 +8,7 @@ {{ project.description|saferst }}
- +
FilenamePlatformTypeVersionUploaded OnSize
{% for release in releases %} @@ -18,6 +18,7 @@ + {% endfor %}
FilenamePlatformTypeVersionUploaded OnSizeChannel
{{ release.version }} {{ release.upload_time }} {{ release.distribution.size|filesizeformat }}{{ release.channel }}
diff --git a/chishop/templates/djangopypi/show_channel.html b/chishop/templates/djangopypi/show_channel.html new file mode 100644 index 0000000..86d312c --- /dev/null +++ b/chishop/templates/djangopypi/show_channel.html @@ -0,0 +1,7 @@ +Links for {{ channel.name }} +

Links for {{ channel.name }}

+ +{% for project in projects %} +{{ project.name }}
+{% endfor %} + diff --git a/djangopypi/admin.py b/djangopypi/admin.py index 6f994e8..663cc8e 100644 --- a/djangopypi/admin.py +++ b/djangopypi/admin.py @@ -1,6 +1,12 @@ from django.contrib import admin -from djangopypi.models import Project, Release, Classifier +from djangopypi.models import Project, Release, Classifier, Channel + + +class ReleaseAdmin(admin.ModelAdmin): + list_display = ['release_name', 'channel'] + admin.site.register(Project) -admin.site.register(Release) +admin.site.register(Channel) admin.site.register(Classifier) +admin.site.register(Release, ReleaseAdmin) diff --git a/djangopypi/models.py b/djangopypi/models.py index d98c4da..3539fb2 100644 --- a/djangopypi/models.py +++ b/djangopypi/models.py @@ -35,6 +35,22 @@ ARCHITECTURES = ( UPLOAD_TO = getattr(settings, "DJANGOPYPI_RELEASE_UPLOAD_TO", 'dist') + +class Channel(models.Model): + name = models.CharField(max_length=255, unique=True) + + class Meta: + verbose_name = _(u"channel") + verbose_name_plural = _(u"channels") + + def __unicode__(self): + return self.name + + @models.permalink + def get_absolute_url(self): + return ('djangopypi-channel_show_dists', (), {'channel': self.name}) + + class Classifier(models.Model): name = models.CharField(max_length=255, unique=True) @@ -82,6 +98,7 @@ class Project(models.Model): except Release.DoesNotExist: return None + class Release(models.Model): version = models.CharField(max_length=32) distribution = models.FileField(upload_to=UPLOAD_TO) @@ -92,6 +109,8 @@ class Release(models.Model): pyversion = models.CharField(max_length=32, blank=True) project = models.ForeignKey(Project, related_name="releases") upload_time = models.DateTimeField(auto_now=True) + channel = models.ForeignKey(Channel, related_name="channels", + blank=True, null=True) class Meta: verbose_name = _(u"release") diff --git a/djangopypi/urls/__init__.py b/djangopypi/urls/__init__.py index e362edc..50fd02b 100644 --- a/djangopypi/urls/__init__.py +++ b/djangopypi/urls/__init__.py @@ -3,6 +3,7 @@ from django.conf.urls.defaults import patterns, include urlpatterns = patterns('djangopypi.views', (r'^simple/', include('djangopypi.urls.simple')), + (r'^channel/', include('djangopypi.urls.channel')), (r'^$', 'simple', {'template_name': 'djangopypi/pypi.html'}, 'djangopypi-pypi'), diff --git a/djangopypi/urls/channel.py b/djangopypi/urls/channel.py new file mode 100644 index 0000000..2bb19a8 --- /dev/null +++ b/djangopypi/urls/channel.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from django.conf.urls.defaults import patterns + +urlpatterns = patterns('djangopypi.views.channel', + (r'^$', 'list_channels', {}, 'djangopypi-channel_simple'), + + (r'^(?P[\w\d_\.\-]+)/$', + 'show_channel', {}, 'djangopypi-channel_show_dists'), + + (r'^(?P[\w\d_\.\-]+)/(?P[\w\d_\.\-]+)/$', + 'show_links', {}, 'djangopypi-channel_show_links'), +) diff --git a/djangopypi/views/channel.py b/djangopypi/views/channel.py new file mode 100644 index 0000000..3dd7946 --- /dev/null +++ b/djangopypi/views/channel.py @@ -0,0 +1,48 @@ +from django.http import Http404 +from django.shortcuts import render_to_response +from django.template import RequestContext + +from djangopypi.models import Project, Release, Channel + + +def list_channels(request, template_name="djangopypi/simple.html"): + channels = Channel.objects.all().order_by("name") + context = RequestContext(request, { "dists": channels }) + return render_to_response(template_name, context_instance=context) + + +def show_links(request, channel, dist_name, + template_name="djangopypi/show_links.html"): + try: + project = Project.objects.get(name=dist_name) + releases = (Release.objects + .filter(project__name=dist_name, channel__name=channel) + .order_by('-version')) + except Project.DoesNotExist: + raise Http404 + + context = RequestContext(request, { + "dist_name": dist_name, + "releases": releases, + }) + + return render_to_response(template_name, context_instance=context) + + +def show_channel(request, channel, + template_name="djangopypi/show_channel.html"): + try: + projects = (Project.objects + .filter(releases__channel__name=channel) + .distinct().all().order_by('name')) + + channel = Channel.objects.get(name=channel) + except Project.DoesNotExist: + raise Http404 + + context = RequestContext(request, { + "projects": projects, + "channel": channel, + }) + + return render_to_response(template_name, context_instance=context) -- cgit v1.2.3