-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cause Document object urls to point to /media/filename instead of to …
…/document/doc_id/filename. This is a workaround for a wart in wagtail that insists on serving documents as attachments. It is a mild compromise in that the proported inside wagtail features of counting document references and controlling access to files is circumvented. However, by design, we don't want different access controls to files for different viewers of the IETF website, and we are looking at different ways to gather information like references. See wagtail/wagtail#4359, wagtail/wagtail#1158, and the knot at wagtail/wagtail#1420.
- Loading branch information
Showing
12 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DocumentsConfig(AppConfig): | ||
name = 'documents' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-06-07 16:27 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('wagtaildocs', '0008_document_file_size'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='IetfDocument', | ||
fields=[ | ||
('document_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtaildocs.Document')), | ||
], | ||
options={ | ||
'verbose_name': 'document', | ||
'abstract': False, | ||
}, | ||
bases=('wagtaildocs.document',), | ||
), | ||
] |
30 changes: 30 additions & 0 deletions
30
ietf/documents/migrations/0002_connect_ietfdocument_to_document.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.21 on 2019-06-07 20:32 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, connection, transaction | ||
|
||
from wagtail.documents.models import Document | ||
|
||
def forward(apps, schema_editor): | ||
IetfDocument = apps.get_model('documents', 'IetfDocument') | ||
|
||
# See https://stackoverflow.com/questions/4298278/django-using-custom-raw-sql-inserts-with-executemany-and-mysql | ||
cursor = connection.cursor() | ||
query = ' INSERT INTO documents_ietfdocument (document_ptr_id) values (%s) ' | ||
queryList = Document.objects.values_list('pk') | ||
cursor.executemany(query,queryList) | ||
# transaction.commit() | ||
|
||
def reverse(apps, schema_editor): | ||
pass | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('documents', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forward,reverse) | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# See https://stackoverflow.com/questions/4298278/django-using-custom-raw-sql-inserts-with-executemany-and-mysql | ||
In [8]: from django.db import connection,transaction | ||
|
||
In [9]: cursor = connection.cursor() | ||
|
||
In [10]: query = ''' INSERT INTO documents_ietfdocument (document_ptr_id) values | ||
...: (%s) ''' | ||
|
||
In [15]: queryList = Document.objects.values_list('pk') | ||
|
||
In [16]: cursor.executemany(query,queryList) | ||
|
||
In [17]: transaction.commit() | ||
|
||
In [18]: IetfDocument.objects.count() | ||
Out[18]: 286 | ||
|
||
In [19]: quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
|
||
from wagtail.documents.models import Document | ||
|
||
class IetfDocument(Document): | ||
|
||
@property | ||
def url(self): | ||
return self.file.url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% load i18n %} | ||
<table class="listing"> | ||
<col /> | ||
<col /> | ||
<col width="16%" /> | ||
<thead> | ||
<tr class="table-headers"> | ||
<th> | ||
{% if not is_searching %} | ||
<a href="{% url 'wagtaildocs:index' %}{% if not ordering == "title" %}?ordering=title{% endif %}" class="icon icon-arrow-down-after {% if ordering == "title" %}teal{% endif %}"> | ||
{% trans "Title" %} | ||
</a> | ||
{% else %} | ||
{% trans "Title" %} | ||
{% endif %} | ||
</th> | ||
<th>{% trans "File" %}</th> | ||
<th> | ||
{% if not is_searching %} | ||
<a href="{% url 'wagtaildocs:index' %}{% if not ordering == "-created_at" %}?ordering=-created_at{% endif %}" class="icon icon-arrow-down-after {% if ordering == "-created_at" %}teal{% endif %}"> | ||
{% trans "Uploaded" %} | ||
</a> | ||
{% else %} | ||
{% trans "Uploaded" %} | ||
{% endif %} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for doc in documents %} | ||
<tr> | ||
<td class="title"> | ||
{% if choosing %} | ||
<h2><a href="{% url 'wagtaildocs:document_chosen' doc.id %}" class="document-choice">{{ doc.title }}</a></h2> | ||
{% else %} | ||
<h2><a href="{% url 'wagtaildocs:edit' doc.id %}">{{ doc.title }}</a></h2> | ||
{% endif %} | ||
</td> | ||
<td><a href="{{ doc.url }}" class="nolink">{{ doc.filename }}</a></td> | ||
<td><div class="human-readable-date" title="{{ doc.created_at|date:"d M Y H:i" }}">{% blocktrans with time_period=doc.created_at|timesince %}{{ time_period }} ago{% endblocktrans %}</div></td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters