Dodanie aplikacji lessons, zapomnianej w poprzednim commicie.
authorMarek Stępniowski <marek@stepniowski.com>
Wed, 16 Dec 2009 00:38:05 +0000 (01:38 +0100)
committerMarek Stępniowski <marek@stepniowski.com>
Wed, 16 Dec 2009 00:38:05 +0000 (01:38 +0100)
apps/lessons/__init__.py [new file with mode: 0644]
apps/lessons/admin.py [new file with mode: 0644]
apps/lessons/models.py [new file with mode: 0644]
apps/lessons/urls.py [new file with mode: 0644]
apps/lessons/views.py [new file with mode: 0644]

diff --git a/apps/lessons/__init__.py b/apps/lessons/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/apps/lessons/admin.py b/apps/lessons/admin.py
new file mode 100644 (file)
index 0000000..813621f
--- /dev/null
@@ -0,0 +1,13 @@
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+from lessons.models import Document
+
+
+class DocumentAdmin(admin.ModelAdmin):
+    list_display = ('title', 'author', 'slideshare_id')
+    list_filter = ('author',)
+    search_fields = ('name', 'author',)
+    prepopulated_fields = {'slug': ('title',)}
+
+admin.site.register(Document, DocumentAdmin)
diff --git a/apps/lessons/models.py b/apps/lessons/models.py
new file mode 100644 (file)
index 0000000..b0cd593
--- /dev/null
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+from os import path
+
+class Document(models.Model):
+    """Dokument - materiał pomocniczy dla nauczycieli."""
+    title = models.CharField(_('title'), max_length=120)
+    slug = models.SlugField(_('slug'))
+    file = models.FileField(_('file'), upload_to='lessons/document')
+    author = models.CharField(_('author'), blank=True, max_length=120)
+    slideshare_id = models.CharField(_('slideshare ID'), blank=True, max_length=120)
+    description = models.TextField(_('description'), blank=True)
+    created_at = models.DateTimeField(auto_now_add=True)
+    
+    def slideshare_player(self):
+        base, ext = path.splitext(self.file.name)
+        if ext in ('.ppt', '.pps', '.pot', '.pptx', '.potx', '.ppsx', '.odp', '.key', '.zip', '.pdf',):
+            return 'ssplayer2.swf'
+        else:
+            return 'ssplayerd.swf'
+    
+    class Meta:
+        ordering = ['slug']
+        verbose_name, verbose_name_plural = _("document"), _("documents")
+
+    def __unicode__(self):
+        return self.title
+
+    @models.permalink
+    def get_absolute_url(self):
+        return ('lessons_document_detail', [self.slug])
diff --git a/apps/lessons/urls.py b/apps/lessons/urls.py
new file mode 100644 (file)
index 0000000..d43ac3a
--- /dev/null
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from django.conf.urls.defaults import *
+from catalogue import forms
+from lessons import models
+
+
+urlpatterns = patterns('',
+    url(r'^$', 'django.views.generic.list_detail.object_list', {
+        'queryset': models.Document.objects.all(),
+        'template_name': 'lessons/document_list.html',
+        'extra_context': {
+            'form': forms.SearchForm(),
+        },
+    }, name='lessons_document_list'),
+    
+    url(r'^(?P<slug>[a-zA-Z0-9_-]+)/$', 'lessons.views.document_detail', name='lessons_document_detail'),
+)
+
diff --git a/apps/lessons/views.py b/apps/lessons/views.py
new file mode 100644 (file)
index 0000000..e226919
--- /dev/null
@@ -0,0 +1,18 @@
+from django.views.generic.list_detail import object_detail
+from catalogue import forms
+from lessons import models
+
+
+def document_detail(request, slug):
+    template_name = 'lessons/document_detail.html'
+    if request.is_ajax():
+        template_name = 'lessons/ajax_document_detail.html'
+    
+    return object_detail(request,
+        slug=slug,
+        slug_field='slug',
+        queryset=models.Document.objects.all(),
+        template_name=template_name,
+        extra_context={
+            'form': forms.SearchForm(),
+        })