From: Marek Stępniowski Date: Wed, 16 Dec 2009 00:38:05 +0000 (+0100) Subject: Dodanie aplikacji lessons, zapomnianej w poprzednim commicie. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/2b42a7314b63bed80a1561970ed0d1a065bce45f?hp=f7833f76b5f9555b0d95d23d47fc886a3528a335 Dodanie aplikacji lessons, zapomnianej w poprzednim commicie. --- diff --git a/apps/lessons/__init__.py b/apps/lessons/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/apps/lessons/admin.py b/apps/lessons/admin.py new file mode 100644 index 000000000..813621f91 --- /dev/null +++ b/apps/lessons/admin.py @@ -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 index 000000000..b0cd59337 --- /dev/null +++ b/apps/lessons/models.py @@ -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 index 000000000..d43ac3ab1 --- /dev/null +++ b/apps/lessons/urls.py @@ -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[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 index 000000000..e22691985 --- /dev/null +++ b/apps/lessons/views.py @@ -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(), + })