Giant refactor

This commit is contained in:
Zak Timson 2017-09-06 00:28:39 -04:00
parent cc8f5750a8
commit 0f484d1d0b
14 changed files with 62 additions and 63 deletions

3
.gitignore vendored
View File

@ -1,6 +1,5 @@
/OACPL.iml
/.idea/
/*/migrations/
/*/migrations
/OACPL/settings.py
/db.sqlite3

View File

@ -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']

View File

View File

@ -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()

View File

@ -14,10 +14,10 @@
<div id="search-filters" class="container-fluid bg-dark-primary text-white collapse">
<div class="container">
<div class="row py-3">
{% for header in allHeaders %}
{% for heading in allHeadings %}
<div class="col-xs-12 col-sm-6 col-md-4">
<input id="input-{{ header.id }}" class="curs-pointer filters" name="filter" type="checkbox" value="{{ header }}">
<label for="input-{{ header.id }}" class="curs-pointer">{{ header }}</label>
<input id="input-{{ heading.id }}" class="curs-pointer filters" name="filter" type="checkbox" value="{{ heading }}">
<label for="input-{{ heading.id }}" class="curs-pointer">{{ heading }}</label>
</div>
{% endfor %}
<div class="col-12">
@ -53,24 +53,24 @@
{% endif %}
<div class="row p-3">
<div class="col-lg-12 ml-auto text-dark-primary">
{% if headersCount > 1 and decisionsCount > 1 and not filter %}
{% if headingCount > 1 and headingCount > 1 and not filter %}
<h4>Headings</h4>
<hr>
{% for header in headers %}
{% for heading in headings %}
<div>
<a href="{% url 'browser' %}?path={% if url %}{{ url }}/{% endif %}{{ header }}">
<h4 class="d-inline-block"><i class="fa fa-folder-open-o"></i> {{ header }}</h4>
<a href="{% url 'browser' %}?path={% if url %}{{ url }}/{% endif %}{{ heading }}">
<h4 class="d-inline-block"><i class="fa fa-folder-open-o"></i> {{ heading }}</h4>
</a>
</div>
{% endfor %}
<br>
{% endif %}
<h4>Decisions</h4>
<h4>Cases</h4>
<hr>
{% for decision in decisions %}
{% for case in cases %}
<div>
<a href="{% url 'case' decision.id %}">
<h4 class="d-inline-block"><i class="fa fa-file-text-o"></i> {{ decision.synopsis }}</h4>
<a href="{% url 'case' case.id %}">
<h4 class="d-inline-block"><i class="fa fa-file-text-o"></i> {{ case.synopsis }}</h4>
</a>
</div>
{% endfor %}
@ -80,7 +80,7 @@
</div>
<div class="container-fluid bg-dark-primary p-2">
<div class="container text-white">
{% if headersCount %}{{ headersCount }} Headers, {% endif %}{{ decisionsCount }} Decision{% if decisionsCount > 1 %}s{% endif %}
{% if headingCount %}{{ headingCount }} Headings, {% endif %}{{ caseCount }} Case{% if caseCount > 1 %}s{% endif %}
</div>
</div>

View File

@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% load static %}
{% block body %}
<div class="container-fluid bg-light-blue py-3">
<div class="container">
<h3 class="text-dark-primary">Synopsis</h3>
{% for heading in headings %}
<span class="badge badge-primary">{{ heading }}</span>
{% endfor %}
<p>{{ case.synopsis | linebreaks }}</p>
<h6 class="text-muted">Published: {{ case.published }}</h6>
{% if perms.case_law.view_pdf %}
<a href="/media/{{ case.pdf }}">View PDF</a>
<br>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -1,19 +0,0 @@
{% extends 'base.html' %}
{% load static %}
{% block head %}
{% endblock %}
{% block body %}
<div class="container-fluid bg-light-blue py-3">
<div class="container">
<h1>Synopsis</h1>
<h6 class="text-muted">Date: {{ decision.date }}</h6>
<p>{{ decision.synopsis | linebreaks }}</p>
{% if perms.case_law.view_pdf %}
<a href="/media/{{ decision.pdf }}">View PDF</a>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -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()})

View File

View File

View File

@ -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)

View File

View File

View File