Grouping libraries into different catalogs
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 9 May 2013 14:33:36 +0000 (16:33 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 9 May 2013 14:33:36 +0000 (16:33 +0200)
apps/libraries/admin.py
apps/libraries/locale/pl/LC_MESSAGES/django.mo
apps/libraries/locale/pl/LC_MESSAGES/django.po
apps/libraries/migrations/0002_auto__add_catalog__add_field_library_catalog.py [new file with mode: 0644]
apps/libraries/models.py
apps/libraries/templates/libraries/main_view.html
apps/libraries/urls.py
apps/libraries/views.py

index c43dd6a..5fa88df 100644 (file)
@@ -1,6 +1,7 @@
 from django.contrib import admin\r
 \r
-from libraries.models import Library\r
+from libraries.models import Library, Catalog\r
 \r
 \r
-admin.site.register(Library)
\ No newline at end of file
+admin.site.register(Catalog)\r
+admin.site.register(Library)\r
index d8c29f1..a29a7b0 100644 (file)
Binary files a/apps/libraries/locale/pl/LC_MESSAGES/django.mo and b/apps/libraries/locale/pl/LC_MESSAGES/django.mo differ
index 57653b8..3c3e2bc 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-05-06 15:42+0200\n"
+"POT-Creation-Date: 2013-05-09 16:09+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -19,23 +19,35 @@ msgstr ""
 "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
 "|| n%100>=20) ? 1 : 2);\n"
 
-#: models.py:8
+#: models.py:8 models.py:22
 msgid "name"
 msgstr "nazwa"
 
 #: models.py:9
+msgid "slug"
+msgstr ""
+
+#: models.py:12
+msgid "catalog"
+msgstr "katalog"
+
+#: models.py:13
+msgid "catalogs"
+msgstr "katalogi"
+
+#: models.py:24
 msgid "url"
 msgstr "url"
 
-#: models.py:10
+#: models.py:25
 msgid "description"
 msgstr "opis"
 
-#: models.py:13
+#: models.py:28
 msgid "library"
 msgstr "biblioteka"
 
-#: models.py:14
+#: models.py:29
 msgid "libraries"
 msgstr "biblioteki"
 
diff --git a/apps/libraries/migrations/0002_auto__add_catalog__add_field_library_catalog.py b/apps/libraries/migrations/0002_auto__add_catalog__add_field_library_catalog.py
new file mode 100644 (file)
index 0000000..c37abf5
--- /dev/null
@@ -0,0 +1,50 @@
+# -*- 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 model 'Catalog'
+        db.create_table(u'libraries_catalog', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=120)),
+            ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=120)),
+        ))
+        db.send_create_signal(u'libraries', ['Catalog'])
+
+        # Adding field 'Library.catalog'
+        db.add_column(u'libraries_library', 'catalog',
+                      self.gf('django.db.models.fields.related.ForeignKey')(default=None, related_name='libraries', on_delete=models.PROTECT, to=orm['libraries.Catalog']),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting model 'Catalog'
+        db.delete_table(u'libraries_catalog')
+
+        # Deleting field 'Library.catalog'
+        db.delete_column(u'libraries_library', 'catalog_id')
+
+
+    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'}),
+            'url': ('django.db.models.fields.CharField', [], {'max_length': '120', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['libraries']
\ No newline at end of file
index ff2afc0..9856608 100644 (file)
@@ -1,10 +1,26 @@
 from django.db import models\r
 from django.utils.translation import ugettext_lazy as _\r
 \r
+\r
+class Catalog(models.Model):\r
+    """Represents a dictionary of libraries"""\r
+\r
+    name = models.CharField(_('name'), max_length = 120, null = False)\r
+    slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True)\r
+\r
+    class Meta:\r
+        verbose_name = _('catalog')\r
+        verbose_name_plural = _('catalogs')\r
+    \r
+    def __unicode__(self):\r
+        return self.name\r
+        \r
+    \r
 class Library(models.Model):\r
     """Represent a single library in the libraries dictionary"""\r
 \r
     name = models.CharField(_('name'), max_length = 120, blank = 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
 \r
index 9e16b19..b109fa1 100644 (file)
@@ -5,10 +5,10 @@
 
 
 {% block body %}
-    <h1>{% trans 'Libraries directory' %}</h1>
+    <h1>{% trans 'Libraries directory' %}: {{ catalog.name }}</h1>
 
     <div class="libraries-list">
-        {% for library in libraries %}
+        {% 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-description">
index 5b13dc5..b4af54b 100644 (file)
@@ -2,5 +2,5 @@ from django.conf.urls.defaults import patterns, url
 
 
 urlpatterns = patterns('libraries.views',
-    url(r'^$', 'main_view', name='libraries_main_view'),
+    url(r'^(?P<slug>[a-zA-Z0-9_-]+)$', 'main_view', name='libraries_main_view'),
 )
\ No newline at end of file
index d75c8b4..45e60dd 100644 (file)
@@ -1,11 +1,10 @@
 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 Library\r
+from libraries.models import Catalog\r
 \r
 \r
-def main_view(request):\r
-    context = RequestContext(request)
-    context['libraries'] = Library.objects.all()\r
-\r
+def main_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/main_view.html', context_instance = context)
\ No newline at end of file