Skip to content

Commit bd4cf33

Browse files
committed
Merged in [10111] from olau@iola.dk:
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. - Legacy-Id: 10251 Note: SVN reference [10111] has been migrated to Git commit 8bca1b4
2 parents a69db3e + 8bca1b4 commit bd4cf33

14 files changed

Lines changed: 314 additions & 88 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/resources.py

Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Autogenerated by the mkresources management command 2014-12-14 19:50
1+
# Autogenerated by the makeresources management command 2015-10-19 12:29 PDT
22
from tastypie.resources import ModelResource
3-
from tastypie.fields import ToOneField, ToManyField, CharField
4-
from tastypie.constants import ALL, ALL_WITH_RELATIONS
3+
from tastypie.fields import ToOneField, ToManyField, CharField # pyflakes:ignore
4+
from tastypie.constants import ALL, ALL_WITH_RELATIONS # pyflakes:ignore
55

66
from ietf import api
77

8-
from ietf.doc.models import * # pyflakes:ignore
8+
from ietf.doc.models import * # pyflakes:ignore
99

1010

1111
from ietf.name.resources import BallotPositionNameResource, DocTypeNameResource
@@ -179,6 +179,53 @@ class Meta:
179179
}
180180
api.doc.register(StateDocEventResource())
181181

182+
from ietf.person.resources import PersonResource, EmailResource
183+
from ietf.group.resources import GroupResource
184+
from ietf.name.resources import StdLevelNameResource, StreamNameResource, DocTypeNameResource, DocTagNameResource, IntendedStdLevelNameResource
185+
class DocHistoryResource(ModelResource):
186+
type = ToOneField(DocTypeNameResource, 'type', null=True)
187+
stream = ToOneField(StreamNameResource, 'stream', null=True)
188+
group = ToOneField(GroupResource, 'group', null=True)
189+
intended_std_level = ToOneField(IntendedStdLevelNameResource, 'intended_std_level', null=True)
190+
std_level = ToOneField(StdLevelNameResource, 'std_level', null=True)
191+
ad = ToOneField(PersonResource, 'ad', null=True)
192+
shepherd = ToOneField(EmailResource, 'shepherd', null=True)
193+
doc = ToOneField(DocumentResource, 'doc')
194+
states = ToManyField(StateResource, 'states', null=True)
195+
tags = ToManyField(DocTagNameResource, 'tags', null=True)
196+
authors = ToManyField(EmailResource, 'authors', null=True)
197+
class Meta:
198+
queryset = DocHistory.objects.all()
199+
serializer = api.Serializer()
200+
#resource_name = 'dochistory'
201+
filtering = {
202+
"id": ALL,
203+
"time": ALL,
204+
"title": ALL,
205+
"abstract": ALL,
206+
"rev": ALL,
207+
"pages": ALL,
208+
"order": ALL,
209+
"expires": ALL,
210+
"notify": ALL,
211+
"external_url": ALL,
212+
"note": ALL,
213+
"internal_comments": ALL,
214+
"name": ALL,
215+
"type": ALL_WITH_RELATIONS,
216+
"stream": ALL_WITH_RELATIONS,
217+
"group": ALL_WITH_RELATIONS,
218+
"intended_std_level": ALL_WITH_RELATIONS,
219+
"std_level": ALL_WITH_RELATIONS,
220+
"ad": ALL_WITH_RELATIONS,
221+
"shepherd": ALL_WITH_RELATIONS,
222+
"doc": ALL_WITH_RELATIONS,
223+
"states": ALL_WITH_RELATIONS,
224+
"tags": ALL_WITH_RELATIONS,
225+
"authors": ALL_WITH_RELATIONS,
226+
}
227+
api.doc.register(DocHistoryResource())
228+
182229
from ietf.person.resources import PersonResource
183230
class ConsensusDocEventResource(ModelResource):
184231
by = ToOneField(PersonResource, 'by')
@@ -207,7 +254,6 @@ class Meta:
207254
serializer = api.Serializer()
208255
#resource_name = 'docalias'
209256
filtering = {
210-
"id": ALL,
211257
"name": ALL,
212258
"document": ALL_WITH_RELATIONS,
213259
}
@@ -336,6 +382,22 @@ class Meta:
336382
}
337383
api.doc.register(InitialReviewDocEventResource())
338384

385+
from ietf.person.resources import EmailResource
386+
class DocHistoryAuthorResource(ModelResource):
387+
document = ToOneField(DocHistoryResource, 'document')
388+
author = ToOneField(EmailResource, 'author')
389+
class Meta:
390+
queryset = DocHistoryAuthor.objects.all()
391+
serializer = api.Serializer()
392+
#resource_name = 'dochistoryauthor'
393+
filtering = {
394+
"id": ALL,
395+
"order": ALL,
396+
"document": ALL_WITH_RELATIONS,
397+
"author": ALL_WITH_RELATIONS,
398+
}
399+
api.doc.register(DocHistoryAuthorResource())
400+
339401
from ietf.person.resources import PersonResource
340402
class BallotDocEventResource(ModelResource):
341403
by = ToOneField(PersonResource, 'by')
@@ -375,54 +437,22 @@ class Meta:
375437
}
376438
api.doc.register(RelatedDocumentResource())
377439

378-
from ietf.person.resources import PersonResource, EmailResource
379-
from ietf.group.resources import GroupResource
380-
from ietf.name.resources import StdLevelNameResource, StreamNameResource, DocTypeNameResource, DocTagNameResource, IntendedStdLevelNameResource
381-
class DocHistoryResource(ModelResource):
382-
type = ToOneField(DocTypeNameResource, 'type', null=True)
383-
stream = ToOneField(StreamNameResource, 'stream', null=True)
384-
group = ToOneField(GroupResource, 'group', null=True)
385-
intended_std_level = ToOneField(IntendedStdLevelNameResource, 'intended_std_level', null=True)
386-
std_level = ToOneField(StdLevelNameResource, 'std_level', null=True)
387-
ad = ToOneField(PersonResource, 'ad', null=True)
388-
shepherd = ToOneField(EmailResource, 'shepherd', null=True)
389-
doc = ToOneField(DocumentResource, 'doc')
390-
states = ToManyField(StateResource, 'states', null=True)
391-
tags = ToManyField(DocTagNameResource, 'tags', null=True)
392-
related = ToManyField(DocAliasResource, 'related', null=True)
393-
authors = ToManyField(EmailResource, 'authors', null=True)
440+
from ietf.name.resources import DocRelationshipNameResource
441+
class RelatedDocHistoryResource(ModelResource):
442+
source = ToOneField(DocHistoryResource, 'source')
443+
target = ToOneField(DocAliasResource, 'target')
444+
relationship = ToOneField(DocRelationshipNameResource, 'relationship')
394445
class Meta:
395-
queryset = DocHistory.objects.all()
446+
queryset = RelatedDocHistory.objects.all()
396447
serializer = api.Serializer()
397-
#resource_name = 'dochistory'
448+
#resource_name = 'relateddochistory'
398449
filtering = {
399450
"id": ALL,
400-
"time": ALL,
401-
"title": ALL,
402-
"abstract": ALL,
403-
"rev": ALL,
404-
"pages": ALL,
405-
"order": ALL,
406-
"expires": ALL,
407-
"notify": ALL,
408-
"external_url": ALL,
409-
"note": ALL,
410-
"internal_comments": ALL,
411-
"name": ALL,
412-
"type": ALL_WITH_RELATIONS,
413-
"stream": ALL_WITH_RELATIONS,
414-
"group": ALL_WITH_RELATIONS,
415-
"intended_std_level": ALL_WITH_RELATIONS,
416-
"std_level": ALL_WITH_RELATIONS,
417-
"ad": ALL_WITH_RELATIONS,
418-
"shepherd": ALL_WITH_RELATIONS,
419-
"doc": ALL_WITH_RELATIONS,
420-
"states": ALL_WITH_RELATIONS,
421-
"tags": ALL_WITH_RELATIONS,
422-
"related": ALL_WITH_RELATIONS,
423-
"authors": ALL_WITH_RELATIONS,
451+
"source": ALL_WITH_RELATIONS,
452+
"target": ALL_WITH_RELATIONS,
453+
"relationship": ALL_WITH_RELATIONS,
424454
}
425-
api.doc.register(DocHistoryResource())
455+
api.doc.register(RelatedDocHistoryResource())
426456

427457
from ietf.person.resources import PersonResource
428458
from ietf.name.resources import BallotPositionNameResource
@@ -455,36 +485,3 @@ class Meta:
455485
}
456486
api.doc.register(BallotPositionDocEventResource())
457487

458-
from ietf.person.resources import EmailResource
459-
class DocHistoryAuthorResource(ModelResource):
460-
document = ToOneField(DocHistoryResource, 'document')
461-
author = ToOneField(EmailResource, 'author')
462-
class Meta:
463-
queryset = DocHistoryAuthor.objects.all()
464-
serializer = api.Serializer()
465-
#resource_name = 'dochistoryauthor'
466-
filtering = {
467-
"id": ALL,
468-
"order": ALL,
469-
"document": ALL_WITH_RELATIONS,
470-
"author": ALL_WITH_RELATIONS,
471-
}
472-
api.doc.register(DocHistoryAuthorResource())
473-
474-
from ietf.name.resources import DocRelationshipNameResource
475-
class RelatedDocHistoryResource(ModelResource):
476-
source = ToOneField(DocHistoryResource, 'source')
477-
target = ToOneField(DocAliasResource, 'target')
478-
relationship = ToOneField(DocRelationshipNameResource, 'relationship')
479-
class Meta:
480-
queryset = RelatedDocHistory.objects.all()
481-
serializer = api.Serializer()
482-
#resource_name = 'relateddochistory'
483-
filtering = {
484-
"id": ALL,
485-
"source": ALL_WITH_RELATIONS,
486-
"target": ALL_WITH_RELATIONS,
487-
"relationship": ALL_WITH_RELATIONS,
488-
}
489-
api.doc.register(RelatedDocHistoryResource())
490-

ietf/doc/tests_draft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ def test_change_replaces(self):
13041304
RelatedDocument.objects.create(source=self.replacea, target=self.basea.docalias_set.first(),
13051305
relationship=DocRelationshipName.objects.get(slug="possibly-replaces"))
13061306
self.assertEqual(self.basea.get_state().slug,'active')
1307-
r = self.client.post(url, dict(replaces=str(DocAlias.objects.get(name=self.basea.name).id)))
1307+
r = self.client.post(url, dict(replaces=self.basea.name))
13081308
self.assertEqual(r.status_code, 302)
13091309
self.assertEqual(RelatedDocument.objects.filter(relationship__slug='replaces',source=self.replacea).count(),1)
13101310
self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl')
@@ -1318,7 +1318,7 @@ def test_change_replaces(self):
13181318
# Post that says replaceboth replaces both base a and base b
13191319
url = urlreverse('doc_change_replaces', kwargs=dict(name=self.replaceboth.name))
13201320
self.assertEqual(self.baseb.get_state().slug,'expired')
1321-
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)))
1321+
r = self.client.post(url, dict(replaces=self.basea.name + "," + self.baseb.name))
13221322
self.assertEqual(r.status_code, 302)
13231323
self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl')
13241324
self.assertEqual(Document.objects.get(name='draft-test-base-b').get_state().slug,'repl')

0 commit comments

Comments
 (0)