Modified:
trunk/app/favicon/helpers.py
trunk/app/favicon/views.py
trunk/app/index.yaml
trunk/app/templates/index.html
trunk/app/urls.py
Log:
ajax loading, should load everthing now
Modified: trunk/app/favicon/helpers.py
==============================================================================
--- trunk/app/favicon/helpers.py (original)
+++ trunk/app/favicon/helpers.py Mon May 19 01:37:58 2008
@@ -69,6 +69,10 @@
def most_recently_added(num):
return Favicon.all().filter('active = ', True).order('-created_at').fetch(num)
+def datetime_url(dt):
+ return "/api/%04d/%02d/%02d/%02d/%02d/%02d/%d/" % (dt.year,
dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond)
+
+
# hack to make key_name begin with a letter
def md5_key(md5):
return 'a' + md5
Modified: trunk/app/favicon/views.py
==============================================================================
--- trunk/app/favicon/views.py (original)
+++ trunk/app/favicon/views.py Mon May 19 01:37:58 2008
@@ -106,10 +106,7 @@
return shortcuts.render_to_response('top.html', params)
def index(request):
- favicons = Favicon.all().filter('active = ', True).fetch(1000)
- # \r hack because one of the keys has a \r in it -- probably should
figure out why
- a_keys = [ "\'" + f.key().id_or_name().replace('\r', ' ') + "\',"
for f in favicons ]
- params = {'favicons_recent':a_keys}
+ params = {}
params['favicon_cnt'] = get_total_favicons()
params['accesses_cnt'] = get_total_accesses()
params['favicon_today_cnt'] = get_today_favicons()
@@ -119,3 +116,19 @@
def update(request):
inc_today_updates()
return http.HttpResponseRedirect('/update/update.rdf')
+
+def api(request, year, month, day, hour, min, sec, micro):
+ params = {}
+ dt = datetime(int(year), int(month), int(day), int(hour), int(min),
int(sec), int(micro))
+ favicons = Favicon.all().filter('active = ',
True).filter('created_at > ', dt).order('created_at').fetch(1000)
+ if not favicons:
+ params['favicons'] = []
+ params['next_url'] = datetime_url(dt)
+ return shortcuts.render_to_response('api.html', params)
+
+ keys = [ f.key().id_or_name().replace('\r', ' ') for f in favicons ]
+ next_url = datetime_url(favicons[-1].created_at)
+
+ params['favicons'] = keys
+ params['next_url'] = next_url
+ return shortcuts.render_to_response('api.html', params)
Modified: trunk/app/index.yaml
==============================================================================
--- trunk/app/index.yaml (original)
+++ trunk/app/index.yaml Mon May 19 01:37:58 2008
@@ -35,6 +35,12 @@
- name: accesses
direction: desc
+# Used 424 times in query history.
+- kind: Favicon
+ properties:
+ - name: active
+ - name: created_at
+
# Unused in query history -- copied from input.
- kind: Favicon
properties:
Modified: trunk/app/templates/index.html
==============================================================================
--- trunk/app/templates/index.html (original)
+++ trunk/app/templates/index.html Mon May 19 01:37:58 2008
@@ -5,11 +5,35 @@
{% block content %}
<script type="text/javascript" charset="utf-8">
- var images = [
-{% for favicon in favicons_recent %}
- {{ favicon }}
-{% endfor %}
- ]
+var images = [];
+
+var url = "/api/2008/01/01/01/01/01/0/";
+
+function getImages() {
+ var the_object;
+ var http_request = new XMLHttpRequest();
+ http_request.open( "GET", url, true );
+ http_request.onreadystatechange = function () {
+ if ( http_request.readyState == 4 ) {
+ if ( http_request.status == 200 ) {
+ the_object = eval( "(" + http_request.responseText + ")" );
+ url = the_object.next_url;
+ images = images.concat(the_object.favicons);
+ loadImage();
+ loadImage(++i);
+ loadImage(++i);
+ loadImage(++i);
+ loadImage(++i);
+ } else {
+ }
+ http_request = null;
+ }
+ };
+ http_request.send(null);
+}
+
+getImages(url);
+window.setInterval(function(){ getImages(url); }, 1000 * 30);
var i = 0;
var j = 0;
@@ -43,23 +67,6 @@
loadImage(i);
}
}
-
-loadImage(i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
-loadImage(++i);
</script>
Modified: trunk/app/urls.py
==============================================================================
--- trunk/app/urls.py (original)
+++ trunk/app/urls.py Mon May 19 01:37:58 2008
@@ -10,7 +10,7 @@
(r'^toggler/', 'favicon.views.toggler'),
(r'^update/', 'favicon.views.update'),
(r'^top/', 'favicon.views.top_x'),
- (r'^api/latest/(?P<num>.+)', 'favicon.views.api_latest'),
+ (r'^api/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<hour>\d{2})/(?P<min>\d{2})/(?P<sec>\d{2})/(?P<micro>\d+)/', 'favicon.views.api'),
(r'^image/(?P<id>.+)', 'favicon.views.image'),
(r'^toggle/(?P<id>.+)', 'favicon.views.toggle_active'),
(r'^$', 'favicon.views.index')