Commits

boblefrag  committed ace0c6e

crud simple todo list

  • Participants
  • Parent commits 9531407

Comments (0)

Files changed (10)

File todo/public/media/templates/todo_list/task_confirm_delete.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+  <head>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <title>{{ site.name }}</title>
+
+  </head>
+  <body>
+  <form action="" method="Post">
+  <h1>Are you sure you want to delete this task ?</h1>
+  <input type="Submit" value="Delete">
+  </form>
+  </body>
+</html>

File todo/public/media/templates/todo_list/task_detail.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+  <head>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <title>{{ site.name }}</title>
+
+  <body>
+  <h1>{{object.title}}</h1>
+  <p>
+    {{object.content}}
+  </p>
+  <ul>
+  <li>created : {{object.creation_date}}</li>
+  <li>due before : {{objcet.due_date}}</li>
+  </ul>
+  <a href="delete">Delete ? </a>
+  <a href="update">Update ? </a>
+  <a href="/todo/">Listing</a>
+  
+  </body>
+</html>

File todo/public/media/templates/todo_list/task_form.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+  <head>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <title>{{ site.name }}</title>
+
+  </head>
+  <body>
+  <form action="" method="post">
+  {{form.as_p}}
+  <input type="Submit" value="submit">
+  </form>
+  </body>
+</html>

File todo/public/media/templates/todo_list/task_list.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+  <head>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <title>{{ site.name }}</title>
+  </head>
+  <body>
+  {%for object in object_list%}
+  <ul>
+	<li>{{object.title}}</li>
+	<li>{{object.due_date}}</li>
+	<a href="{{object.id}}/delete/">Delete</a>/<a href="{{object.id}}/update/">Update</a>/<a href="{{object.id}}/">Detail
+  </ul>
+  {%endfor%}
+  <a href="create">Create a new one</a>
+  </body>
+</html>

File todo/settings.py

 # Django settings for todo project.
-
+import os
+SETTINGS_DIR = os.path.abspath(os.path.dirname(__file__))
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
+#    'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
 )
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
+    os.path.join(SETTINGS_DIR,"public","media","templates")
 )
 
 INSTALLED_APPS = (
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.messages',
+    'todo_list'
     # Uncomment the next line to enable the admin:
     # 'django.contrib.admin',
 )

File todo/todo_list/models.py

+from django.db import models
+
+class task (models.Model):
+    title = models.CharField(max_length=200)
+    slug = models.SlugField()
+    content = models.TextField(blank=True)
+    creation_date = models.DateField(auto_now_add=True)
+    due_date = models.DateField()
+
+

File todo/todo_list/tests.py

+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these 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.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+

File todo/todo_list/urls.py

+from django.views.generic.list_detail import object_list, object_detail
+from django.views.generic.create_update import create_object, update_object, delete_object
+from django.conf.urls.defaults import *
+from django.contrib import admin
+from todo_list.models import task 
+admin.autodiscover()
+tasks_list_info = {
+    'queryset' : task.objects.all(),
+    }
+task_info = {
+    'model' : task,
+    'post_save_redirect' : '..'
+}
+task_delete={
+    'model' :task,
+        'post_delete_redirect' : '/todo/'
+}
+urlpatterns = patterns('',
+    (r'^/$', object_list,tasks_list_info),# the list of things to do
+    (r'^/create/$', create_object, task_info), # create a new task
+    (r'^/(?P<object_id>\d+)/$', object_detail, tasks_list_info),# a particular task
+
+    (r'^/(?P<object_id>\d+)/update/$', update_object, task_info),# modifying a task
+    (r'^/(?P<object_id>\d+)/delete/$', delete_object, task_delete),# delete a done task
+)

File todo/todo_list/views.py

+# Create your views here.

File todo/urls.py

-
 from django.conf.urls.defaults import *
 from django.contrib import admin
 admin.autodiscover()
 urlpatterns = patterns('',
+    (r'^todo',include('todo_list.urls')),
     (r'^admin/', include(admin.site.urls)),
 )