Compare commits
No commits in common. "3fa153ee592fae0e5a22c2d2e834ee031946f376" and "599fc413892c89b79428eed76340637f2d477f4b" have entirely different histories.
3fa153ee59
...
599fc41389
|
@ -1,2 +0,0 @@
|
||||||
SECRET_KEY=834701
|
|
||||||
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
|
|
|
@ -5,4 +5,3 @@ __pycache__
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
media
|
media
|
||||||
uploads/
|
uploads/
|
||||||
staticfiles/
|
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -1,5 +0,0 @@
|
||||||
prod: # execute this target on the production server in the nix-shell
|
|
||||||
rm -r franklincce/staticfiles
|
|
||||||
cd franklincce; python3 manage.py collectstatic
|
|
||||||
sed -i "s/change_me/$(shell shuf -i1-1000000 -n1)/g" .env.prod
|
|
||||||
docker-compose -f docker-compose.prod.yml up -d --build
|
|
|
@ -1,22 +0,0 @@
|
||||||
services:
|
|
||||||
web:
|
|
||||||
build:
|
|
||||||
context: ./franklincce
|
|
||||||
dockerfile: Dockerfile.prod
|
|
||||||
command: gunicorn franklincce.wsgi:application --bind 0.0.0.0:8000
|
|
||||||
volumes:
|
|
||||||
- static_volume:/home/app/web/staticfiles
|
|
||||||
expose:
|
|
||||||
- 8000
|
|
||||||
env_file:
|
|
||||||
- ./.env.prod
|
|
||||||
nginx:
|
|
||||||
build: ./nginx
|
|
||||||
volumes:
|
|
||||||
- static_volume:/home/app/web/staticfiles
|
|
||||||
ports:
|
|
||||||
- 1337:80
|
|
||||||
depends_on:
|
|
||||||
- web
|
|
||||||
volumes:
|
|
||||||
static_volume:
|
|
|
@ -1,6 +1,6 @@
|
||||||
services:
|
services:
|
||||||
web:
|
web:
|
||||||
build: ./franklincce
|
build: ./app
|
||||||
command: python manage.py runserver 0.0.0.0:8000
|
command: python manage.py runserver 0.0.0.0:8000
|
||||||
volumes:
|
volumes:
|
||||||
- ./franklincce/:/usr/src/app/
|
- ./franklincce/:/usr/src/app/
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
FROM python:3.11.4-slim-buster as builder
|
|
||||||
|
|
||||||
# set work directory
|
|
||||||
WORKDIR /usr/src/app
|
|
||||||
|
|
||||||
# set environment variables
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
|
||||||
ENV PYTHONUNBUFFERED 1
|
|
||||||
|
|
||||||
# install system dependencies
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y --no-install-recommends gcc
|
|
||||||
|
|
||||||
COPY ./requirements.txt .
|
|
||||||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
|
|
||||||
|
|
||||||
# pull official base image
|
|
||||||
FROM python:3.11.4-slim-buster
|
|
||||||
|
|
||||||
# create directory for the app user
|
|
||||||
RUN mkdir -p /home/app
|
|
||||||
|
|
||||||
# create the app user
|
|
||||||
RUN addgroup --system app && adduser --system --group app
|
|
||||||
|
|
||||||
# create the appropriate directories
|
|
||||||
ENV HOME=/home/app
|
|
||||||
ENV APP_HOME=/home/app/web
|
|
||||||
RUN mkdir $APP_HOME
|
|
||||||
RUN mkdir $APP_HOME/staticfiles
|
|
||||||
WORKDIR $APP_HOME
|
|
||||||
|
|
||||||
# install dependencies
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends netcat
|
|
||||||
COPY --from=builder /usr/src/app/wheels /wheels
|
|
||||||
COPY --from=builder /usr/src/app/requirements.txt .
|
|
||||||
RUN pip install --upgrade pip
|
|
||||||
RUN pip install --no-cache /wheels/*
|
|
||||||
|
|
||||||
# copy entrypoint.prod.sh
|
|
||||||
COPY ./entrypoint.prod.sh .
|
|
||||||
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.prod.sh
|
|
||||||
RUN chmod +x $APP_HOME/entrypoint.prod.sh
|
|
||||||
|
|
||||||
# copy project
|
|
||||||
COPY . $APP_HOME
|
|
||||||
|
|
||||||
# chown all the files to the app user
|
|
||||||
RUN chown -R app:app $APP_HOME
|
|
||||||
|
|
||||||
# change to the app user
|
|
||||||
USER app
|
|
||||||
|
|
||||||
# run entrypoint.prod.sh
|
|
||||||
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
exec "$@"
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from explorer import models
|
from .models import LegislativeText, LegislationBook
|
||||||
|
|
||||||
class LegislativeTextAdmin(admin.ModelAdmin):
|
class LegislativeTextAdmin(admin.ModelAdmin):
|
||||||
list_display = ('__str__', 'legislation_title', 'school')
|
list_display = ('__str__', 'legislation_title', 'school')
|
||||||
|
@ -8,11 +8,5 @@ class LegislativeTextAdmin(admin.ModelAdmin):
|
||||||
class LegislationBookAdmin(admin.ModelAdmin):
|
class LegislationBookAdmin(admin.ModelAdmin):
|
||||||
exclude = ("has_performed_export",)
|
exclude = ("has_performed_export",)
|
||||||
|
|
||||||
to_register = [
|
admin.site.register(LegislativeText, LegislativeTextAdmin)
|
||||||
[models.LegislativeText, LegislativeTextAdmin],
|
admin.site.register(LegislationBook, LegislationBookAdmin)
|
||||||
[models.LegislationBook, LegislationBookAdmin],
|
|
||||||
[models.LegislationClassification]
|
|
||||||
]
|
|
||||||
for i in to_register:
|
|
||||||
admin.site.register(*i)
|
|
||||||
print(i)
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
# 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)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,19 +0,0 @@
|
||||||
# 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,
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,17 +0,0 @@
|
||||||
# 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,6 +31,8 @@ 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)
|
||||||
|
@ -134,13 +136,3 @@ 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)
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
{% 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 %}
|
|
|
@ -1,15 +0,0 @@
|
||||||
{% 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,6 +8,4 @@ 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, LegislationClassification
|
from .models import LegislativeText, LegislationBook
|
||||||
|
|
||||||
from random import sample
|
from random import sample
|
||||||
|
|
||||||
|
@ -53,30 +53,3 @@ 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)
|
|
||||||
})
|
|
||||||
|
|
|
@ -23,10 +23,7 @@ DEBUG = bool(os.environ.get("DEBUG", default=0))
|
||||||
|
|
||||||
# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each.
|
# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each.
|
||||||
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]'
|
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]'
|
||||||
try:
|
|
||||||
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
|
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
|
||||||
except:
|
|
||||||
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]
|
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'explorer.apps.ExplorerConfig',
|
'explorer.apps.ExplorerConfig',
|
||||||
|
@ -121,8 +118,4 @@ STATIC_URL = '/static/'
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = ["http://localhost:1337"]
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
FROM nginx:1.25
|
|
||||||
|
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d
|
|
|
@ -1,18 +0,0 @@
|
||||||
upstream franklincce {
|
|
||||||
server web:8000;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://franklincce;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_redirect off;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /static/ {
|
|
||||||
alias /home/app/web/staticfiles/;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ pkgs ? import <nixpkgs> {} }:
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
nativeBuildInputs = with pkgs.python311Packages; [ django pymupdf ] ++ [pkgs.docker-compose pkgs.gnumake] ;
|
nativeBuildInputs = with pkgs.python311Packages; [ django pymupdf ] ++ [pkgs.docker-compose] ;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue