Skip to content

Commit 316dd18

Browse files
committed
first run at external resources
- Legacy-Id: 17470
1 parent 53de504 commit 316dd18

23 files changed

Lines changed: 459 additions & 2 deletions

ietf/doc/migrations/0032_extres.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.29 on 2020-03-19 13:56
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+
('extresource', '0001_extres'),
15+
('doc', '0031_set_state_for_charters_of_replaced_groups'),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name='DocExtResource',
21+
fields=[
22+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23+
('doc', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='doc.Document')),
24+
('extresource', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='extresource.ExtResource')),
25+
],
26+
),
27+
]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.29 on 2020-03-19 13:06
4+
from __future__ import unicode_literals
5+
6+
import re
7+
8+
import debug
9+
10+
from django.db import migrations
11+
12+
"""
13+
This makes me very nervous:
14+
15+
>>> DocumentURL.objects.filter(desc__icontains='notifications').values_list('tag',flat=True).distinct()
16+
<QuerySet ['yang-impact-analysis', 'yang-module-metadata']>
17+
18+
I suspect the wrong thing is happening with the map below wrt the GitHub notificaitons string.
19+
20+
"""
21+
22+
name_map = {
23+
"Issue.*": "tracker",
24+
".*FAQ.*": "faq",
25+
".*Area Web Page": "webpage",
26+
".*Wiki": "wiki",
27+
"Home Page": "webpage",
28+
"Slack.*": "slack",
29+
"Additional .* Web Page": "webpage",
30+
"Additional .* Page": "webpage",
31+
"Yang catalog entry.*": "yc_entry",
32+
"Yang impact analysis.*": "yc_impact",
33+
"GitHub": "github_repo",
34+
"Github page": "github_repo",
35+
"GitHub repo.*": "github_repo",
36+
"Github repository.*": "github_repo",
37+
"GitHub notifications": "github_notify",
38+
"GitHub org.*": "github_org",
39+
"GitHub User.*": "github_username",
40+
"GitLab User": "gitlab_username",
41+
"GitLab User Name": "gitlab_username",
42+
}
43+
44+
def forward(apps, schema_editor):
45+
DocExtResource = apps.get_model('doc', 'DocExtResource')
46+
ExtResource = apps.get_model('extresource', 'ExtResource')
47+
ExtResourceName = apps.get_model('name', 'ExtResourceName')
48+
DocumentUrl = apps.get_model('doc', 'DocumentUrl')
49+
50+
mapped = 0
51+
not_mapped = 0
52+
53+
for doc_url in DocumentUrl.objects.all():
54+
match_found = False
55+
for regext,slug in name_map.items():
56+
if re.match(regext, doc_url.desc):
57+
match_found = True
58+
mapped += 1
59+
name = ExtResourceName.objects.get(slug=slug)
60+
ext_res = ExtResource.objects.create(name_id=slug, value= doc_url.url) # TODO: validate this value against name.type
61+
DocExtResource.objects.create(doc=doc_url.doc, extresource=ext_res)
62+
break
63+
if not match_found:
64+
debug.show('("Not Mapped:",doc_url.desc, doc_url.tag.slug, doc_url.doc.name, doc_url.url)')
65+
not_mapped += 1
66+
debug.show('(mapped, not_mapped)')
67+
68+
def reverse(apps, schema_editor):
69+
DocExtResource = apps.get_model('doc', 'DocExtResource')
70+
DocExtResource.objects.all().delete()
71+
72+
class Migration(migrations.Migration):
73+
74+
dependencies = [
75+
('doc', '0032_extres'),
76+
('extresource', '0001_extres'),
77+
('name', '0011_populate_extres'),
78+
]
79+
80+
operations = [
81+
migrations.RunPython(forward, reverse)
82+
]

ietf/doc/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import debug # pyflakes:ignore
2424

25+
from ietf.extresource.models import ExtResource
2526
from ietf.group.models import Group
2627
from ietf.name.models import ( DocTypeName, DocTagName, StreamName, IntendedStdLevelName, StdLevelName,
2728
DocRelationshipName, DocReminderTypeName, BallotPositionName, ReviewRequestStateName, ReviewAssignmentStateName, FormalLanguageName,
@@ -108,6 +109,7 @@ class DocumentInfo(models.Model):
108109
note = models.TextField(blank=True)
109110
internal_comments = models.TextField(blank=True)
110111

112+
111113
def file_extension(self):
112114
if not hasattr(self, '_cached_extension'):
113115
if self.uploaded_filename:
@@ -861,6 +863,10 @@ class DocumentURL(models.Model):
861863
desc = models.CharField(max_length=255, default='', blank=True)
862864
url = models.URLField(max_length=2083) # 2083 is the legal max for URLs
863865

866+
class DocExtResource(models.Model):
867+
doc = ForeignKey(Document) # Should this really be to DocumentInfo rather than Document?
868+
extresource = ForeignKey(ExtResource)
869+
864870
@python_2_unicode_compatible
865871
class RelatedDocHistory(models.Model):
866872
source = ForeignKey('DocHistory')

ietf/extresource/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved

ietf/extresource/admin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
from django.contrib import admin
3+
4+
# Register your models here.

ietf/extresource/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
from django.apps import AppConfig
3+
4+
5+
class ExtresourceConfig(AppConfig):
6+
name = 'extresource'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright The IETF Trust ... 2020, All Rights Reserved
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright The IETF Trust ... 2020, All Rights Reserved
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
import json
3+
4+
from django.core.management.base import BaseCommand
5+
from django.db.models import Q
6+
7+
from ietf.extresource.models import ExtResource
8+
from ietf.doc.models import DocExtResource
9+
from ietf.group.models import GroupExtResource
10+
from ietf.person.models import PersonExtResource
11+
12+
class Command(BaseCommand):
13+
help = ('Locate information about gihub repositories to backup')
14+
15+
def handle(self, *args, **options):
16+
17+
info_dict = {}
18+
for repo in ExtResource.objects.filter(name__slug='github_repo'):
19+
if repo not in info_dict:
20+
info_dict[repo.value] = []
21+
22+
for username in DocExtResource.objects.filter(extresource__name__slug='github_username', doc__name__in=repo.docextresource_set.values_list('doc__name',flat=True).distinct()):
23+
info_dict[repo.value].push(username.value)
24+
25+
for username in GroupExtResource.objects.filter(extresource__name__slug='github_username', group__acronym__in=repo.groupextresource_set.values_list('group__acronym',flat=True).distinct()):
26+
info_dict[repo.value].push(username.value)
27+
28+
for username in PersonExtResource.objects.filter(extresource__name__slug='github_username', person_id__in=repo.personextresource_set.values_list('person__id',flat=True).distinct()):
29+
info_dict[repo.value].push(username.value)
30+
31+
print (json.dumps(info_dict))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.29 on 2020-03-19 13:56
4+
from __future__ import unicode_literals
5+
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
initial = True
13+
14+
dependencies = [
15+
('name', '0010_extres'),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name='ExtResource',
21+
fields=[
22+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23+
('value', models.CharField(max_length=2083)),
24+
('name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='name.ExtResourceName')),
25+
],
26+
),
27+
]

0 commit comments

Comments
 (0)