Skip to content

Commit

Permalink
timestamps issue #51
Browse files Browse the repository at this point in the history
  • Loading branch information
averrin committed Aug 19, 2013
1 parent 00af33e commit bb09c18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
5 changes: 3 additions & 2 deletions activity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_ajax(self, request, *args, **kwargs):
'message': m.html(event.message),
'user': event.user.username,
'type': event.type,
'timestamp': event.timestamp
'timestamp': event.timestamp.isoformat()
})
return self.render_json_response(json_dict)

Expand All @@ -48,8 +48,9 @@ def post_ajax(self, request, *args, **kwargs):
'message': m.html(self.request.POST['message']),
'user': self.request.user.username,
'type': 'chat',
'timestamp': datetime.now().isoformat()
}
Event(timestamp=datetime.now(), user=self.request.user, type='chat', message=msg['message']).save()
Event(timestamp=msg['timestamp'], user=self.request.user, type='chat', message=msg['message']).save()
Pusher.send("activity", 'my_event', msg)
json_dict = {
"success": True
Expand Down
32 changes: 11 additions & 21 deletions static/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,24 @@ function chat_send(editor){

$(function(){

var chat_message = _.template(
var templates = {
chat: _.template(
"<div class='chat_message'>" +
"<strong><a href='/users/<%= user %>'><%= user %></a></strong> (<%= now %>): <br>" +
"<strong><a href='/users/<%= user %>'><%= user %></a></strong> (<%= now.toLocaleDateString() %> <%= now.toLocaleTimeString() %>): <br>" +
" <%= message %>" +
"</div>"
);
var rpg_message = _.template(
),
rpg: _.template(
"<div class='rpg_message'>" +
" <%= message %>" +
"</div>"
);
)
}

function ws_handler(data) {
console.log(data);
data.now = new Date().toLocaleTimeString();
var template;
if(data.type == "chat"){
template = chat_message;
}else if(data.type == "rpg"){
template = rpg_message;
}
$("#events").append(template(data));
data.now = new Date(data.timestamp);
$("#events").append(templates[data.type](data));
}

websocket_init(ws_handler);
Expand Down Expand Up @@ -56,14 +52,8 @@ $(function(){
$.get("/activity/history", function(data){
console.log(data);
_.each(data.history, function(e,i){
e.now = new Date().toLocaleTimeString();
var template;
if(e.type == "chat"){
template = chat_message;
}else if(e.type == "rpg"){
template = rpg_message;
}
$("#events").append(template(e));
e.now = new Date(e.timestamp);
$("#events").append(templates[e.type](e));
})

})
Expand Down

0 comments on commit bb09c18

Please sign in to comment.