Skip to content

Commit ac2b5a1

Browse files
committed
Merged in [15864] from rjsparks@nostrum.com:
Refactored DocumentInfo to address overloading the external_url field with strings that are not URLs. - Legacy-Id: 15876 Note: SVN reference [15864] has been migrated to Git commit 25cc00f
2 parents 00544eb + 25cc00f commit ac2b5a1

18 files changed

Lines changed: 143 additions & 69 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.17 on 2018-12-28 13:11
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('doc', '0007_idexists'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='dochistory',
17+
name='uploaded_filename',
18+
field=models.TextField(blank=True),
19+
),
20+
migrations.AddField(
21+
model_name='document',
22+
name='uploaded_filename',
23+
field=models.TextField(blank=True),
24+
),
25+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.17 on 2018-12-28 13:33
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
from django.db.models import F
7+
8+
def forward(apps, schema_editor):
9+
Document = apps.get_model('doc','Document')
10+
Document.objects.exclude(type_id__in=('review','recording')).update(uploaded_filename = F('external_url'))
11+
Document.objects.exclude(type_id__in=('review','recording')).update(external_url="")
12+
13+
Document.objects.filter(name='slides-100-edu-sessf-patents-at-ietf-an-overview-of-bcp79bis').update(uploaded_filename='slides-100-edu-sessf-patents-at-ietf-an-overview-of-bcp79bis-00.pdf')
14+
15+
DocHistory = apps.get_model('doc','DocHistory')
16+
DocHistory.objects.exclude(type_id__in=('review','recording')).update(uploaded_filename = F('external_url'))
17+
DocHistory.objects.exclude(type_id__in=('review','recording')).update(external_url="")
18+
19+
DocHistory.objects.filter(uploaded_filename='https://www.ietf.org/proceedings/97/slides/slides-97-edu-sessb-local-version-of-newcomers-training-in-korean-00.pdf').update(uploaded_filename='slides-97-edu-sessb-local-version-of-newcomers-training-in-korean-00.pdf')
20+
DocHistory.objects.filter(uploaded_filename='http://materials-98-codec-opus-newvectors-00.tar.gz').update(uploaded_filename='materials-98-codec-opus-newvectors-00.tar.gz')
21+
DocHistory.objects.filter(uploaded_filename='http://materials-98-codec-opus-update-00.patch').update(uploaded_filename='materials-98-codec-opus-update-00.patch')
22+
DocHistory.objects.filter(uploaded_filename='http://slides-100-edu-sessf-patents-at-ietf-an-overview-of-bcp79bis-00.pdf').update(uploaded_filename='slides-100-edu-sessf-patents-at-ietf-an-overview-of-bcp79bis-00.pdf')
23+
DocHistory.objects.filter(uploaded_filename='http://bluesheets-97-6man-201611150930-00.pdf/').update(uploaded_filename='bluesheets-97-6man-201611150930-00.pdf')
24+
DocHistory.objects.filter(uploaded_filename='http://agenda-interim-2017-stir-01-stir-01-01.txt').update(uploaded_filename='agenda-interim-2017-stir-01-stir-01-01.txt')
25+
DocHistory.objects.filter(uploaded_filename='http://agenda-interim-2017-icnrg-02-icnrg-01-05.html').update(uploaded_filename='agenda-interim-2017-icnrg-02-icnrg-01-05.html')
26+
27+
28+
def reverse(apps, schema_editor):
29+
Document = apps.get_model('doc','Document')
30+
Document.objects.exclude(type_id__in=('review','recording')).update(external_url = F('uploaded_filename'))
31+
Document.objects.exclude(type_id__in=('review','recording')).update(uploaded_filename="")
32+
33+
DocHistory = apps.get_model('doc','DocHistory')
34+
DocHistory.objects.exclude(type_id__in=('review','recording')).update(external_url = F('uploaded_filename'))
35+
DocHistory.objects.exclude(type_id__in=('review','recording')).update(uploaded_filename="")
36+
37+
38+
class Migration(migrations.Migration):
39+
40+
dependencies = [
41+
('doc', '0008_add_uploaded_filename'),
42+
]
43+
44+
operations = [
45+
migrations.RunPython(forward,reverse),
46+
]

ietf/doc/models.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,19 @@ class DocumentInfo(models.Model):
9797
shepherd = ForeignKey(Email, related_name='shepherd_%(class)s_set', blank=True, null=True)
9898
expires = models.DateTimeField(blank=True, null=True)
9999
notify = models.CharField(max_length=255, blank=True)
100-
external_url = models.URLField(blank=True) # Should be set for documents with type 'External'.
100+
external_url = models.URLField(blank=True)
101+
uploaded_filename = models.TextField(blank=True)
101102
note = models.TextField(blank=True)
102103
internal_comments = models.TextField(blank=True)
103104

104105
def file_extension(self):
105-
_,ext = os.path.splitext(self.external_url)
106-
return ext.lstrip(".").lower()
106+
if not hasattr(self, '_cached_extension'):
107+
if self.uploaded_filename:
108+
_, ext= os.path.splitext(self.uploaded_filename)
109+
self._cached_extension = ext.lstrip(".").lower()
110+
else:
111+
self._cached_extension = "txt"
112+
return self._cached_extension
107113

108114
def get_file_path(self):
109115
if not hasattr(self, '_cached_file_path'):
@@ -138,7 +144,9 @@ def get_file_path(self):
138144

139145
def get_base_name(self):
140146
if not hasattr(self, '_cached_base_name'):
141-
if self.type_id == 'draft':
147+
if self.uploaded_filename:
148+
self._cached_base_name = self.uploaded_filename
149+
elif self.type_id == 'draft':
142150
if self.is_dochistory():
143151
self._cached_base_name = "%s-%s.txt" % (self.doc.name, self.rev)
144152
else:
@@ -147,12 +155,9 @@ def get_base_name(self):
147155
else:
148156
self._cached_base_name = "%s-%s.txt" % (self.name, self.rev)
149157
elif self.type_id in ["slides", "agenda", "minutes", "bluesheets", ] and self.meeting_related():
150-
if self.external_url:
151-
# we need to remove the extension for the globbing below to work
152-
self._cached_base_name = self.external_url
153-
else:
154-
self._cached_base_name = "%s.txt" % self.canonical_name() # meeting materials are unversioned at the moment
158+
self._cached_base_name = "%s-%s.txt" % self.canonical_name()
155159
elif self.type_id == 'review':
160+
# TODO: This will be wrong if a review is updated on the same day it was created (or updated more than once on the same day)
156161
self._cached_base_name = "%s.txt" % self.name
157162
else:
158163
if self.rev:
@@ -195,15 +200,14 @@ def _get_ref(self, meeting=None, meeting_doc_refs=settings.MEETING_DOC_HREFS):
195200
# the earlier resulution order, but there's at the moment one single
196201
# instance which matches this (with correct results), so we won't
197202
# break things all over the place.
198-
# XXX TODO: move all non-URL 'external_url' values into a field which is
199-
# better named, or regularize the filename based on self.name
200203
if not hasattr(self, '_cached_href'):
201204
validator = URLValidator()
202205
if self.external_url and self.external_url.split(':')[0] in validator.schemes:
203206
try:
204207
validator(self.external_url)
205208
return self.external_url
206209
except ValidationError:
210+
log.unreachable('2018-12-28')
207211
pass
208212

209213

@@ -223,10 +227,7 @@ def _get_ref(self, meeting=None, meeting_doc_refs=settings.MEETING_DOC_HREFS):
223227
elif self.type_id in meeting_doc_refs:
224228
self.is_meeting_related = True
225229
else:
226-
if len(self.external_url):
227-
return self.external_url
228-
else:
229-
return None
230+
return None
230231

231232
if self.is_meeting_related:
232233
if not meeting:
@@ -625,7 +626,7 @@ def get_absolute_url(self):
625626
if self.type_id == 'recording':
626627
url = self.external_url
627628
else:
628-
filename = self.external_url
629+
filename = self.uploaded_filename
629630
url = '%sproceedings/%s/%s/%s' % (settings.IETF_HOST_URL,meeting.number,self.type_id,filename)
630631
else:
631632
url = urlreverse('ietf.doc.views_doc.document_main', kwargs={ 'name': name }, urlconf="ietf.urls")

ietf/doc/resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class Meta:
116116
"expires": ALL,
117117
"notify": ALL,
118118
"external_url": ALL,
119+
"uploaded_filename": ALL,
119120
"note": ALL,
120121
"internal_comments": ALL,
121122
"name": ALL,
@@ -228,6 +229,7 @@ class Meta:
228229
"expires": ALL,
229230
"notify": ALL,
230231
"external_url": ALL,
232+
"uploaded_filename": ALL,
231233
"note": ALL,
232234
"internal_comments": ALL,
233235
"name": ALL,

ietf/doc/views_doc.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,9 @@ def document_main(request, name, rev=None):
549549
if doc.type_id in ("slides", "agenda", "minutes", "bluesheets",):
550550
can_manage_material = can_manage_materials(request.user, doc.group)
551551
presentations = doc.future_presentations()
552-
if doc.meeting_related():
553-
basename = doc.canonical_name() # meeting materials are unversioned at the moment
554-
if doc.external_url:
555-
# we need to remove the extension for the globbing below to work
556-
basename = os.path.splitext(doc.external_url)[0]
552+
if doc.uploaded_filename:
553+
# we need to remove the extension for the globbing below to work
554+
basename = os.path.splitext(doc.uploaded_filename)[0]
557555
else:
558556
basename = "%s-%s" % (doc.canonical_name(), doc.rev)
559557

ietf/liaisons/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def save_attachments(self):
366366
defaults=dict(
367367
title = attachment_title,
368368
type_id = "liai-att",
369-
external_url = name + extension, # strictly speaking not necessary, but just for the time being ...
369+
uploaded_filename = name + extension,
370370
)
371371
)
372372
if created:

ietf/liaisons/tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def test_edit_liaison(self):
432432
self.assertEqual(new_liaison.attachments.count(), attachments_before + 1)
433433
attachment = new_liaison.attachments.order_by("-name")[0]
434434
self.assertEqual(attachment.title, "attachment")
435-
with open(os.path.join(self.liaison_dir, attachment.external_url)) as f:
435+
with open(os.path.join(self.liaison_dir, attachment.uploaded_filename)) as f:
436436
written_content = f.read()
437437

438438
test_file.seek(0)
@@ -736,7 +736,7 @@ def test_add_incoming_liaison(self):
736736
self.assertEqual(l.attachments.count(), 1)
737737
attachment = l.attachments.all()[0]
738738
self.assertEqual(attachment.title, "attachment")
739-
with open(os.path.join(self.liaison_dir, attachment.external_url)) as f:
739+
with open(os.path.join(self.liaison_dir, attachment.uploaded_filename)) as f:
740740
written_content = f.read()
741741

742742
test_file.seek(0)
@@ -815,7 +815,7 @@ def test_add_outgoing_liaison(self):
815815
self.assertEqual(l.attachments.count(), 1)
816816
attachment = l.attachments.all()[0]
817817
self.assertEqual(attachment.title, "attachment")
818-
with open(os.path.join(self.liaison_dir, attachment.external_url)) as f:
818+
with open(os.path.join(self.liaison_dir, attachment.uploaded_filename)) as f:
819819
written_content = f.read()
820820

821821
test_file.seek(0)

ietf/meeting/feeds.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ class LatestMeetingMaterialFeed(Feed):
1515

1616
def items(self):
1717
objs = []
18+
# FIXME: why aren't other materials types in here?
1819
for doc in Document.objects.filter(type__in=("agenda", "minutes", "slides")).order_by('-time')[:60]:
1920
obj = dict(
2021
title=doc.type_id,
2122
group_acronym=doc.name.split("-")[2],
2223
date=doc.time,
23-
link=self.base_url + os.path.join(doc.get_file_path(), doc.external_url)[len(settings.AGENDA_PATH):],
24+
# FIXME: why isn't this using gref or href?
25+
link=self.base_url + os.path.join(doc.get_file_path(), doc.uploaded_filename)[len(settings.AGENDA_PATH):],
2426
author=""
2527
)
2628
objs.append(obj)

ietf/meeting/forms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ def save_agenda(self):
267267
group=self.group,
268268
name=filename,
269269
rev='00',
270-
external_url='{}-00.txt'.format(filename))
270+
# FIXME: if these are always computed, they shouldn't be in uploaded_filename - just compute them when needed
271+
# FIXME: What about agendas in html or markdown format?
272+
uploaded_filename='{}-00.txt'.format(filename))
271273
doc.set_state(State.objects.get(type__slug=doc.type.slug, slug='active'))
272274
DocAlias.objects.create(name=doc.name, document=doc)
273275
self.instance.sessionpresentation_set.create(document=doc, rev=doc.rev)

ietf/meeting/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ def read_session_file(type, num, doc):
208208
# style python format, something like this:
209209
# DOC_PATH_FORMAT = { "agenda": "/foo/bar/agenda-{meeting.number}/agenda-{meeting-number}-{doc.group}*", }
210210
#
211-
path = os.path.join(settings.AGENDA_PATH, "%s/%s/%s" % (num, type, doc.external_url))
211+
# FIXME: uploaded_filename should be replaced with a function call that computes names that are fixed
212+
path = os.path.join(settings.AGENDA_PATH, "%s/%s/%s" % (num, type, doc.uploaded_filename))
212213
if os.path.exists(path):
213214
with open(path) as f:
214215
return f.read(), path

0 commit comments

Comments
 (0)