Skip to content

Commit 8bca1b4

Browse files
committed
Summary: Make name the primary key for DocAlias.
This fixes Javascript widgets working with DocAliases, such as the replaces field in draft submission, to work better with Javascript disabled. It also makes sense from a modelling perspective as the name really is a unique key for the alias. The actual transformation requires a series of migrations taking a couple of minutes to complete. The actual switch to the key is done at the end. Branch ready for merge. - Legacy-Id: 10111
1 parent f2445e9 commit 8bca1b4

13 files changed

Lines changed: 236 additions & 7 deletions

ietf/doc/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class DocHistoryAdmin(admin.ModelAdmin):
105105
list_display = ['doc', 'rev', 'state', 'group', 'pages', 'intended_std_level', 'author_list', 'time']
106106
search_fields = ['doc__name']
107107
ordering = ['time', 'doc', 'rev']
108-
raw_id_fields = ['doc', 'authors', 'related', 'group', 'shepherd', 'ad']
108+
raw_id_fields = ['doc', 'authors', 'group', 'shepherd', 'ad']
109109

110110
def state(self, instance):
111111
return instance.get_state()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('doc', '0005_auto_20150721_0230'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='dochistory',
16+
name='related',
17+
),
18+
migrations.AddField(
19+
model_name='relateddochistory',
20+
name='target_name',
21+
field=models.CharField(default=b'', max_length=255),
22+
preserve_default=True,
23+
),
24+
migrations.AddField(
25+
model_name='relateddocument',
26+
name='target_name',
27+
field=models.CharField(default=b'', max_length=255),
28+
preserve_default=True,
29+
),
30+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations
5+
import django.db
6+
7+
def fill_in_docalias_relationship_names(apps, schema_editor):
8+
with django.db.connection.cursor() as cursor:
9+
cursor.execute("update doc_relateddocument join doc_docalias on doc_docalias.id = doc_relateddocument.target_id set doc_relateddocument.target_name = doc_docalias.name;")
10+
cursor.execute("update doc_relateddochistory join doc_docalias on doc_docalias.id = doc_relateddochistory.target_id set doc_relateddochistory.target_name = doc_docalias.name;")
11+
12+
def noop(apps, schema_editor):
13+
pass
14+
15+
class Migration(migrations.Migration):
16+
17+
dependencies = [
18+
('doc', '0006_auto_20150929_0828'),
19+
]
20+
21+
operations = [
22+
migrations.RunPython(fill_in_docalias_relationship_names, noop)
23+
]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('doc', '0007_auto_20150929_0840'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='relateddochistory',
16+
name='target',
17+
),
18+
migrations.RenameField(
19+
model_name='relateddochistory',
20+
old_name='target_name',
21+
new_name='target',
22+
),
23+
migrations.RemoveField(
24+
model_name='relateddocument',
25+
name='target',
26+
),
27+
migrations.RenameField(
28+
model_name='relateddocument',
29+
old_name='target_name',
30+
new_name='target',
31+
),
32+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('doc', '0008_auto_20150930_0242'),
11+
('ipr', '0006_auto_20150930_0235'),
12+
]
13+
14+
operations = [
15+
migrations.RemoveField(
16+
model_name='docalias',
17+
name='id',
18+
),
19+
migrations.AlterField(
20+
model_name='docalias',
21+
name='name',
22+
field=models.CharField(max_length=255, serialize=False, primary_key=True),
23+
preserve_default=True,
24+
),
25+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('doc', '0009_auto_20150930_0248'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='relateddochistory',
16+
name='target',
17+
field=models.ForeignKey(related_name='reversely_related_document_history_set', to='doc.DocAlias'),
18+
preserve_default=True,
19+
),
20+
migrations.AlterField(
21+
model_name='relateddocument',
22+
name='target',
23+
field=models.ForeignKey(to='doc.DocAlias'),
24+
preserve_default=True,
25+
),
26+
]

ietf/doc/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ class Meta:
367367

368368
class Document(DocumentInfo):
369369
name = models.CharField(max_length=255, primary_key=True) # immutable
370-
#related = models.ManyToManyField('DocAlias', through=RelatedDocument, blank=True, related_name="reversely_related_document_set")
371370
authors = models.ManyToManyField(Email, through=DocumentAuthor, blank=True)
372371

373372
def __unicode__(self):
@@ -540,7 +539,6 @@ class DocHistory(DocumentInfo):
540539
# canonical_name and replace the function on Document with a
541540
# property
542541
name = models.CharField(max_length=255)
543-
related = models.ManyToManyField('DocAlias', through=RelatedDocHistory, blank=True)
544542
authors = models.ManyToManyField(Email, through=DocHistoryAuthor, blank=True)
545543
def __unicode__(self):
546544
return unicode(self.doc.name)
@@ -620,8 +618,8 @@ class DocAlias(models.Model):
620618
same immutable Document.name, in the tables, but will be referred
621619
to by RFC number, primarily, after achieving RFC status.
622620
"""
621+
name = models.CharField(max_length=255, primary_key=True)
623622
document = models.ForeignKey(Document)
624-
name = models.CharField(max_length=255, db_index=True)
625623
def __unicode__(self):
626624
return "%s-->%s" % (self.name, self.document.name)
627625
document_link = admin_link("document")

ietf/doc/tests_draft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ def test_change_replaces(self):
12581258
RelatedDocument.objects.create(source=self.replacea, target=self.basea.docalias_set.first(),
12591259
relationship=DocRelationshipName.objects.get(slug="possibly-replaces"))
12601260
self.assertEqual(self.basea.get_state().slug,'active')
1261-
r = self.client.post(url, dict(replaces=str(DocAlias.objects.get(name=self.basea.name).id)))
1261+
r = self.client.post(url, dict(replaces=self.basea.name))
12621262
self.assertEqual(r.status_code, 302)
12631263
self.assertEqual(RelatedDocument.objects.filter(relationship__slug='replaces',source=self.replacea).count(),1)
12641264
self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl')
@@ -1267,7 +1267,7 @@ def test_change_replaces(self):
12671267
# Post that says replaceboth replaces both base a and base b
12681268
url = urlreverse('doc_change_replaces', kwargs=dict(name=self.replaceboth.name))
12691269
self.assertEqual(self.baseb.get_state().slug,'expired')
1270-
r = self.client.post(url, dict(replaces=str(DocAlias.objects.get(name=self.basea.name).id) + "," + str(DocAlias.objects.get(name=self.baseb.name).id)))
1270+
r = self.client.post(url, dict(replaces=self.basea.name + "," + self.baseb.name))
12711271
self.assertEqual(r.status_code, 302)
12721272
self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl')
12731273
self.assertEqual(Document.objects.get(name='draft-test-base-b').get_state().slug,'repl')

ietf/idindex/tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def get_fields(content):
124124

125125
e = LastCallDocEvent.objects.create(doc=draft, type="sent_last_call", expires=datetime.datetime.now() + datetime.timedelta(days=14), by=draft.ad)
126126

127-
DocAlias.objects.create(name="rfc1234", document=draft)
128127
t = get_fields(all_id2_txt())
129128
self.assertEqual(t[11], e.expires.strftime("%Y-%m-%d"))
130129

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('ipr', '0003_auto_20150430_0847'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='iprdocrel',
16+
name='document_name',
17+
field=models.CharField(default=b'', max_length=255),
18+
preserve_default=True,
19+
),
20+
]

0 commit comments

Comments
 (0)