From 0f484d1d0b52487a5e2427415dc982bbf7293a9d Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Wed, 6 Sep 2017 00:28:39 -0400 Subject: [PATCH] Giant refactor --- .gitignore | 3 +-- case_law/admin.py | 12 ++++----- case_law/migrations/__init__.py | 0 case_law/models.py | 8 +++--- case_law/templates/browser.html | 24 ++++++++--------- case_law/templates/case.html | 19 +++++++++++++ case_law/templates/decision.html | 19 ------------- case_law/views.py | 36 ++++++++++++------------- charter_members/migrations/__init__.py | 0 expert_witnesses/migrations/__init__.py | 0 expert_witnesses/models.py | 4 +-- forum/migrations/__init__.py | 0 main/migrations/__init__.py | 0 newsletters/migrations/__init__.py | 0 14 files changed, 62 insertions(+), 63 deletions(-) create mode 100644 case_law/migrations/__init__.py create mode 100644 case_law/templates/case.html delete mode 100644 case_law/templates/decision.html create mode 100644 charter_members/migrations/__init__.py create mode 100644 expert_witnesses/migrations/__init__.py create mode 100644 forum/migrations/__init__.py create mode 100644 main/migrations/__init__.py create mode 100644 newsletters/migrations/__init__.py diff --git a/.gitignore b/.gitignore index e3120de..192a820 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ - /OACPL.iml /.idea/ -/*/migrations/ +/*/migrations /OACPL/settings.py /db.sqlite3 diff --git a/case_law/admin.py b/case_law/admin.py index 3d914a8..04e801f 100644 --- a/case_law/admin.py +++ b/case_law/admin.py @@ -1,12 +1,12 @@ from django.contrib import admin -from case_law.models import Decision, Subtitle +from case_law.models import Case, Heading -admin.site.register(Subtitle) +admin.site.register(Heading) -@admin.register(Decision) +@admin.register(Case) class DecisionAdmin(admin.ModelAdmin): - fields = ['synopsis', 'headers', 'date', 'pdf'] - filter_horizontal = ['headers'] - list_display = ['synopsis', 'date'] + fields = ['synopsis', 'headings', 'published', 'pdf'] + filter_horizontal = ['headings'] + list_display = ['synopsis', 'published'] diff --git a/case_law/migrations/__init__.py b/case_law/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/case_law/models.py b/case_law/models.py index 4b96c77..8d137d6 100644 --- a/case_law/models.py +++ b/case_law/models.py @@ -1,22 +1,22 @@ from django.db import models -class Subtitle(models.Model): +class Heading(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name -class Decision(models.Model): +class Case(models.Model): class Meta(object): permissions = ( ('view_pdf', 'Can view PDF'), ) - date = models.DateField() - headers = models.ManyToManyField(Subtitle) + published = models.DateField() + headings = models.ManyToManyField(Heading) pdf = models.FileField(upload_to='secure') synopsis = models.TextField() diff --git a/case_law/templates/browser.html b/case_law/templates/browser.html index 6a237fd..48de71d 100644 --- a/case_law/templates/browser.html +++ b/case_law/templates/browser.html @@ -14,10 +14,10 @@
- {% for header in allHeaders %} + {% for heading in allHeadings %}
- - + +
{% endfor %}
@@ -53,24 +53,24 @@ {% endif %}
- {% if headersCount > 1 and decisionsCount > 1 and not filter %} + {% if headingCount > 1 and headingCount > 1 and not filter %}

Headings


- {% for header in headers %} + {% for heading in headings %} {% endfor %}
{% endif %} -

Decisions

+

Cases


- {% for decision in decisions %} + {% for case in cases %} {% endfor %} @@ -80,7 +80,7 @@
- {% if headersCount %}{{ headersCount }} Headers, {% endif %}{{ decisionsCount }} Decision{% if decisionsCount > 1 %}s{% endif %} + {% if headingCount %}{{ headingCount }} Headings, {% endif %}{{ caseCount }} Case{% if caseCount > 1 %}s{% endif %}
diff --git a/case_law/templates/case.html b/case_law/templates/case.html new file mode 100644 index 0000000..0959b16 --- /dev/null +++ b/case_law/templates/case.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} +{% load static %} + +{% block body %} +
+
+

Synopsis

+ {% for heading in headings %} + {{ heading }} + {% endfor %} +

{{ case.synopsis | linebreaks }}

+
Published: {{ case.published }}
+ {% if perms.case_law.view_pdf %} + View PDF +
+ {% endif %} +
+
+{% endblock %} \ No newline at end of file diff --git a/case_law/templates/decision.html b/case_law/templates/decision.html deleted file mode 100644 index 68beb8b..0000000 --- a/case_law/templates/decision.html +++ /dev/null @@ -1,19 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block head %} - -{% endblock %} - -{% block body %} -
-
-

Synopsis

-
Date: {{ decision.date }}
-

{{ decision.synopsis | linebreaks }}

- {% if perms.case_law.view_pdf %} - View PDF - {% endif %} -
-
-{% endblock %} \ No newline at end of file diff --git a/case_law/views.py b/case_law/views.py index 8dcc86b..977e0a8 100644 --- a/case_law/views.py +++ b/case_law/views.py @@ -1,42 +1,42 @@ from django.shortcuts import render -from .models import Decision, Subtitle +from .models import Case, Heading def browser(request): - headers = {} + headings = {} path = request.GET.get('path') filter = request.GET.get('filter') - decisions = Decision.objects.all() + cases = Case.objects.all() if filter: filter = filter.split('/') print(filter) - ids = Subtitle.objects.filter(name__in=filter).values_list('id') + ids = Heading.objects.filter(name__in=filter).values_list('id') for id in ids: - decisions = decisions.filter(headers__in=id) + cases = cases.filter(headings__in=id) elif path: path = path.split('/') - ids = Subtitle.objects.filter(name__in=path).values_list('id') + ids = Heading.objects.filter(name__in=path).values_list('id') for id in ids: - decisions = decisions.filter(headers__in=id) + cases = cases.filter(headings__in=id) - headers = set() - for decision in decisions: - headers = headers.union(decision.headers.all().values_list('name', flat=True)) - if path: headers = headers.difference(path) + headings = set() + for decision in cases: + headings = headings.union(decision.headings.all().values_list('name', flat=True)) + if path: headings = headings.difference(path) return render(request, 'browser.html', { - 'allHeaders': Subtitle.objects.all().order_by('name'), - 'decisions': decisions.order_by('synopsis'), - 'decisionsCount': len(decisions), + 'allHeadings': Heading.objects.all().order_by('name'), + 'cases': cases.order_by('synopsis'), + 'caseCount': len(cases), 'filter': filter, - 'headers': sorted(headers), - 'headersCount': len(headers), + 'headings': sorted(headings), + 'headingCount': len(headings), 'url': request.GET.get('path'), 'urls': path }) def case(request, id): - decision = Decision.objects.get(id=id) - return render(request, 'decision.html', {'decision': decision}) + case = Case.objects.get(id=id) + return render(request, 'case.html', {'case': case, 'headings': case.headings.all()}) diff --git a/charter_members/migrations/__init__.py b/charter_members/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/expert_witnesses/migrations/__init__.py b/expert_witnesses/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/expert_witnesses/models.py b/expert_witnesses/models.py index d569358..2fb1e0c 100644 --- a/expert_witnesses/models.py +++ b/expert_witnesses/models.py @@ -1,6 +1,6 @@ from django.db import models -from case_law.models import Decision +from case_law.models import Case class AreaOfExpertise(models.Model): @@ -15,7 +15,7 @@ class AreaOfExpertise(models.Model): class Expert(models.Model): - cases = models.ManyToManyField(Decision, null=True, blank=True) + cases = models.ManyToManyField(Case, null=True, blank=True) expertise = models.ManyToManyField(AreaOfExpertise) institute = models.CharField(max_length=255, null=True, blank=True) name = models.CharField(max_length=255) diff --git a/forum/migrations/__init__.py b/forum/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/migrations/__init__.py b/main/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/newsletters/migrations/__init__.py b/newsletters/migrations/__init__.py new file mode 100644 index 0000000..e69de29