--- /dev/null
+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)
--- /dev/null
+# -*- 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])
--- /dev/null
+# -*- 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'),
+)
+
--- /dev/null
+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(),
+ })