From: Aleksander Ɓukasz Date: Thu, 9 May 2013 14:33:36 +0000 (+0200) Subject: Grouping libraries into different catalogs X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/1a6872f821959ade6a7382012338d628a4244877?ds=sidebyside Grouping libraries into different catalogs --- diff --git a/apps/libraries/admin.py b/apps/libraries/admin.py index c43dd6a35..5fa88df54 100644 --- a/apps/libraries/admin.py +++ b/apps/libraries/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from libraries.models import Library +from libraries.models import Library, Catalog -admin.site.register(Library) \ No newline at end of file +admin.site.register(Catalog) +admin.site.register(Library) diff --git a/apps/libraries/locale/pl/LC_MESSAGES/django.mo b/apps/libraries/locale/pl/LC_MESSAGES/django.mo index d8c29f1b0..a29a7b08d 100644 Binary files a/apps/libraries/locale/pl/LC_MESSAGES/django.mo and b/apps/libraries/locale/pl/LC_MESSAGES/django.mo differ diff --git a/apps/libraries/locale/pl/LC_MESSAGES/django.po b/apps/libraries/locale/pl/LC_MESSAGES/django.po index 57653b8fd..3c3e2bc3c 100644 --- a/apps/libraries/locale/pl/LC_MESSAGES/django.po +++ b/apps/libraries/locale/pl/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \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 index 000000000..c37abf526 --- /dev/null +++ b/apps/libraries/migrations/0002_auto__add_catalog__add_field_library_catalog.py @@ -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 diff --git a/apps/libraries/models.py b/apps/libraries/models.py index ff2afc07e..9856608ae 100644 --- a/apps/libraries/models.py +++ b/apps/libraries/models.py @@ -1,10 +1,26 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ + +class Catalog(models.Model): + """Represents a dictionary of libraries""" + + name = models.CharField(_('name'), max_length = 120, null = False) + slug = models.SlugField(_('slug'), max_length = 120, unique = True, db_index = True) + + class Meta: + verbose_name = _('catalog') + verbose_name_plural = _('catalogs') + + def __unicode__(self): + return self.name + + class Library(models.Model): """Represent a single library in the libraries dictionary""" name = models.CharField(_('name'), max_length = 120, blank = True) + catalog = models.ForeignKey(Catalog, null = False, related_name = 'libraries', on_delete = models.PROTECT) url = models.CharField(_('url'), max_length = 120, blank = True) description = models.TextField(_('description'), blank = True) diff --git a/apps/libraries/templates/libraries/main_view.html b/apps/libraries/templates/libraries/main_view.html index 9e16b1911..b109fa1b3 100644 --- a/apps/libraries/templates/libraries/main_view.html +++ b/apps/libraries/templates/libraries/main_view.html @@ -5,10 +5,10 @@ {% block body %} -

{% trans 'Libraries directory' %}

+

{% trans 'Libraries directory' %}: {{ catalog.name }}

- {% for library in libraries %} + {% for library in catalog.libraries.all %}
diff --git a/apps/libraries/urls.py b/apps/libraries/urls.py index 5b13dc526..b4af54be7 100644 --- a/apps/libraries/urls.py +++ b/apps/libraries/urls.py @@ -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[a-zA-Z0-9_-]+)$', 'main_view', name='libraries_main_view'), ) \ No newline at end of file diff --git a/apps/libraries/views.py b/apps/libraries/views.py index d75c8b468..45e60ddbf 100644 --- a/apps/libraries/views.py +++ b/apps/libraries/views.py @@ -1,11 +1,10 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext, Template, TemplateSyntaxError -from libraries.models import Library +from libraries.models import Catalog -def main_view(request): - context = RequestContext(request) - context['libraries'] = Library.objects.all() - +def main_view(request, slug): + context = RequestContext(request) + context['catalog'] = get_object_or_404(Catalog.objects.filter(slug = slug).select_related()) return render_to_response('libraries/main_view.html', context_instance = context) \ No newline at end of file