Skip to content

Commit 49fc493

Browse files
committed
Clean up doc.json view, only export plain fields and fields requested
in RFC 6359, more can be added later if necessary; export more info on the group - Legacy-Id: 4869
1 parent ff077f4 commit 49fc493

3 files changed

Lines changed: 41 additions & 36 deletions

File tree

ietf/group/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class GroupInfo(models.Model):
2424
def __unicode__(self):
2525
return self.name
2626

27+
def name_with_acronym(self):
28+
res = self.name
29+
if self.type_id in ("wg", "rg", "area"):
30+
res += " %s (%s)" % (self.type, self.acronym)
31+
return res
32+
2733
class Meta:
2834
abstract = True
2935

ietf/idrfc/mails.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,7 @@ def generate_approval_mail_rfc_editorREDESIGN(request, doc):
287287
def generate_publication_request(request, doc):
288288
group_description = ""
289289
if doc.group and doc.group.acronym != "none":
290-
group_description = doc.group.name
291-
if doc.group.type_id in ("wg", "rg", "area"):
292-
group_description += " %s (%s)" % (doc.group.type, doc.group.acronym)
293-
290+
group_description = doc.group.name_with_acronym()
294291

295292
return render_to_string("idrfc/publication_request.txt",
296293
dict(doc=doc,

ietf/idrfc/views_doc.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
from ietf.utils.history import find_history_active_at
5656
from ietf.ietfauth.decorators import has_role
5757

58-
5958
def render_document_top(request, doc, tab, name):
6059
tabs = []
6160
tabs.append(("Document", "document", urlreverse("ietf.idrfc.views_doc.document_main", kwargs=dict(name=name)), True))
@@ -373,44 +372,47 @@ def document_ballot(request, name, ballot_id=None):
373372
context_instance=RequestContext(request))
374373

375374
def document_json(request, name):
376-
# old interface
377-
r = re.compile("^rfc([1-9][0-9]*)$")
378-
m = r.match(name)
379-
if m:
380-
rfc_number = int(m.group(1))
381-
rfci = get_object_or_404(RfcIndex, rfc_number=rfc_number)
382-
doc = RfcWrapper(rfci)
383-
else:
384-
id = get_object_or_404(InternetDraft, filename=name)
385-
doc = IdWrapper(draft=id)
386-
387-
from idrfc_wrapper import jsonify_helper
375+
doc = get_object_or_404(Document, docalias__name=name)
388376

389-
if isinstance(doc, RfcWrapper):
390-
data = jsonify_helper(doc, ['rfc_number', 'title', 'publication_date', 'maturity_level', 'obsoleted_by','obsoletes','updated_by','updates','also','has_errata','stream_name','file_types','in_ietf_process', 'friendly_state'])
391-
else:
392-
data = jsonify_helper(doc, ['draft_name', 'draft_status', 'latest_revision', 'rfc_number', 'title', 'tracker_id', 'publication_date','rfc_editor_state', 'replaced_by', 'replaces', 'in_ietf_process', 'file_types', 'group_acronym', 'stream_id','friendly_state', 'abstract', 'ad_name'])
393-
if doc.in_ietf_process():
394-
data['ietf_process'] = doc.ietf_process.dict()
377+
def extract_name(s):
378+
return s.name if s else None
395379

396-
# add some more fields using the new interface
397-
d = get_object_or_404(Document, docalias__name=name)
380+
data = {}
381+
382+
data["name"] = doc.name
383+
data["rev"] = doc.rev
384+
data["time"] = doc.time.strftime("%Y-%m-%d %H:%M:%S")
385+
data["group"] = None
386+
if doc.group:
387+
data["group"] = dict(
388+
name=doc.group.name,
389+
type=extract_name(doc.group.type),
390+
acronym=doc.group.acronym)
391+
data["expires"] = doc.expires.strftime("%Y-%m-%d %H:%M:%S")
392+
data["title"] = doc.title
393+
data["abstract"] = doc.abstract
394+
data["aliases"] = list(doc.docalias_set.values_list("name", flat=True))
395+
data["state"] = extract_name(doc.get_state())
396+
data["intended_std_level"] = extract_name(doc.intended_std_level)
397+
data["std_level"] = extract_name(doc.std_level)
398398
data["authors"] = [
399399
dict(name=e.person.name,
400400
email=e.address,
401401
affiliation=e.person.affiliation)
402-
for e in Email.objects.filter(documentauthor__document=d).select_related("person").order_by("documentauthor__order")
402+
for e in Email.objects.filter(documentauthor__document=doc).select_related("person").order_by("documentauthor__order")
403403
]
404-
e = d.latest_event(ConsensusDocEvent, type="changed_consensus")
405-
data["consensus"] = e.consensus if e else None
406-
data["stream"] = d.stream.name if d.stream else None
407-
data["shepherd"] = d.shepherd.formatted_email() if d.shepherd else None
408-
409-
def state_name(s):
410-
return s.name if s else None
411-
412-
data["iana_review_state"] = state_name(d.get_state("draft-iana-review"))
413-
data["iana_action_state"] = state_name(d.get_state("draft-iana-action"))
404+
data["shepherd"] = doc.shepherd.formatted_email() if doc.shepherd else None
405+
data["ad"] = doc.ad.role_email("ad").formatted_email() if doc.ad else None
406+
407+
if doc.type_id == "draft":
408+
data["iesg_state"] = extract_name(doc.get_state("draft-iesg"))
409+
data["rfceditor_state"] = extract_name(doc.get_state("draft-rfceditor"))
410+
data["iana_review_state"] = extract_name(doc.get_state("draft-iana-review"))
411+
data["iana_action_state"] = extract_name(doc.get_state("draft-iana-action"))
412+
413+
e = doc.latest_event(ConsensusDocEvent, type="changed_consensus")
414+
data["consensus"] = e.consensus if e else None
415+
data["stream"] = extract_name(doc.stream)
414416

415417
return HttpResponse(json.dumps(data, indent=2), mimetype='text/plain')
416418

0 commit comments

Comments
 (0)