Adding library own page
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 13 May 2013 12:07:49 +0000 (14:07 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 13 May 2013 12:07:49 +0000 (14:07 +0200)
apps/libraries/migrations/0003_auto__add_field_library_slug.py [new file with mode: 0644]
apps/libraries/models.py
apps/libraries/templates/libraries/catalog_view.html
apps/libraries/templates/libraries/library_view.html [new file with mode: 0644]
apps/libraries/urls.py
apps/libraries/views.py

diff --git a/apps/libraries/migrations/0003_auto__add_field_library_slug.py b/apps/libraries/migrations/0003_auto__add_field_library_slug.py
new file mode 100644 (file)
index 0000000..de0cdf0
--- /dev/null
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Library.slug'
+        db.add_column(u'libraries_library', 'slug',
+                      self.gf('django.db.models.fields.SlugField')(max_length=120, unique=True, null=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Library.slug'
+        db.delete_column(u'libraries_library', 'slug')
+
+
+    models = {
+        u'libraries.catalog': {
+            'Meta': {'object_name': 'Catalog'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'})
+        },
+        u'libraries.library': {
+            'Meta': {'object_name': 'Library'},
+            'catalog': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'libraries'", 'on_delete': 'models.PROTECT', 'to': u"orm['libraries.Catalog']"}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'null': 'True'}),
+            'url': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['libraries']
\ No newline at end of file
index c6db612..5f92421 100644 (file)
@@ -24,6 +24,7 @@ class Library(models.Model):
     """Represent a single library in the libraries dictionary"""\r
 \r
     name = models.CharField(_('name'), max_length = 120, blank = True)
     """Represent a single library in the libraries dictionary"""\r
 \r
     name = models.CharField(_('name'), max_length = 120, blank = True)
+    slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True, null = True)
     catalog = models.ForeignKey(Catalog, null = False, related_name = 'libraries', on_delete = models.PROTECT)\r
     url = models.CharField(_('url'), max_length = 120, blank = True)
     description = models.TextField(_('description'), blank = True)\r
     catalog = models.ForeignKey(Catalog, null = False, related_name = 'libraries', on_delete = models.PROTECT)\r
     url = models.CharField(_('url'), max_length = 120, blank = True)
     description = models.TextField(_('description'), blank = True)\r
@@ -35,3 +36,6 @@ class Library(models.Model):
     def __unicode__(self):\r
         return self.name\r
 \r
     def __unicode__(self):\r
         return self.name\r
 \r
+    @models.permalink\r
+    def get_absolute_url(self):\r
+        return ('libraries_library_view', [self.catalog.slug, self.slug])
\ No newline at end of file
index b109fa1..1a56cbc 100644 (file)
     <div class="libraries-list">
         {% for library in catalog.libraries.all %}
         <div class="libraries-list-item">
     <div class="libraries-list">
         {% for library in catalog.libraries.all %}
         <div class="libraries-list-item">
-            <div class="libraries-list-item-header"><a href="{{library.url}}">{{library.name}}</a></div>
+            <div class="libraries-list-item-header"><a href="{{library.get_absolute_url}}">{{library.name}}</a></div>
             <div class="libraries-list-item-description">
                 
             <div class="libraries-list-item-description">
                 
-                {% autoescape off %}{{library.description}}{% endautoescape%}
+                
             </div>
         </div>
         {% endfor %}
             </div>
         </div>
         {% endfor %}
diff --git a/apps/libraries/templates/libraries/library_view.html b/apps/libraries/templates/libraries/library_view.html
new file mode 100644 (file)
index 0000000..153ead0
--- /dev/null
@@ -0,0 +1,15 @@
+{% extends "base.html" %}\r
+{% load i18n %}\r
+\r
+{% block titleextra %}{{ library.name }}{% endblock %}\r
+\r
+\r
+{% block body %}
+    <h1>{{ library.name }}</h1>\r
+    <div class="left-column">
+        <div class="normal-text">
+            <p>Adres strony www: <a href="{{library.url}}">{{library.url}}</a></p>\r
+            {% autoescape off %}{{library.description}}{% endautoescape%}
+        </div>\r
+    </div>\r
+{% endblock %}
\ No newline at end of file
index fe0fd6b..01531a9 100644 (file)
@@ -6,4 +6,5 @@ urlpatterns = patterns('libraries.views',
     url(r'^$', 'main_view', name='libraries_main_view'),
     url(r'^/$', lambda x: HttpResponseRedirect(x.path[:-1])),
     url(r'^/(?P<slug>[a-zA-Z0-9_-]+)$', 'catalog_view', name='libraries_catalog_view'),
     url(r'^$', 'main_view', name='libraries_main_view'),
     url(r'^/$', lambda x: HttpResponseRedirect(x.path[:-1])),
     url(r'^/(?P<slug>[a-zA-Z0-9_-]+)$', 'catalog_view', name='libraries_catalog_view'),
+    url(r'^/(?P<catalog_slug>[a-zA-Z0-9_-]+)/(?P<slug>[a-zA-Z0-9_-]+)$', 'library_view', name='libraries_library_view'),
 )
\ No newline at end of file
 )
\ No newline at end of file
index 88f993d..f79f2a1 100644 (file)
@@ -1,7 +1,7 @@
 from django.shortcuts import render_to_response, get_object_or_404\r
 from django.template import RequestContext, Template, TemplateSyntaxError\r
 \r
 from django.shortcuts import render_to_response, get_object_or_404\r
 from django.template import RequestContext, Template, TemplateSyntaxError\r
 \r
-from libraries.models import Catalog\r
+from libraries.models import Catalog, Library\r
 \r
 \r
 def main_view(request):\r
 \r
 \r
 def main_view(request):\r
@@ -12,4 +12,9 @@ def main_view(request):
 def catalog_view(request, slug):\r
     context = RequestContext(request)\r
     context['catalog'] = get_object_or_404(Catalog.objects.filter(slug = slug).select_related())\r
 def catalog_view(request, slug):\r
     context = RequestContext(request)\r
     context['catalog'] = get_object_or_404(Catalog.objects.filter(slug = slug).select_related())\r
-    return render_to_response('libraries/catalog_view.html', context_instance = context)
\ No newline at end of file
+    return render_to_response('libraries/catalog_view.html', context_instance = context)\r
+    \r
+def library_view(request, catalog_slug, slug):\r
+    context = RequestContext(request)\r
+    context['library'] = get_object_or_404(Library.objects.filter(slug = slug).filter(catalog__slug = catalog_slug))\r
+    return render_to_response('libraries/library_view.html', context_instance = context)
\ No newline at end of file