Commits

Brantley Harris committed ea16c58 Merge

Merged style changes.

  • Participants
  • Parent commits f7771b7, 85169c5

Comments (0)

Files changed (11)

 syntax: glob
+*.orig
 *.pyc
 *.pyo
 build

File migrations/001-view_most_required_packages.sql

 create or replace view view_most_required_packages as
     select  p.name,
             count(pr.id) as required_count
-    from    packages_packagerequirement pr
-            left join packages_package p on p.name=pr.required_package_id
+    from    packages_package p
+            left join packages_packagerequirement pr on
+                                (p.name=pr.required_package_id)
     where   p.supports_python_3 = 'f'
     group by p.name
-    order by count(pr.id) desc;
+    order by count(pr.id) desc, p.name;

File onpython3yet/home/views.py

 def index(request):
     req = MostRequiredPackages.objects.all()
     total = Package.objects.all().count()
+    offset = 20
     return render_to_response('home/index.html',
                               {'dependend_on_total': req.count(),
                                'total': total,
-                               'most_depended_on': req[0:20]},
+                               'most_depended_on': req[0:offset],
+                               'offset': offset},
                               context_instance=RequestContext(request))

File onpython3yet/media/js/site.js

         });
     });
 
+    $("#show-more-packages").click(function(e) {
+        e.preventDefault();
+        var results = $("#depended-on-packages"),
+            start = parseInt(results.attr('data-offset'), 10),
+            url = results.attr('data-url'),
+            offset = start + 20;
+        $.ajax({
+            url: url,
+            type: 'GET',
+            dataType: 'json',
+            data: {start: start, offset: offset},
+            success: function(data, textStatus, xhr) {
+                results.attr('data-offset', offset);
+                $.each(data.packages, function(i, pkg) {
+                    var name = site.escapeHtml(pkg.name);
+                    var h = '<li><a href="' + pkg.show_pkg_url + '"' +
+                            ' title="' + name + ', ' + pkg.required_count +
+                            ' dependents">' + name + '</a></li>';
+                    results.append($(h));
+                });
+            },
+            error: site.onAjaxError
+        });
+    });
+
 });
 
 site.escapeHtml = function(s) {

File onpython3yet/packages/tests/test_models.py

 
         # now baz should not show up anymore:
         pkg_by_count = [o.name for o in MostRequiredPackages.objects.all()]
-        self.assertEqual(pkg_by_count, ['bar'])
+        self.assertEqual(pkg_by_count, [u'bar', u'foo', u'fred'])

File onpython3yet/packages/tests/test_views.py

         eq_(data['name'], 'somecrazypkg')
         eq_(data['found_pkg'], True)
         eq_(data['supports_python_3'], True)
+
+
+class TestDependedOn(DjangoTestCase):
+
+    def setUp(self):
+        Package.objects.create(name='aaz', supports_python_3=False)
+        Package.objects.create(name='baz', supports_python_3=False)
+        Package.objects.create(name='caz', supports_python_3=False)
+        Package.objects.create(name='daz', supports_python_3=False)
+    
+    def get(self, *args, **kw):
+        r = self.client.get(reverse('packages.depended_on'), *args, **kw)
+        eq_(r.status_code, 200)
+        return simplejson.loads(r.content)
+
+    def tearDown(self):
+        teardown_data()
+
+    def test_pkg(self):
+        data = self.get()
+        p = data['packages'][0]
+        eq_(p['name'], 'aaz')
+        eq_(p['show_pkg_url'], reverse('packages.show', args=[p['name']]))
+        eq_(p['required_count'], 0)
+
+    def test_slicing(self):
+        data = self.get({'start': 0, 'offset': 2})
+        eq_([p['name'] for p in data['packages']],
+            ['aaz', 'baz'])
+        data = self.get({'start': 1, 'offset': 2})
+        eq_([p['name'] for p in data['packages']],
+            ['baz', 'caz'])

File onpython3yet/packages/urls.py

 urlpatterns = patterns('packages.views',
     url(r'^fetch/(?P<package_name>[^/]+)$', 'fetch', name="packages.fetch"),
     url(r'^show/(?P<package_name>[^/]+)$', 'show', name="packages.show"),
+    url(r'^depended_on$', 'depended_on', name="packages.depended_on"),
     url(r'^query$', 'query', name="packages.query"),
     url(r'^requirements$', 'requirements',
         name="packages.requirements"),

File onpython3yet/packages/views.py

 from django.template import loader, RequestContext
 import simplejson
 
-from packages.models import Package, PackageRequirement
+from packages.models import Package, PackageRequirement, MostRequiredPackages
 from packages import requirelib
 from onpython3yet.utils import as_json
 
     return result
 
 
+def _json_package(pkg):
+    return {
+        'name': pkg.name,
+        'show_pkg_url': reverse('packages.show', args=[pkg.name]),
+        'required_count': pkg.required_count
+    }
+
+
+@as_json
+def depended_on(request):
+    default_start = 0
+    default_offset = 20
+    try:
+        start = int(request.GET.get('start', default_start))
+        offset = int(request.GET.get('offset', default_offset))
+    except ValueError:
+        start = default_start
+        offset = default_offset
+    qs = MostRequiredPackages.objects.all()
+    return {
+        'packages': [_json_package(p) for p in qs[start:start+offset]]
+    }
+
+
 def show(request, package_name):
     query = Package.objects.filter(name=package_name)
     if query.count():

File onpython3yet/templates/base.html

         {% block extrastyle %}{% endblock %}
         {% block extrahead %}{% endblock %}
         <title>On Python 3 Yet?</title>
+
+        <script type="text/javascript" src="{{ MEDIA_URL }}/js/jquery-1.4.4.min.js"></script>
+        <script type="text/javascript" src="{{ MEDIA_URL }}/js/site.js"></script>
         
         <link rel="stylesheet" href="css/base.css" type="text/css" title="no title" charset="utf-8">
     </head>

File onpython3yet/templates/home/index.html

 {% block content %}	    
     <h2>2.x Packages Most Depended On</h2>
     <div class="info">{{ dependend_on_total }} packages out of {{ total }}</div>
+    <div id="package-list" offset="{{ offset }}" href="{% url packages.depended_on %}">
     {% for pkg in most_depended_on %}
         {% include "pkg_link.html" %}
     {% endfor %}
+    </div>
 {% endblock %}

File onpython3yet/templates/packages/requirements.html

 {% extends 'base.html' %}
 
-{% block extrahead %}
-<script type="text/javascript" src="{{ MEDIA_URL }}/js/jquery-1.4.4.min.js"></script>
-<script type="text/javascript" src="{{ MEDIA_URL }}/js/site.js"></script>
-{% endblock %}
-
 {% block content %}
 
     <div id="requirements-results"