Commits

Scott Nixon committed 1a1b4d8

Beginnings of views and models.

  • Participants
  • Parent commits c83627c

Comments (0)

Files changed (4)

 lib
 include
 .Python
+.DS_Store
+Courses.kpf
 from django.db import models
+from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
+from django.contrib.sites.managers import CurrentSiteManager
 
-# Create your models here.
+class Courses(models.Model):
+    title = models.charfield(max_length=100,unique=True)
+    slug = models.SlugField('Course URL', max_length=50,unique=True)
+    createdate = models.DateTimeField(auto_now_add=True,null=True)
+    updatedate = models.DateTimeField(auto_now=True)
+    is_published = models.BooleanField(
+		"Published", default=False, help_text="Publish this Course?"
+	)
+    sites = models.ManyToManyField(Site)
+    
+    @models.permalink
+    def get_absolute_url(self):
+	return ('courses.views.course_detail', None, { 'slug': self.slug })
+    def __unicode__(self):
+	return self.title
+    
+class Lessons(models.Model):
+    title = models.Charfield(max_length=150,unique=True)
+    content = models.TextField()
+    slug = models.SlugField('Lesson URL', max_length=50,unique=True)
+    createdate = models.DateTimeField(auto_now_add=True,null=True)
+    updatedate = models.DateTimeField(auto_now=True)
+    is_published = models.BooleanField(
+		"Published", default=False, help_text="Publish this Lesson?"
+	)
+    @models.permalink
+    def get_absolute_url(self):
+            return ('courses.views.lesson_detail', None, { 'slug': self.slug })
+            
+    def __unicode__(self):
+            return self.title
+
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('courses.views',
+	url(r'^courses/$', view='course_index', name='course_index'),
+	url(r'^course/(?P<slug>.*)/$', view='course_detail', name='course_detail'),
+	url(r'^lesson/(?P<slug>.*)/$', view='lesson_detail', name='lesson_detail'),
+)
-# Create your views here.
+from django.shortcuts import render_to_response
+from models import Courses, Lessons
+
+def course_index(request):
+    try:
+            c = Courses.active.all()
+    except Courses.DoesNotExist:
+            raise Http404
+    return render_to_response('courses/course_index.html', locals(),context_instance=RequestContext(request))
+
+def course_detail(request, slug):
+    try:
+            c = Courses.active.get(slug=slug)
+    except Courses.DoesNotExist:
+            raise Http404
+    return render_to_response('courses/course_detail.html', locals(),context_instance=RequestContext(request))
+        
+def lesson_detail(request, slug):
+    try:
+            l = Lessons.active.get(slug=slug)
+    except Lessons.DoesNotExist:
+            raise Http404
+    return render_to_response('courses/lesson_detail.html', locals(),context_instance=RequestContext(request))