Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into l10n_main
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Oct 24, 2023
2 parents dbd6f2c + c875798 commit 999d519
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 226 deletions.
1 change: 1 addition & 0 deletions africanlii/static/lib/flag-icons/css/flag-icons.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion africanlii/templates/africanlii/au_institution_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
{% endblock %}
{% block entity-profile %}
{% with entity_profile=author.entity_profile.first entity_profile_title=author.name %}
{% with entity_profile=author.au_institution.entity_profile.first entity_profile_title=author.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% endif %}
Expand Down
8 changes: 5 additions & 3 deletions africanlii/templates/africanlii/au_organ_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
</div>
{% endblock %}
{% block entity-profile %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% endif %}
{% with entity_profile=author.au_organ.entity_profile.first entity_profile_title=author.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% endif %}
{% endwith %}
{% endblock %}
{% block page-header %}
<h1 class="mt-4">{{ obj }}</h1>
Expand Down
12 changes: 0 additions & 12 deletions africanlii/views/au.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ def get_context_data(self, **kwargs):
class AfricanUnionOrganDetailView(AuthorDetailView):
template_name = "africanlii/au_organ_detail.html"

def get_queryset(self):
self.au_organ = get_object_or_404(
AfricanUnionOrgan, author__code=self.kwargs["code"]
)
return super().get_queryset()

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["entity_profile"] = self.au_organ.entity_profile.first()
context["entity_profile_title"] = self.au_organ.author.name
return context


class AfricanUnionInstitutionDetailView(AuthorDetailView):
template_name = "africanlii/au_institution_detail.html"
Expand Down
6 changes: 6 additions & 0 deletions peachjam/adapters/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ def update_document(self, url):
else:
raise error

# don't ingest stubs that don't have a publication document
if document["stub"]:
pubdoc = document["publication_document"]
if not pubdoc or not pubdoc["url"]:
return

frbr_uri = FrbrUri.parse(document["frbr_uri"])
title = document["title"]
toc_json = self.get_toc_json(url)
Expand Down
2 changes: 2 additions & 0 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ class LegislationAdmin(ImportExportMixin, DocumentAdmin):
fieldsets = copy.deepcopy(DocumentAdmin.fieldsets)
fieldsets[0][1]["fields"].extend(["nature"])
fieldsets[3][1]["fields"].extend(["metadata_json"])
fieldsets[3][1]["fields"].extend(["commencements_json"])
fieldsets[3][1]["fields"].extend(["timeline_json"])
fieldsets[2][1]["classes"] = ("collapse",)
fieldsets[4][1]["fields"].extend(["parent_work"])
readonly_fields = ["parent_work"] + list(DocumentAdmin.readonly_fields)
Expand Down
19 changes: 15 additions & 4 deletions peachjam/js/components/DocumentContent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ class DocumentContent {
this.tocController?.addEventListener('itemTitleClicked', (e) => {
if (this.originalDocument && this.documentElement) {
const id = (e as CustomEvent).detail.target.getAttribute('href');
if (id) {
if (!id || id === '#') {
this.documentElement.replaceChildren(...Array.from(this.originalDocument.children).map(node => node.cloneNode(true)));
} else {
// @ts-ignore
const sectionOfFocus = this.originalDocument.querySelector(id)?.cloneNode(true) as HTMLElement;
if (sectionOfFocus) {
// Delete content within document element and then append section of focus
this.documentElement.replaceChildren(sectionOfFocus);
}
} else {
// @ts-ignore
this.documentElement.replaceChildren(...Array.from(this.originalDocument.children).map(node => node.cloneNode(true)));
}
}
});
Expand All @@ -196,6 +196,17 @@ class DocumentContent {
setupTocForTab () {
// If there is no toc item don't create and mount la-toc-controller
const tocItems = this.getTocItems();

if (this.root.hasAttribute('data-toc-show-active-item-only')) {
// Add a "Show full text" item to the top of the TOC when the "show active item only" option is enabled
tocItems.unshift({
tag: 'H1',
title: i18next.t('Show full text'),
id: '',
children: []
});
}

if (!tocItems.length) return false;

this.tocController = createTocController(tocItems);
Expand Down
39 changes: 34 additions & 5 deletions peachjam/js/components/DocumentContent/pdf-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,29 @@ class PdfRenderer {
const pdf = await loadingTask.promise;
this.root.removeAttribute('data-pdf-loading');

const canvas = document.createElement('canvas');

for (let i = 0; i < pdf.numPages; i++) {
const page = await pdf.getPage(i + 1);
await this.renderSinglePage(page, i, scale, containerWidth);
await this.renderSinglePage(page, i, scale, containerWidth, canvas);
if (initialPage && initialPage === i + 1) {
this.scrollToPage(i + 1);
}
}

// free up the canvas so that iOS doesn't complain about memory usage
// see https://pqina.nl/blog/total-canvas-memory-use-exceeds-the-maximum-limit/
canvas.width = 1;
canvas.height = 1;
const ctx = canvas.getContext('2d');
if (ctx) ctx.clearRect(0, 0, 1, 1);
} catch (e) {
console.log(e);
}
}

async renderSinglePage (page: any, index: number, scale: number, containerWidth: number) {
async renderSinglePage (page: any, index: number, scale: number, containerWidth: number, canvas: HTMLCanvasElement) {
const viewport = page.getViewport({ scale });
const canvas = document.createElement('canvas');
canvas.style.display = 'block';
// set the logical size of the canvas to match the scaled-up size of the viewport
canvas.width = viewport.width;
Expand All @@ -186,19 +194,40 @@ class PdfRenderer {
pageContainer.dataset.page = String(index + 1);
pageContainer.classList.add('pdf-content__page');
pageContainer.style.position = 'relative';
pageContainer.appendChild(canvas);

if (this.pdfContentWrapper) {
this.pdfContentWrapper.appendChild(pageContainer);
}

// render the page
await page.render(renderContext).promise;
// add the text layer
pageContainer.appendChild(await this.addTextLayer(page, containerWidth, canvas));
pageContainer.append(this.addImageLayer(page, containerWidth, canvas));
pageContainer.append(await this.addTextLayer(page, containerWidth, canvas));
// add image previews
this.addPreviewPanel(canvas, index + 1);
}

addImageLayer (page: any, containerWidth: number, canvas: HTMLCanvasElement) {
const image = new Image();
image.src = canvas.toDataURL('image/jpeg');

// when rendering the image layer, we want the renderer to know that we'll place the image on top
// of a canvas that has been scaled up/down to fit into the containing div; so we need to calculate
// the scale required to go from the original PDF width, to the container width.
let viewport = page.getViewport({ scale: 1 });
const textScale = containerWidth / viewport.width;
// this viewport will have the correct scale to render image to, to be placed directly over the canvas
viewport = page.getViewport({ scale: textScale });

image.style.left = `${canvas.offsetLeft}px`;
image.style.top = `${canvas.offsetTop}px`;
image.style.height = `${viewport.height}px`;
image.style.width = `${viewport.width}px`;

return image;
}

async addTextLayer (page: any, containerWidth: number, canvas: HTMLCanvasElement) {
const textLayer = document.createElement('div');
textLayer.classList.add('textLayer');
Expand Down
2 changes: 1 addition & 1 deletion peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</div>
<div class="col-md order-md-1">
<span v-if="searchInfo.count > 9999">{{ $t('More than 10,000 documents found.') }}</span>
<span v-else>{{ $t('{document_count} documents found.', { document_count: searchInfo.count }) }}</span>
<span v-else>{{ $t('{document_count} documents found', { document_count: searchInfo.count }) }}</span>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.2.20 on 2023-10-21 13:58
import logging

from django.db import migrations

log = logging.getLogger(__name__)


def delete_stubs_without_publication_documents(apps, schema_editor):
db_alias = schema_editor.connection.alias
Legislation = apps.get_model("peachjam", "Legislation")
for legislation in (
Legislation.objects.using(db_alias)
.filter(metadata_json__stub=True, source_file__isnull=True)
.order_by("-pk")
.iterator(100)
):
log.info(
f"Deleting stub with no publication document: {legislation.expression_frbr_uri}"
)
legislation.delete()


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0106_legislation_timeline_commencements"),
]

operations = [
migrations.RunPython(
delete_stubs_without_publication_documents, migrations.RunPython.noop
),
]
6 changes: 6 additions & 0 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ def __str__(self):
return self.name


class CourtRegistryManager(models.Manager):
def get_queryset(self):
return super().get_queryset().select_related("court")


class CourtRegistry(models.Model):
objects = CourtRegistryManager()
court = models.ForeignKey(
Court,
on_delete=models.CASCADE,
Expand Down
6 changes: 5 additions & 1 deletion peachjam/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ def save_m2m(self, instance, row, using_transactions, dry_run):

# attach source file, but only if it was explicitly provided during import
# the preferred source URL was set during import by the SourceFileWidget
if row.get("source_url") == instance.source_url and instance.source_url:
if (
instance.source_url
and row.get("source_url")
and instance.source_url in row.get("source_url")
):
self.attach_source_file(instance, instance.source_url)
extract_content = True

Expand Down
2 changes: 2 additions & 0 deletions peachjam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
"default": default_db_config,
"gazettes_africa": gazette_db_config,
}
CONN_MAX_AGE = int(os.environ.get("CONN_MAX_AGE", 0))

# descriptive name for this application in psql's pg_stat_activity output, to help link connections to apps
db_app_name = "-".join(
[slugify(PEACHJAM["APP_NAME"]), os.environ.get("DYNO", "django")]
Expand Down
2 changes: 1 addition & 1 deletion peachjam/static/js/app-prod.js

Large diffs are not rendered by default.

113 changes: 32 additions & 81 deletions peachjam/templates/peachjam/_timeline_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,42 @@ <h4>
{% trans 'History of this document' %}
</h4>
<div class="vertical-timeline ms-5 mt-4">
{% if timeline %}
{% for entry in timeline %}
<div class="vertical-timeline__item">
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0">
{{ entry.date|parse_string_date|date:"d F Y" }}
{% if entry.date == current_object_date %}
<span class="badge rounded-pill bg-primary">{% trans 'this version' %}</span>
{% endif %}
{% if entry.contains_unapplied_amendment %}
<span class="badge rounded-pill bg-secondary">{% trans 'amendment not yet applied' %}</span>
{% endif %}
</h5>
</div>
<div class="card-body">
{% for event in entry.events %}
<div>
{% if event.type == "publication" %}
{% if event.link_url %}
<a href="{{ event.link_url }}">{{ event.description }}</a>
{% else %}
{{ event.description }}
{% endif %}
{% else %}
{{ event.description }}
{% if event.by_frbr_uri %}<a href="{{ event.by_frbr_uri }}">{{ event.by_title }}</a>{% endif %}
{% endif %}
{% if event.note %}<p>{{ event.note }}</p>{% endif %}
</div>
{% endfor %}
{% if entry.date != current_object_date and entry.expression_frbr_uri %}
<a class="btn btn-outline-primary mt-2"
href="{{ entry.expression_frbr_uri }}">{% trans 'Read this version' %}</a>
{% for entry in timeline %}
<div class="vertical-timeline__item">
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0">
{{ entry.date|parse_string_date|date:"d F Y" }}
{% if entry.date == current_object_date %}
<span class="badge rounded-pill bg-primary">{% trans 'this version' %}</span>
{% endif %}
{% if entry.contains_unapplied_amendment %}
<span class="badge rounded-pill bg-secondary">{% trans 'amendment not yet applied' %}</span>
{% endif %}
</div>
</h5>
</div>
</div>
{% endfor %}
{% else %}
{# TODO: get rid of timeline_events once all Legislation objects have been re-ingested #}
{% for history_item in timeline_events %}
<div class="vertical-timeline__item">
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0">
{{ history_item.date|parse_string_date|date:"d F Y" }}
{% if history_item.date == current_object_date %}
<span class="badge rounded-pill bg-primary">{% trans 'this version' %}</span>
{% endif %}
{% for event in history_item.events %}
{% if event.unapplied_amendment %}
<span class="badge rounded-pill bg-secondary">{% trans 'amendment not yet applied' %}</span>
{% endif %}
{% endfor %}
</h5>
</div>
<div class="card-body">
{% for event in history_item.events %}
<div>
{% if event.event == "amendment" %}
{% trans 'Amended by' %}
<a href="{{ event.amending_uri }}"><i>{{ event.amending_title }}</i></a>
{% elif event.event == "assent" %}
{% trans 'Assented to' %}.
{% elif event.event == "commencement" %}
{% trans 'Commences' %}.
{% elif event.event == "publication" %}
{% trans 'Published in' %}
<a href="{{ event.publication_url }}">{{ event.publication_name }} {% trans 'number' %} {{ event.publication_number }}</a>
{% elif event.event == "repeal" %}
{% trans 'Repealed by' %}
<a href="{{ event.repealing_uri }}"><i>{{ event.repealing_title }}</i></a>
<div class="card-body">
{% for event in entry.events %}
<div>
{% if event.type == "publication" %}
{% if event.link_url %}
<a href="{{ event.link_url }}">{{ event.description }}</a>
{% else %}
{{ event.description }}
{% endif %}
</div>
{% endfor %}
{% if history_item.date != current_object_date %}
{% if history_item.expression_frbr_uri %}
<a class="btn btn-outline-primary mt-2"
href="{{ history_item.expression_frbr_uri }}">{% trans 'Read this version' %}</a>
{% else %}
{{ event.description }}
{% if event.by_frbr_uri %}<a href="{{ event.by_frbr_uri }}">{{ event.by_title }}</a>{% endif %}
{% endif %}
{% endif %}
</div>
{% if event.note %}<p>{{ event.note }}</p>{% endif %}
</div>
{% endfor %}
{% if entry.date != current_object_date and entry.expression_frbr_uri %}
<a class="btn btn-outline-primary mt-2"
href="{{ entry.expression_frbr_uri }}">{% trans 'Read this version' %}</a>
{% endif %}
</div>
</div>
{% endfor %}
{% endif %}
</div>
{% endfor %}
</div>
2 changes: 1 addition & 1 deletion peachjam/templates/peachjam/layouts/document_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ <h5>
</li>
{% endif %}
{% endfor %}
{% for rel in document.relationships_as_object %}
{% for rel in relationships_as_object %}
{% if rel.subject_work %}
<li>
{% translate rel.predicate.reverse_verb as verb %}
Expand Down
Loading

0 comments on commit 999d519

Please sign in to comment.