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)