Commits

Yann Malet committed c7def91

Wrote a minimal todo django app

  • Participants
  • Parent commits 8d2dfd7

Comments (0)

Files changed (11)

 package main
 
 import (
+	"io"
 	"log"
 	"net/http"
 	"net/http/httputil"
 	"net/url"
+	"code.google.com/p/go.net/websocket"
 )
 
 const (
 	STATIC_URL string = "/static"
 )
 
+func EchoServer(ws *websocket.Conn) {
+    log.Println("got something")
+    io.Copy(ws, ws)
+}
+
 func main() {
 	log.Println("start bereal go server")
 	dstUrl, err := url.Parse("http://127.0.0.1:8000")
 	  log.Fatal(err)
 	}
 
+	http.Handle("/ws", websocket.Handler(EchoServer))
 	http.Handle(STATIC_URL, http.FileServer(http.Dir(STATIC_ROOT)))
 	reverse_proxy := httputil.NewSingleHostReverseProxy(dstUrl)
 	http.Handle("/", reverse_proxy)

bereal/apps/todos/__init__.py

Empty file added.

bereal/apps/todos/admin.py

+from django.contrib import admin
+from .models import Collection, Item
+
+
+class ItemInline(admin.TabularInline):
+    model = Item
+
+
+class CollectionAdmin(admin.ModelAdmin):
+    inlines = [ItemInline]
+
+admin.site.register(Collection, CollectionAdmin)

bereal/apps/todos/models.py

+from django.db import models
+
+
+class Collection(models.Model):
+    name = models.CharField(max_length=255)
+    user = models.ForeignKey("auth.User")
+
+    def __unicode__(self):
+        return u"{0} for {1}".format(self.name, self.user)
+
+class Item(models.Model):
+    parent = models.ForeignKey(Collection)
+    name = models.CharField(max_length=255)
+    is_done = models.BooleanField(default=False)
+
+    def __unicode__(self):
+        return self.name

bereal/apps/todos/tests.py

+"""
+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)

bereal/apps/todos/urls.py

+from django.conf.urls.defaults import patterns, url, include
+
+from .views import index, my_collections
+
+urlpatterns = patterns('',
+    url(r'^$', index, name="todos_index"),
+    url(r'^todos/$', my_collections, name="todos_mycollections"),
+)
+

bereal/apps/todos/views.py

+from django.shortcuts import render
+from django.contrib.auth.decorators import login_required
+
+from .models import Collection
+
+def index(request):
+    return render(request, "todos/index.html", {})
+
+@login_required
+def my_collections(request):
+    mycollections = Collection.objects.filter(user=request.user)
+    return render(request, "todos/my_collections.html", {"mycollections": mycollections})
+

bereal/settings/base.py

 SECRET_KEY = 'ynlea(lti9gf+n@=w8jc&^0b4b%&v%@7mam)_qg!e8)61ow641'
 
 INSTALLED_APPS = (
-    # 'bereal.apps.',
+    'bereal.apps.core',
+    'bereal.apps.todos',
 
     #'south',
 

bereal/templates/todos/index.html

+{% block content %}
+    <h1>Todos</h1>
+    <a href="{% url todos_mycollections %}">My todo lists</a>
+{% endblock %}

bereal/templates/todos/my_collections.html

+{% block content %}
+{% for collection in mycollections %}
+    <h2>{{ collection.name }}</h2>
+    <ul>
+        {% for item in collection.item_set.all %}
+        <li>{{ item.name }} </li>
+        {% endfor %}
+    </ul>
+{% endfor %}
+{% endblock %}
+
 
 urlpatterns = patterns('',
     (r'', include('bereal.apps.core.urls')),
+    (r'', include('bereal.apps.todos.urls')),
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),
     (r'^admin/', include(admin.site.urls)),
 )