add a model for legislation classification, making topics
now you can make topics!
This commit is contained in:
parent
f415713bdb
commit
3fa153ee59
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import LegislativeText, LegislationBook
|
from explorer import models
|
||||||
|
|
||||||
class LegislativeTextAdmin(admin.ModelAdmin):
|
class LegislativeTextAdmin(admin.ModelAdmin):
|
||||||
list_display = ('__str__', 'legislation_title', 'school')
|
list_display = ('__str__', 'legislation_title', 'school')
|
||||||
|
@ -8,5 +8,11 @@ class LegislativeTextAdmin(admin.ModelAdmin):
|
||||||
class LegislationBookAdmin(admin.ModelAdmin):
|
class LegislationBookAdmin(admin.ModelAdmin):
|
||||||
exclude = ("has_performed_export",)
|
exclude = ("has_performed_export",)
|
||||||
|
|
||||||
admin.site.register(LegislativeText, LegislativeTextAdmin)
|
to_register = [
|
||||||
admin.site.register(LegislationBook, LegislationBookAdmin)
|
[models.LegislativeText, LegislativeTextAdmin],
|
||||||
|
[models.LegislationBook, LegislationBookAdmin],
|
||||||
|
[models.LegislationClassification]
|
||||||
|
]
|
||||||
|
for i in to_register:
|
||||||
|
admin.site.register(*i)
|
||||||
|
print(i)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 4.2.12 on 2024-06-28 20:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('explorer', '0003_legislationbook_has_performed_export_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='LegislationClassification',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(help_text='Name of this classification.', max_length=256)),
|
||||||
|
('text_to_match', models.CharField(help_text='a comma seperated list of keywords to include in the classification. spaces and dashes are discluded.', max_length=256)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 4.2.12 on 2024-06-28 21:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('explorer', '0004_legislationclassification'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='legislationclassification',
|
||||||
|
name='obvious_change',
|
||||||
|
field=models.CharField(default='test', help_text='Name of this classification.', max_length=256),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 4.2.12 on 2024-06-28 21:08
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('explorer', '0005_legislationclassification_obvious_change'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='legislationclassification',
|
||||||
|
name='obvious_change',
|
||||||
|
),
|
||||||
|
]
|
|
@ -31,8 +31,6 @@ class LegislationBook(models.Model):
|
||||||
has_performed_export = models.BooleanField(default=False)
|
has_performed_export = models.BooleanField(default=False)
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
super().save(**kwargs)
|
|
||||||
|
|
||||||
if not self.has_performed_export:
|
if not self.has_performed_export:
|
||||||
self.has_performed_export = True
|
self.has_performed_export = True
|
||||||
super().save(**kwargs)
|
super().save(**kwargs)
|
||||||
|
@ -136,3 +134,13 @@ class LegislativeText(models.Model):
|
||||||
if self.assembly in ["RGA", "BGA", "WGA", "GEN"]:
|
if self.assembly in ["RGA", "BGA", "WGA", "GEN"]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
class LegislationClassification(models.Model):
|
||||||
|
name = models.CharField(max_length=256, help_text="Name of this classification.")
|
||||||
|
text_to_match = models.CharField(
|
||||||
|
max_length=256,
|
||||||
|
help_text="a comma seperated list of keywords to include in the classification. spaces and dashes are discluded."
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "{}".format(self.name)
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
{% extends "explorer/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/tn.css" />
|
||||||
|
|
||||||
|
<div class="boxed">
|
||||||
|
<h1>All topics</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for topic in classifications %}
|
||||||
|
<li><a href="/explorer/topics/{{ topic.id }}">{{ topic.name }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{% extends "explorer/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/tn.css" />
|
||||||
|
|
||||||
|
<div class="boxed">
|
||||||
|
<h1>{{ result_name }}</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for text in legislation %}
|
||||||
|
<li><a href="/explorer/legislation/{{ text.id }}">{{ text.legislation_title }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
|
@ -8,4 +8,6 @@ urlpatterns = [
|
||||||
path("stats/", views.stats, name="stats"),
|
path("stats/", views.stats, name="stats"),
|
||||||
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"),
|
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"),
|
||||||
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
||||||
|
path("topics/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
|
||||||
|
path("topics/", views.get_all_classifications, name="classificationview"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from .models import LegislativeText, LegislationBook
|
from .models import LegislativeText, LegislationBook, LegislationClassification
|
||||||
|
|
||||||
from random import sample
|
from random import sample
|
||||||
|
|
||||||
|
@ -53,3 +53,30 @@ def stats(request):
|
||||||
"white_ga": len(LegislativeText.objects.filter(assembly="WGA")),
|
"white_ga": len(LegislativeText.objects.filter(assembly="WGA")),
|
||||||
}
|
}
|
||||||
return render(request, "explorer/stats.html", context)
|
return render(request, "explorer/stats.html", context)
|
||||||
|
|
||||||
|
def get_all_classifications(request):
|
||||||
|
classifications = LegislationClassification.objects.all()
|
||||||
|
return render(request, "explorer/classifications.html", {
|
||||||
|
"classifications": classifications,
|
||||||
|
})
|
||||||
|
|
||||||
|
def get_all_classified_by_id(request, classification_id):
|
||||||
|
classification = get_object_or_404(LegislationClassification, pk=classification_id)
|
||||||
|
# this is very expensive; make a way for this to be cached please?
|
||||||
|
|
||||||
|
all_texts = LegislativeText.objects.all()
|
||||||
|
all_terms = classification.text_to_match.split(',')
|
||||||
|
all_terms = [i.lower() for i in all_terms]
|
||||||
|
|
||||||
|
matches = []
|
||||||
|
|
||||||
|
for text in all_texts:
|
||||||
|
for term in all_terms:
|
||||||
|
if term in text.text.lower():
|
||||||
|
matches.append(text)
|
||||||
|
break
|
||||||
|
|
||||||
|
return render(request, "explorer/results.html", {
|
||||||
|
"legislation": matches,
|
||||||
|
"result_name": "All legislation in topic {}".format(classification.name)
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue