├── django_glossary ├── migrations │ ├── __init__.py │ └── 0001_initial.py ├── templatetags │ ├── __init__.py │ └── glossary_tags.py ├── templates │ └── django_glossary │ │ ├── .svn │ │ ├── format │ │ └── entries │ │ ├── glossarize.html │ │ ├── glossary_list.html │ │ ├── term_detail.html │ │ ├── glossary.html │ │ └── term_list.html ├── media │ ├── base.css │ └── glossary.css ├── apps.py ├── urls.py ├── admin.py ├── __init__.py ├── README.rst ├── models.py ├── views.py └── tests.py ├── .gitignore ├── MANIFEST.in ├── README └── setup.py /django_glossary/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_glossary/templatetags/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_glossary/templates/django_glossary/.svn/format: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /django_glossary/media/base.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | background-color:#b0c4de; 4 | } -------------------------------------------------------------------------------- /django_glossary/templates/django_glossary/glossarize.html: -------------------------------------------------------------------------------- 1 | {{ content|safe }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | MANIFEST* 3 | dist 4 | .idea* 5 | .svn* 6 | test_project 7 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include-file README 2 | recursive-include glossary/media * 3 | recursive-include glossary/templates * 4 | -------------------------------------------------------------------------------- /django_glossary/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class GlossaryConfig(AppConfig): 5 | name = 'django_glossary' 6 | -------------------------------------------------------------------------------- /django_glossary/templates/django_glossary/glossary_list.html: -------------------------------------------------------------------------------- 1 |
You searched for "{{ query }}".
35 | {% if results %} 36 |Search results:
37 |No results found.
46 | {% endif %} 47 | {% if not query %} 48 |Please make a query! I'm hungry!
49 | {% endif %} 50 | 51 | {% endblock %} -------------------------------------------------------------------------------- /django_glossary/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.12 on 2018-04-29 14:36 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | import django.db.models.deletion 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='Synonym', 19 | fields=[ 20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('title', models.CharField(max_length=250)), 22 | ], 23 | ), 24 | migrations.CreateModel( 25 | name='Term', 26 | fields=[ 27 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 28 | ('created', models.DateTimeField(auto_now_add=True)), 29 | ('modified', models.DateTimeField(auto_now=True)), 30 | ('title', models.CharField(max_length=250)), 31 | ('slug', models.SlugField(unique=True)), 32 | ('description', models.TextField()), 33 | ], 34 | options={ 35 | 'ordering': ['title', '-modified'], 36 | }, 37 | ), 38 | migrations.AddField( 39 | model_name='synonym', 40 | name='term', 41 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='synonyms', to='django_glossary.Term'), 42 | ), 43 | ] 44 | -------------------------------------------------------------------------------- /django_glossary/views.py: -------------------------------------------------------------------------------- 1 | import string 2 | from django.db.models import Q 3 | from django.views.generic import DetailView, ListView 4 | from django_glossary.models import Term 5 | 6 | 7 | class TermListView(ListView): 8 | model = Term 9 | context_object_name = "terms" 10 | paginate_by = 20 11 | ordering = 'title' 12 | 13 | def get_context_data(self, **kwargs): 14 | context = super(TermListView, self).get_context_data(**kwargs) 15 | 16 | # import ipdb; ipdb.set_trace() 17 | 18 | terms = self.model.objects.all() 19 | 20 | if "q" in self.request.GET: 21 | query = self.request.GET['q'] 22 | terms = terms.filter( 23 | Q(title__icontains=query) 24 | | Q(description__icontains=query) 25 | | Q(synonyms__title__icontains=query) 26 | ).distinct() 27 | try: 28 | starts_with = query[0] 29 | except IndexError: 30 | starts_with = '' 31 | else: 32 | query = '' 33 | starts_with = self.request.GET.get("l", "a").lower() 34 | terms = terms.filter(title__istartswith=starts_with) 35 | 36 | used_letters = list(set(self.model.objects.distinct().extra( 37 | select={'f_letter': "lower(substr(title,1,1))"} 38 | ).values_list('f_letter', flat=True))) 39 | 40 | context.update({ 41 | 'a_z': string.ascii_lowercase, 42 | 'query': query, 43 | 'starts_with': starts_with, 44 | 'used_letters': used_letters, 45 | }) 46 | 47 | return context 48 | 49 | 50 | class TermDetailView(DetailView): 51 | model = Term 52 | context_object_name = "term" 53 | -------------------------------------------------------------------------------- /django_glossary/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | from django.core.urlresolvers import reverse 3 | from django_glossary.models import Term, Synonym 4 | 5 | 6 | class GlossaryTestCase(TestCase): 7 | def setUp(self): 8 | self.ace = Term.objects.create( title="Ace", slug = "ace", description="Description for Ace") 9 | self.base = Term.objects.create( title="Bace", slug = "base", description="Ace of BASE!") 10 | self.case = Term.objects.create( title="Case", slug = "case", description="Make a case") 11 | self.dace = Term.objects.create( title="Dace", slug = "dace", description="A dude named Dace") 12 | self.eco = Term.objects.create( title="Eco", slug = "eco", description="Eco-awesomeness") 13 | self.face = Term.objects.create( title="Face", slug = "face", description="In your face!") 14 | self.gale = Term.objects.create( title="Gale", slug = "gale", description="Dorothy Gale?") 15 | self.hail = Term.objects.create( title="Hail", slug = "hail", description="Hail of fail") 16 | self.ill = Term.objects.create( title="Ill", slug = "ill", description="That coat is ill.") 17 | self.synonym = Synonym.objects.create(title="Synonym", term = self.ace) 18 | 19 | def test_term(self): 20 | # These really aren't supposed to be different without non-ascii test data: 21 | self.assertEquals(str(self.ace), str(self.ace)) 22 | 23 | self.assertEquals(self.ace.title, u"Ace") 24 | self.assertEquals(self.ace.slug, "ace") 25 | 26 | def test_synonym(self): 27 | self.assertEquals(self.ace.title, self.synonym.term.title) 28 | 29 | # These really aren't supposed to be different without non-ascii test data: 30 | self.assertEquals(str(self.synonym)), str(self.synonym) 31 | 32 | self.assertTrue("synonym for" in self.synonym) 33 | self.assertTrue(self.ace.title in self.synonym) 34 | 35 | def test_term_view(self): 36 | response = self.client.get(reverse("glossary-list")) 37 | self.assertTrue(response.status_code == 200) 38 | -------------------------------------------------------------------------------- /django_glossary/templates/django_glossary/term_list.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% load glossary_tags %} 3 | {% load cache %} 4 | 5 | {% block title %}Glossary{% endblock %} 6 | {% block extra_head %} 7 | {{ block.super }} 8 | 9 | {% endblock %} 10 | 11 | {% block content %} 12 || 15 | a_z: {{ a_z }} 16 | | 17 |
| 20 | used_letters: {{ used_letters }} 21 | | 22 |
No results found
48 | {% endif %} 49 | {% endif %} 50 | 51 |