diff --git a/templates/zephyr/index.html b/templates/zephyr/index.html
index a5ac5e3859..a10a9448ec 100644
--- a/templates/zephyr/index.html
+++ b/templates/zephyr/index.html
@@ -8,29 +8,15 @@
+
-{% for zephyr in zephyrs %}
-
-{% if user_profile.pointer == zephyr.id %} ▶{% else %} {% endif %} |
-
-
-
-{% if zephyr.recipient.type == 'class' %}
-{{ zephyr.display_recipient }}
-{{ zephyr.instance }}
-{% else %}
-{{ zephyr.display_recipient }}
-←
-{% endif %}
-
-{{ zephyr.sender.user.username }}
-{{ zephyr.content|linebreaksbr }}
- |
-
-{% endfor %}
+▶ | dummy row, FIXME |
+{# Zephyrs go here #}
diff --git a/zephyr/models.py b/zephyr/models.py
index a6c13d06ce..315cbf0d04 100644
--- a/zephyr/models.py
+++ b/zephyr/models.py
@@ -76,6 +76,14 @@ class Zephyr(models.Model):
display_recipient = get_display_recipient(self.recipient)
return "" % (display_recipient, self.instance, self.sender)
+ def to_dict(self):
+ return {'id' : self.id,
+ 'sender' : self.sender.user.username,
+ 'type' : self.recipient.type,
+ 'display_recipient': get_display_recipient(self.recipient),
+ 'instance' : self.instance,
+ 'content' : self.content }
+
def send_zephyr(**kwargs):
zephyr = kwargs["instance"]
if zephyr.recipient.type == "personal":
diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js
index b195359068..e8c0c2b345 100644
--- a/zephyr/static/js/zephyr.js
+++ b/zephyr/static/js/zephyr.js
@@ -257,6 +257,10 @@ function add_message(index, zephyr) {
$("#table tr:last").after(new_str);
}
+$(function() {
+ $(initial_zephyr_json).each(add_message);
+});
+
function get_updates_longpoll(data) {
if (data && data.zephyrs) {
$.each(data.zephyrs, add_message);
diff --git a/zephyr/views.py b/zephyr/views.py
index 9871dcc7e9..5ff25fae32 100644
--- a/zephyr/views.py
+++ b/zephyr/views.py
@@ -8,7 +8,8 @@ from django.shortcuts import render
from django.utils.timezone import utc
from django.contrib.auth.models import User
-from zephyr.models import Zephyr, UserProfile, ZephyrClass, Recipient, get_display_recipient, filter_by_subscriptions
+from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
+ Recipient, filter_by_subscriptions
from zephyr.forms import RegistrationForm
import tornado.web
@@ -44,15 +45,16 @@ def home(request):
return HttpResponseRedirect('accounts/home/')
zephyrs = filter_by_subscriptions(Zephyr.objects.all(), request.user)
- for zephyr in zephyrs:
- zephyr.display_recipient = get_display_recipient(zephyr.recipient)
user = request.user
user_profile = UserProfile.objects.get(user=user)
if user_profile.pointer == -1 and zephyrs:
user_profile.pointer = min([zephyr.id for zephyr in zephyrs])
user_profile.save()
- return render_to_response('zephyr/index.html', {'zephyrs': zephyrs, 'user_profile': user_profile},
+ zephyr_json = simplejson.dumps([zephyr.to_dict() for zephyr in zephyrs])
+ return render_to_response('zephyr/index.html',
+ {'zephyr_json' : zephyr_json,
+ 'user_profile': user_profile },
context_instance=RequestContext(request))
def update(request):
@@ -83,17 +85,8 @@ def get_updates_longpoll(request, handler):
def on_receive(zephyrs):
if handler.request.connection.stream.closed():
return
- new_zephyr_list = []
- for zephyr in zephyrs:
- new_zephyr_list.append({"id": zephyr.id,
- "sender": zephyr.sender.user.username,
- "display_recipient": get_display_recipient(zephyr.recipient),
- "type": zephyr.recipient.type,
- "instance": zephyr.instance,
- "content": zephyr.content
- })
try:
- handler.finish({'zephyrs': new_zephyr_list})
+ handler.finish({'zephyrs': [zephyr.to_dict() for zephyr in zephyrs]})
except socket.error, e:
pass