Skip to content

Commit e678659

Browse files
committed
Merged in a lot of shim-layer removals from olau@iola.dk
(-r5194:5465 from branch/iola/shimfree). Copying relevant commit messages here: - Removed .related many to many relationship, it's not really useful since we always have to restrict on the relationship type anyway, instead add two helpers for doing the necessary queries (in both directions) - Added migration for transforming the .desc on the new_revision events into something more akin to what is actually shown in the history page - Added migration for blanking IESG notes that just consist of "RFC XXXX", these have been superfluous for some time - Grant stream chairs access to changing the stream on a draft - Hacked the format_history_text filter to be less weird, using the same formatting for snippets and full text, also link up legacy ballot set events - Moved the decoraters + utilities to new ietfauth/utils.py file - Added simple helper to Email to identify invalid email addresses (from legacy author entries) - Used new new_revision .desc format for when drafts are submitted - Improved the looks of the button class by adding extra contrast and a linear gradient. Currently the gradient is only visible in fairly recent browsers. - Rewrote draft and RFC tabs in terms of the new schema, porting write-up and history tabs as well - Fixed two bugs in RFC Editor syncing: make sure documents we don't know beforehand get a "draft" type and make sure individually submitted drafts get the type="individ" group instead of NULL - Made the CSS-styled button feel a bit nicer to use by flattening the active state, also introduce some temporary styles until browsers catch up with the standard syntax - Added migrations for fixing 1) a dummy RFC entry, 2) three stand-alone RFCs that didn't get their doc.type set, 3) a big bunch of historic stand-alone RFCs that have doc.group=None - set these to the individual submission "none" group for the time being so the view code doesn't have to deal with a special case. In some cases this is wrong since there actually was a WG associated but unfortunately fixing them properly requires detective work (probably parsing the RFCs) and in at least some cases recreating historic WGs. In case someone ends up doing this, the documents to check can still be found with Document.objects.filter(name__startswith="rfc", group__type="individ") since there are almost no new RFCs that didn't went through the I-D process. - Merged the I-D and RFC views by showing I-D information on RFCs too. I-Ds that have been published as RFCs redirect to the RFC URL. Also support alias URLs so e.g. /doc/bcpXXXX redirects to /doc/rfcXXXX. - Fixed revision augmentation so events after RFC publication gets a "RFC" designation - Fixed a bug with tabs not using provided name but rather doc.name - Displaying draft-iesg state rather than doc.friendly_state as IESG state, also show a notice that the IESG state refers to post-RFC processing if it does, like the old separate RFC page did - Fixed the RFC number doc.note migration to catch combined "RFC XXX; BCP XXX" notes too, use the opportunity to remove inserted HTML tags from notes and rely on linebreaksbr filter instead (the other thing was a left-over from the Perl days), update the various uses of the note to reflect that - Refactored slightly to make views_doc.py independent of other idrfc code - Moveed idrfc/views_doc.py to doc/ with associated templates, replace the somewhat fragile simple URL tests for views_doc.py with ordinary unit tests. The new tests are still fairly basic but at least test more than the URL tests did. - Made sure RFC's (and BCP/STD/FYI) are stored as RFC123 instead of RFC0123 in the alias table with a new migration and a change to the RFC Editor sync, this in turn makes /doc/std1/ do the right thing - Now /doc/std1/ works, we can actually do a local link in urlize_ietf_docs rather than linking to the tools.ietf.org server - Fixed history text formatter: sanitize HTML before adding linebreaks and non-breaking spaces, this cuts the time to render a history page with long comments in half - Added a test crawler that walks through the crawlable part of the site, reporting errors and slow pages - Got rid of initial "No record" positions when showing old positions, it's just noise - Added a .select_related() to the document main tab to reduce the number of DB queries, unfortunately it seems it doesn't really help with Django 1.2.x due to a bug (Document inherits from DocumentInfo which makes things a bit more complicated) - Introduced a simple cache in doc.get_state so repeated reads don't cause a DB query - Cleaned up the search code in preparation for removal of the shim-layer; use a static button and don't send extraneous GET parameters - Removed dead code in several places - Legacy-Id: 5830
2 parents c9cfc8f + 619b1d8 commit e678659

74 files changed

Lines changed: 4931 additions & 4460 deletions

Some content is hidden

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

django/test/testcases.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,19 @@ def assertTemplateNotUsed(self, response, template_name, msg_prefix=''):
494494
def assertQuerysetEqual(self, qs, values, transform=repr):
495495
return self.assertEqual(map(transform, qs), values)
496496

497+
# some things from newer (python 2.7) unittests
498+
def assertIsNone(self, obj, msg=None):
499+
"""Same as self.assertTrue(obj is None), with a nicer default message."""
500+
if obj is not None:
501+
standardMsg = '%s is not None' % (safe_repr(obj),)
502+
self.fail(self._formatMessage(msg, standardMsg))
503+
504+
def assertIsNotNone(self, obj, msg=None):
505+
"""Included for symmetry with assertIsNone."""
506+
if obj is None:
507+
standardMsg = 'unexpectedly None'
508+
self.fail(self._formatMessage(msg, standardMsg))
509+
497510
def connections_support_transactions():
498511
"""
499512
Returns True if all connections support transactions. This is messy

ietf/bin/test-crawl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python
2+
3+
import os, sys, re, datetime, optparse, traceback
4+
import syslog
5+
6+
# boilerplate
7+
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
8+
sys.path = [ basedir ] + sys.path
9+
10+
from ietf import settings
11+
from django.core import management
12+
management.setup_environ(settings)
13+
14+
import django.test
15+
from django.conf import settings
16+
17+
# prevent memory from leaking when settings.DEBUG=True
18+
from django.db import connection
19+
class DontSaveQueries(object):
20+
def append(self, x):
21+
pass
22+
connection.queries = DontSaveQueries()
23+
24+
MAX_URL_LENGTH = 500
25+
SLOW_THRESHOLD = 1.0
26+
27+
def strip_url(url):
28+
if url.startswith("http://testserver"):
29+
url = url[len("http://testserver"):]
30+
return url
31+
32+
def extract_html_urls(content):
33+
for m in re.finditer(r'<a.*href="([^"]+)">', content):
34+
url = strip_url(m.group(1))
35+
if len(url) > MAX_URL_LENGTH:
36+
continue # avoid infinite GET parameter appendages
37+
38+
if not url.startswith("/"):
39+
continue
40+
41+
yield url
42+
43+
44+
visited = set()
45+
blacklist = set()
46+
urls = set(["/doc/all/"])
47+
48+
client = django.test.Client()
49+
50+
while urls:
51+
url = urls.pop()
52+
53+
visited.add(url)
54+
55+
try:
56+
timestamp = datetime.datetime.now()
57+
r = client.get(url)
58+
elapsed = datetime.datetime.now() - timestamp
59+
except KeyboardInterrupt:
60+
print "was fetching", url
61+
sys.exit(1)
62+
except:
63+
print "FAIL", url
64+
print "============="
65+
traceback.print_exc()
66+
print "============="
67+
else:
68+
tags = []
69+
70+
if r.status_code in (301, 302):
71+
u = strip_url(r["Location"])
72+
if u not in visited and u not in urls:
73+
urls.add(u)
74+
75+
elif r.status_code == 200:
76+
ctype = r["Content-Type"]
77+
if ";" in ctype:
78+
ctype = ctype[:ctype.index(";")]
79+
80+
if ctype == "text/html":
81+
for u in extract_html_urls(r.content):
82+
if u not in visited and u not in urls:
83+
urls.add(u)
84+
else:
85+
tags.append("FAIL")
86+
87+
if elapsed.total_seconds() > SLOW_THRESHOLD:
88+
tags.append("SLOW")
89+
90+
print r.status_code, "%.3fs" % elapsed.total_seconds(), url, " ".join(tags)
91+

ietf/doc/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class DocumentAdmin(admin.ModelAdmin):
9393
list_display = ['name', 'rev', 'group', 'pages', 'intended_std_level', 'author_list', 'time']
9494
search_fields = ['name']
9595
list_filter = ['type']
96-
raw_id_fields = ['authors', 'related', 'group', 'shepherd', 'ad']
96+
raw_id_fields = ['authors', 'group', 'shepherd', 'ad']
9797
inlines = [DocAliasInline, DocAuthorInline, RelatedDocumentInline, ]
9898
form = DocumentForm
9999

ietf/doc/migrations/0011_cleanup_new_revision_docevents.py

Lines changed: 351 additions & 0 deletions
Large diffs are not rendered by default.

ietf/doc/migrations/0012_cleanup_doc_notes.py

Lines changed: 363 additions & 0 deletions
Large diffs are not rendered by default.

ietf/doc/migrations/0013_fixup_broken_rfc_docs.py

Lines changed: 379 additions & 0 deletions
Large diffs are not rendered by default.

ietf/doc/migrations/0014_fix_rfc_aliases.py

Lines changed: 369 additions & 0 deletions
Large diffs are not rendered by default.

ietf/doc/models.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.urlresolvers import reverse as urlreverse
55
from django.contrib.contenttypes.models import ContentType
66
from django.conf import settings
7+
from django.utils.html import mark_safe
78

89
from ietf.group.models import *
910
from ietf.name.models import *
@@ -99,20 +100,26 @@ def set_state(self, state):
99100
self.states.remove(*others)
100101
if state not in already_set:
101102
self.states.add(state)
103+
self.state_cache = None # invalidate cache
102104

103105
def unset_state(self, state_type):
104106
"""Unset state of type so no state of that type is any longer set."""
105107
self.states.remove(*self.states.filter(type=state_type))
108+
self.state_cache = None # invalidate cache
106109

107110
def get_state(self, state_type=None):
108-
"""Get state of type, or default state for document type if not specified."""
111+
"""Get state of type, or default state for document type if
112+
not specified. Uses a local cache to speed multiple state
113+
reads up."""
109114
if state_type == None:
110115
state_type = self.type_id
111116

112-
try:
113-
return self.states.get(type=state_type)
114-
except State.DoesNotExist:
115-
return None
117+
if not hasattr(self, "state_cache") or self.state_cache == None:
118+
self.state_cache = {}
119+
for s in self.states.all().select_related():
120+
self.state_cache[s.type_id] = s
121+
122+
return self.state_cache.get(state_type, None)
116123

117124
def get_state_slug(self, state_type=None):
118125
"""Get state of type, or default if not specified, returning
@@ -137,8 +144,10 @@ def ballot_open(self, ballot_type_slug):
137144
def active_ballot(self):
138145
"""Returns the most recently created ballot if it isn't closed."""
139146
ballot = self.latest_event(BallotDocEvent, type="created_ballot")
140-
open = self.ballot_open(ballot.ballot_type.slug) if ballot else False
141-
return ballot if open else None
147+
if ballot and self.ballot_open(ballot.ballot_type.slug):
148+
return ballot
149+
else:
150+
return None
142151

143152
class Meta:
144153
abstract = True
@@ -167,7 +176,7 @@ class Meta:
167176

168177
class Document(DocumentInfo):
169178
name = models.CharField(max_length=255, primary_key=True) # immutable
170-
related = models.ManyToManyField('DocAlias', through=RelatedDocument, blank=True, related_name="reversely_related_document_set")
179+
#related = models.ManyToManyField('DocAlias', through=RelatedDocument, blank=True, related_name="reversely_related_document_set")
171180
authors = models.ManyToManyField(Email, through=DocumentAuthor, blank=True)
172181

173182
def __unicode__(self):
@@ -230,6 +239,14 @@ def display_name(self):
230239
name = name.upper()
231240
return name
232241

242+
def related_that(self, relationship):
243+
"""Return the documents that are source of relationship targeting self."""
244+
return Document.objects.filter(relateddocument__target__document=self, relateddocument__relationship=relationship)
245+
246+
def related_that_doc(self, relationship):
247+
"""Return the doc aliases that are target of relationship originating from self."""
248+
return DocAlias.objects.filter(relateddocument__source=self, relateddocument__relationship=relationship)
249+
233250
#TODO can/should this be a function instead of a property? Currently a view uses it as a property
234251
@property
235252
def telechat_date(self):
@@ -284,9 +301,6 @@ def rfc_number(self):
284301
qs = self.docalias_set.filter(name__startswith='rfc')
285302
return qs[0].name[3:] if qs else None
286303

287-
def replaced_by(self):
288-
return [ rel.source for alias in self.docalias_set.all() for rel in alias.relateddocument_set.filter(relationship='replaces') ]
289-
290304
def friendly_state(self):
291305
""" Return a concise text description of the document's current state """
292306
if self.type_id=='draft':
@@ -305,12 +319,12 @@ def friendly_state(self):
305319
iesg_state_summary = iesg_state_summary + "::"+"::".join(tag.name for tag in iesg_substate)
306320

307321
if self.get_state_slug() == "rfc":
308-
#return "<a href=\"%s\">RFC %d</a>" % (urlreverse('doc_view', args=['rfc%d' % int(self.rfc_number())]), int(self.rfc_number()))
309-
return "RFC %d (%s)" % (int(self.rfc_number()), self.std_level)
322+
n = self.rfc_number()
323+
return "<a href=\"%s\">RFC %s</a>" % (urlreverse('doc_view', kwargs=dict(name='rfc%s' % n)), n)
310324
elif self.get_state_slug() == "repl":
311-
rs = self.replaced_by()
325+
rs = self.related_that("replaces")
312326
if rs:
313-
return "Replaced by "+", ".join("<a href=\"%s\">%s</a>" % (urlreverse('doc_view', args=[name]),name) for name in rs)
327+
return mark_safe("Replaced by " + ", ".join("<a href=\"%s\">%s</a>" % (urlreverse('doc_view', args=[name]), name) for name in rs))
314328
else:
315329
return "Replaced"
316330
elif self.get_state_slug() == "active":
@@ -585,7 +599,13 @@ def all_positions(self):
585599

586600
if e.pos != prev:
587601
latest.old_positions.append(e.pos)
588-
602+
603+
# get rid of trailling "No record" positions, some old ballots
604+
# have plenty of these
605+
for p in positions:
606+
while p.old_positions and p.old_positions[-1].slug == "norecord":
607+
p.old_positions.pop()
608+
589609
# add any missing ADs through fake No Record events
590610
if self.doc.active_ballot() == self:
591611
norecord = BallotPositionName.objects.get(slug="norecord")

ietf/doc/tests.py

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,144 @@
1+
import os, shutil, datetime
12

3+
import django.test
4+
from django.core.urlresolvers import reverse as urlreverse
5+
from django.conf import settings
26

7+
from pyquery import PyQuery
8+
9+
from ietf.utils.mail import outbox
10+
from ietf.utils.test_utils import login_testing_unauthorized
11+
from ietf.utils.test_data import make_test_data
12+
13+
from ietf.doc.models import *
14+
from ietf.name.models import *
15+
from ietf.group.models import *
16+
from ietf.person.models import *
17+
from ietf.meeting.models import Meeting, MeetingTypeName
18+
from ietf.iesg.models import TelechatDate
19+
20+
# extra tests
321
from ietf.doc.tests_conflict_review import *
4-
from ietf.doc.tests_status_change import *
22+
23+
24+
class DocTestCase(django.test.TestCase):
25+
fixtures = ['names']
26+
27+
def test_document_draft(self):
28+
draft = make_test_data()
29+
30+
# these tests aren't testing all attributes yet, feel free to
31+
# expand them
32+
33+
34+
# active draft
35+
draft.set_state(State.objects.get(type="draft", slug="active"))
36+
37+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=draft.name)))
38+
self.assertEqual(r.status_code, 200)
39+
self.assertTrue("Active Internet-Draft" in r.content)
40+
41+
# expired draft
42+
draft.set_state(State.objects.get(type="draft", slug="expired"))
43+
44+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=draft.name)))
45+
self.assertEqual(r.status_code, 200)
46+
self.assertTrue("Expired Internet-Draft" in r.content)
47+
48+
# replaced draft
49+
draft.set_state(State.objects.get(type="draft", slug="repl"))
50+
51+
replacement = Document.objects.create(
52+
name="draft-ietf-replacement",
53+
time=datetime.datetime.now(),
54+
type_id="draft",
55+
title="Replacement Draft",
56+
stream_id=draft.stream_id, group_id=draft.group_id, abstract=draft.stream, rev=draft.rev,
57+
pages=draft.pages, intended_std_level_id=draft.intended_std_level_id,
58+
shepherd_id=draft.shepherd_id, ad_id=draft.ad_id, expires=draft.expires,
59+
notify=draft.notify, note=draft.note)
60+
DocAlias.objects.create(name=replacement.name, document=replacement)
61+
rel = RelatedDocument.objects.create(source=replacement,
62+
target=draft.docalias_set.get(name__startswith="draft"),
63+
relationship_id="replaces")
64+
65+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=draft.name)))
66+
self.assertEqual(r.status_code, 200)
67+
self.assertTrue("Replaced Internet-Draft" in r.content)
68+
self.assertTrue(replacement.name in r.content)
69+
rel.delete()
70+
71+
# draft published as RFC
72+
draft.set_state(State.objects.get(type="draft", slug="rfc"))
73+
draft.std_level_id = "bcp"
74+
draft.save()
75+
76+
DocEvent.objects.create(doc=draft, type="published_rfc", by=Person.objects.get(name="(System)"))
77+
78+
rfc_alias = DocAlias.objects.create(name="rfc123456", document=draft)
79+
bcp_alias = DocAlias.objects.create(name="bcp123456", document=draft)
80+
81+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=draft.name)))
82+
self.assertEqual(r.status_code, 302)
83+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=bcp_alias.name)))
84+
self.assertEqual(r.status_code, 302)
85+
86+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=rfc_alias.name)))
87+
self.assertEqual(r.status_code, 200)
88+
self.assertTrue("RFC 123456" in r.content)
89+
self.assertTrue(draft.name in r.content)
90+
91+
# naked RFC
92+
rfc = Document.objects.create(
93+
name="rfc1234567",
94+
type_id="draft",
95+
title="RFC without a Draft",
96+
stream_id="ise",
97+
group=Group.objects.get(type="individ"),
98+
std_level_id="ps")
99+
DocAlias.objects.create(name=rfc.name, document=rfc)
100+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name=rfc.name)))
101+
self.assertEqual(r.status_code, 200)
102+
self.assertTrue("RFC 1234567" in r.content)
103+
104+
# unknown draft
105+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name="draft-xyz123")))
106+
self.assertEqual(r.status_code, 404)
107+
108+
def test_document_charter(self):
109+
make_test_data()
110+
111+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name="charter-ietf-mars")))
112+
self.assertEqual(r.status_code, 200)
113+
114+
def test_document_conflict_review(self):
115+
make_test_data()
116+
117+
r = self.client.get(urlreverse("doc_view", kwargs=dict(name='conflict-review-imaginary-irtf-submission')))
118+
self.assertEqual(r.status_code, 200)
119+
120+
def test_document_ballot(self):
121+
doc = make_test_data()
122+
ballot = doc.active_ballot()
123+
124+
BallotPositionDocEvent.objects.create(
125+
doc=doc,
126+
type="changed_ballot_position",
127+
pos_id="yes",
128+
comment="Looks fine to me",
129+
comment_time=datetime.datetime.now(),
130+
ad=Person.objects.get(user__username="ad"),
131+
by=Person.objects.get(name="(System)"))
132+
133+
r = self.client.get(urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=doc.name)))
134+
self.assertEqual(r.status_code, 200)
135+
136+
# test popup too while we're at it
137+
r = self.client.get(urlreverse("ietf.doc.views_doc.ballot_for_popup", kwargs=dict(name=doc.name)))
138+
self.assertEqual(r.status_code, 200)
139+
140+
def test_document_json(self):
141+
doc = make_test_data()
142+
143+
r = self.client.get(urlreverse("ietf.doc.views_doc.document_json", kwargs=dict(name=doc.name)))
144+
self.assertEqual(r.status_code, 200)

0 commit comments

Comments
 (0)