Skip to content

Commit 426870b

Browse files
committed
Merged in the Document and DocAlias primary key change and m2m work in ^/personal/henrik/6.96.1-docalias.
- Legacy-Id: 16261
2 parents df08d82 + 83efb34 commit 426870b

126 files changed

Lines changed: 5058 additions & 338 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/.settings
2323
/.tmp
2424
/.factoryboy_random_state
25+
/attic
2526
/bin
2627
/etc
2728
/ghostdriver.log

bin/add-old-drafts-from-archive.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# Copyright The IETF Trust 2017-2019, All Rights Reserved
23

34
import datetime
45
import os
@@ -79,7 +80,7 @@
7980
words=draft.get_wordcount(),
8081
expires=time+datetime.timedelta(settings.INTERNET_DRAFT_DAYS_TO_EXPIRE),
8182
)
82-
doc.docalias_set.create(name=doc.name)
83+
DocAlias.objects.create(name=doc.name).docs.add(doc)
8384
doc.states.add(expired)
8485
# update authors
8586
authors = []
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-21 14:23
4+
from __future__ import unicode_literals
5+
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
import ietf.utils.models
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
dependencies = [
14+
('community', '0002_auto_20180220_1052'),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='CommunityListDocs',
20+
fields=[
21+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('communitylist', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='community.CommunityList')),
23+
('document', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='doc.Document', to_field=b'id')),
24+
],
25+
),
26+
migrations.AddField(
27+
model_name='communitylist',
28+
name='added_docs2',
29+
field=models.ManyToManyField(related_name='communitylists', through='community.CommunityListDocs', to='doc.Document'),
30+
),
31+
migrations.CreateModel(
32+
name='SearchRuleDocs',
33+
fields=[
34+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
35+
('document', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='doc.Document', to_field=b'id')),
36+
('searchrule', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='community.SearchRule')),
37+
],
38+
),
39+
migrations.AddField(
40+
model_name='searchrule',
41+
name='name_contains_index2',
42+
field=models.ManyToManyField(related_name='searchrules', through='community.SearchRuleDocs', to='doc.Document'),
43+
),
44+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-21 14:27
4+
from __future__ import unicode_literals
5+
6+
import sys
7+
8+
from tqdm import tqdm
9+
10+
from django.db import migrations
11+
12+
13+
def forward(apps, schema_editor):
14+
15+
Document = apps.get_model('doc','Document')
16+
CommunityList = apps.get_model('community', 'CommunityList')
17+
CommunityListDocs = apps.get_model('community', 'CommunityListDocs')
18+
SearchRule = apps.get_model('community', 'SearchRule')
19+
SearchRuleDocs = apps.get_model('community', 'SearchRuleDocs')
20+
21+
# Document id fixup ------------------------------------------------------------
22+
23+
objs = Document.objects.in_bulk()
24+
nameid = { o.name: o.id for id, o in objs.iteritems() }
25+
26+
sys.stderr.write('\n')
27+
28+
sys.stderr.write(' %s.%s:\n' % (CommunityList.__name__, 'added_docs'))
29+
count = 0
30+
for l in tqdm(CommunityList.objects.all()):
31+
for d in l.added_docs.all():
32+
count += 1
33+
CommunityListDocs.objects.get_or_create(communitylist=l, document_id=nameid[d.name])
34+
sys.stderr.write(' %s CommunityListDocs objects created\n' % (count, ))
35+
36+
sys.stderr.write(' %s.%s:\n' % (SearchRule.__name__, 'name_contains_index'))
37+
count = 0
38+
for r in tqdm(SearchRule.objects.all()):
39+
for d in r.name_contains_index.all():
40+
count += 1
41+
SearchRuleDocs.objects.get_or_create(searchrule=r, document_id=nameid[d.name])
42+
sys.stderr.write(' %s SearchRuleDocs objects created\n' % (count, ))
43+
44+
def reverse(apps, schema_editor):
45+
pass
46+
47+
class Migration(migrations.Migration):
48+
49+
dependencies = [
50+
('community', '0003_add_communitylist_docs2_m2m'),
51+
('doc', '0014_set_document_docalias_id'),
52+
]
53+
54+
operations = [
55+
migrations.RunPython(forward, reverse),
56+
]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-22 08:15
4+
from __future__ import unicode_literals
5+
6+
from django.db import migrations
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('community', '0004_set_document_m2m_keys'),
13+
]
14+
15+
# The implementation of AlterField in Django 1.11 applies
16+
# 'ALTER TABLE <table> MODIFY <field> ...;' in order to fix foregn keys
17+
# to the altered field, but as it seems does _not_ fix up m2m
18+
# intermediary tables in an equivalent manner, so here we remove and
19+
# then recreate the m2m tables so they will have the appropriate field
20+
# types.
21+
22+
operations = [
23+
# Remove fields
24+
migrations.RemoveField(
25+
model_name='communitylist',
26+
name='added_docs',
27+
),
28+
migrations.RemoveField(
29+
model_name='searchrule',
30+
name='name_contains_index',
31+
),
32+
]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-22 08:15
4+
from __future__ import unicode_literals
5+
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('community', '0005_1_del_docs_m2m_table'),
13+
]
14+
15+
# The implementation of AlterField in Django 1.11 applies
16+
# 'ALTER TABLE <table> MODIFY <field> ...;' in order to fix foregn keys
17+
# to the altered field, but as it seems does _not_ fix up m2m
18+
# intermediary tables in an equivalent manner, so here we remove and
19+
# then recreate the m2m tables so they will have the appropriate field
20+
# types.
21+
22+
operations = [
23+
# Add fields back (will create the m2m tables with the right field types)
24+
migrations.AddField(
25+
model_name='communitylist',
26+
name='added_docs',
27+
field=models.ManyToManyField(to='doc.Document'),
28+
),
29+
migrations.AddField(
30+
model_name='searchrule',
31+
name='name_contains_index',
32+
field=models.ManyToManyField(to='doc.Document'),
33+
),
34+
]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-27 05:56
4+
from __future__ import unicode_literals
5+
6+
from django.db import migrations
7+
8+
import sys, time
9+
10+
from tqdm import tqdm
11+
12+
13+
def forward(apps, schema_editor):
14+
15+
CommunityList = apps.get_model('community', 'CommunityList')
16+
CommunityListDocs = apps.get_model('community', 'CommunityListDocs')
17+
SearchRule = apps.get_model('community', 'SearchRule')
18+
SearchRuleDocs = apps.get_model('community', 'SearchRuleDocs')
19+
20+
# Document id fixup ------------------------------------------------------------
21+
22+
23+
sys.stderr.write('\n')
24+
25+
sys.stderr.write(' %s.%s:\n' % (CommunityList.__name__, 'added_docs'))
26+
for l in tqdm(CommunityList.objects.all()):
27+
l.added_docs.set([ d.document for d in CommunityListDocs.objects.filter(communitylist=l) ])
28+
29+
sys.stderr.write(' %s.%s:\n' % (SearchRule.__name__, 'name_contains_index'))
30+
for r in tqdm(SearchRule.objects.all()):
31+
r.name_contains_index.set([ d.document for d in SearchRuleDocs.objects.filter(searchrule=r) ])
32+
33+
def reverse(apps, schema_editor):
34+
pass
35+
36+
def timestamp(apps, schema_editor):
37+
sys.stderr.write('\n %s' % time.strftime('%Y-%m-%d %H:%M:%S'))
38+
39+
class Migration(migrations.Migration):
40+
41+
dependencies = [
42+
('community', '0005_2_add_docs_m2m_table'),
43+
]
44+
45+
operations = [
46+
#migrations.RunPython(forward, reverse),
47+
# Alternative:
48+
migrations.RunPython(timestamp, timestamp),
49+
migrations.RunSQL(
50+
"INSERT INTO community_communitylist_added_docs SELECT * FROM community_communitylistdocs;",
51+
""),
52+
migrations.RunPython(timestamp, timestamp),
53+
migrations.RunSQL(
54+
"INSERT INTO community_searchrule_name_contains_index SELECT * FROM community_searchruledocs;",
55+
""),
56+
migrations.RunPython(timestamp, timestamp),
57+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright The IETF Trust 2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-30 03:06
4+
from __future__ import unicode_literals
5+
6+
from django.db import migrations
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('community', '0006_copy_docs_m2m_table'),
13+
]
14+
15+
operations = [
16+
migrations.RemoveField(
17+
model_name='communitylistdocs',
18+
name='communitylist',
19+
),
20+
migrations.RemoveField(
21+
model_name='communitylistdocs',
22+
name='document',
23+
),
24+
migrations.RemoveField(
25+
model_name='searchruledocs',
26+
name='document',
27+
),
28+
migrations.RemoveField(
29+
model_name='searchruledocs',
30+
name='searchrule',
31+
),
32+
migrations.RemoveField(
33+
model_name='communitylist',
34+
name='added_docs2',
35+
),
36+
migrations.RemoveField(
37+
model_name='searchrule',
38+
name='name_contains_index2',
39+
),
40+
migrations.DeleteModel(
41+
name='CommunityListDocs',
42+
),
43+
migrations.DeleteModel(
44+
name='SearchRuleDocs',
45+
),
46+
]

ietf/community/tests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright The IETF Trust 2016-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
14
import json
25

36
from pyquery import PyQuery
@@ -107,7 +110,7 @@ def test_manage_personal_list(self):
107110
self.assertEqual(r.status_code, 200)
108111

109112
# add document
110-
r = self.client.post(url, { "action": "add_documents", "documents": draft.pk })
113+
r = self.client.post(url, { "action": "add_documents", "documents": draft.name })
111114
self.assertEqual(r.status_code, 302)
112115
clist = CommunityList.objects.get(user__username="plain")
113116
self.assertTrue(clist.added_docs.filter(pk=draft.pk))
@@ -118,7 +121,7 @@ def test_manage_personal_list(self):
118121
self.assertTrue(draft.name in unicontent(r))
119122

120123
# remove document
121-
r = self.client.post(url, { "action": "remove_document", "document": draft.pk })
124+
r = self.client.post(url, { "action": "remove_document", "document": draft.name })
122125
self.assertEqual(r.status_code, 302)
123126
clist = CommunityList.objects.get(user__username="plain")
124127
self.assertTrue(not clist.added_docs.filter(pk=draft.pk))

ietf/community/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright The IETF Trust 2016-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
14
import re
25

36
from django.db.models import Q
@@ -61,7 +64,7 @@ def augment_docs_with_tracking_info(docs, user):
6164
if user and user.is_authenticated:
6265
clist = CommunityList.objects.filter(user=user).first()
6366
if clist:
64-
tracked.update(docs_tracked_by_community_list(clist).filter(pk__in=docs).values_list("pk", flat=True))
67+
tracked.update(docs_tracked_by_community_list(clist).filter(pk__in=[ d.pk for d in docs ]).values_list("pk", flat=True))
6568

6669
for d in docs:
6770
d.tracked_in_personal_community_list = d.pk in tracked

0 commit comments

Comments
 (0)