Skip to content

Commit

Permalink
new activity app; markdown; new editor #51
Browse files Browse the repository at this point in the history
  • Loading branch information
averrin committed Aug 19, 2013
1 parent a7313bb commit bfd7f0d
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 37 deletions.
Empty file added activity/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions activity/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
16 changes: 16 additions & 0 deletions activity/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""

from django.test import TestCase


class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
47 changes: 47 additions & 0 deletions activity/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Create your views here.

import os
import random
from django.conf import settings
from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.views.generic import TemplateView, View
from braces.views import LoginRequiredMixin, JSONResponseMixin, AjaxResponseMixin
import misaka as m


__all__ = (
'StreamView',
'ChatSendView'
)



class StreamView(LoginRequiredMixin, TemplateView):
template_name = 'activity/stream.html'

def get_context_data(self, **kwargs):
context = super(StreamView, self).get_context_data(**kwargs)
return context


class ChatSendView(LoginRequiredMixin, JSONResponseMixin, AjaxResponseMixin, View):
def post_ajax(self, request, *args, **kwargs):
import pusher

p = pusher.Pusher(
app_id=settings.PUSHER_APPID,
key=settings.PUSHER_KEY,
secret=settings.PUSHER_SECRET
)
p['activity'].trigger('my_event', {
'message': m.html(self.request.POST['message']),
'user': self.request.user.username,
'type': 'chat',
})
json_dict = {
"success": True
}
return self.render_json_response(json_dict)


1 change: 1 addition & 0 deletions emergent/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
'emergent',
'zen',
'rpg',
'activity',

)

Expand Down
5 changes: 2 additions & 3 deletions emergent/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.conf.urls import patterns, include, url
from views import IndexView, StatusView, ProfileView, MyProfileView, LoginView, UserListView, ChatView, ChatSendView
from views import IndexView, StatusView, ProfileView, MyProfileView, LoginView, UserListView

from django.contrib.auth import views as auth_views

Expand Down Expand Up @@ -28,8 +28,7 @@
url(r'^account/profile/$', MyProfileView.as_view(), name='me'),


url(r'^chat/$', ChatView.as_view(), name='chatlist'),
url(r'^chat/send$', ChatSendView.as_view(), name='chatsend'),
url(r'^activity/', include('activity.urls'), name='activity'),

)

Expand Down
27 changes: 0 additions & 27 deletions emergent/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,3 @@ def get_context_data(self, **kwargs):
context['users'] = get_user_model().objects.all()
return context

class ChatView(LoginRequiredMixin, TemplateView):
template_name = 'emergent/chat.html'

def get_context_data(self, **kwargs):
context = super(ChatView, self).get_context_data(**kwargs)
return context


class ChatSendView(LoginRequiredMixin, JSONResponseMixin, AjaxResponseMixin, View):
def post_ajax(self, request, *args, **kwargs):
import pusher

p = pusher.Pusher(
app_id=settings.PUSHER_APPID,
key=settings.PUSHER_KEY,
secret=settings.PUSHER_SECRET
)
p['test_channel'].trigger('my_event', {
'message': self.request.POST['message'],
'user': self.request.user.username
})
json_dict = {
"success": True
}
return self.render_json_response(json_dict)


4 changes: 4 additions & 0 deletions static/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
margin-top: 20px;
min-height: 400px;
}
#chat_send{
float: right;
margin-top: 6px;
}
4 changes: 2 additions & 2 deletions static/js/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(".level_info").tooltip({placement: "bottom", html: true})

var pusher = new Pusher('6bb5412badf09454aa87');
var channel = pusher.subscribe('test_channel');
var channel = pusher.subscribe('activity');
channel.bind('my_event', function(data) {
console.log(data)
var now = new Date().toLocaleTimeString();
Expand All @@ -11,7 +11,7 @@ var pusher = new Pusher('6bb5412badf09454aa87');

$("#msg_form").on("submit", function(e){
e.preventDefault();
$.post("/chat/send", {message:$('#msg_text').val()}, function(){})
$.post("/activity/send", {message:$('#msg_text').val()}, function(){})
$('#msg_text').val('')
return false;
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
{% load static %}

{% block page %}
<script type='text/javascript' src='http://js.pusher.com/2.1/pusher.min.js'></script>

<link rel="stylesheet" href="{% static 'chat.css' %}">


<h3>Websocket test:</h3>
<form id="msg_form">
{% csrf_token %}
<input id="msg_text"><input type="submit" value="Send"></input>
<div id="epiceditor"></div>
<input type="submit" value="Send" class="btn btn-default" id="chat_send"></input>
</form>
<div id="events"></div>

{% endblock page %}
6 changes: 5 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<li class="active"><a href="/">Home</a></li>
{% if user.is_authenticated %}
<li><a href="/status">Status</a></li>
<li><a href="/chat">Chat</a></li>
<li><a href="/activity">Activity</a></li>
<li><a href="/admin">Admin</a></li>
{% endif %}
</ul>
Expand Down Expand Up @@ -60,11 +60,15 @@
<script type="text/javascript" src='{% static 'jquery/jquery.js' %}'></script>
<script type="text/javascript" src='{% static 'bootstrap/dist/js/bootstrap.js' %}'></script>
<script type="text/javascript" src='{% static 'notify.js' %}'></script>
<script src="{% static 'epiceditor/js/epiceditor.min.js' %}"></script>
<script type='text/javascript' src='http://js.pusher.com/2.1/pusher.min.js'></script>

<script type="text/javascript" src='{% static 'js/init.js' %}'></script>
<script type="text/javascript" src='{% static 'js/rpg.js' %}'></script>
<script type="text/javascript" src='{% static 'js/main.js' %}'></script>

<script src="{% static 'js/activity.js' %}"></script>


<script>
$("#login_btn").on("click", function(){
Expand Down

0 comments on commit bfd7f0d

Please sign in to comment.