|
55 | 55 | from ietf.utils.history import find_history_active_at |
56 | 56 | from ietf.ietfauth.decorators import has_role |
57 | 57 |
|
58 | | - |
59 | 58 | def render_document_top(request, doc, tab, name): |
60 | 59 | tabs = [] |
61 | 60 | 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): |
373 | 372 | context_instance=RequestContext(request)) |
374 | 373 |
|
375 | 374 | 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) |
388 | 376 |
|
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 |
395 | 379 |
|
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) |
398 | 398 | data["authors"] = [ |
399 | 399 | dict(name=e.person.name, |
400 | 400 | email=e.address, |
401 | 401 | 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") |
403 | 403 | ] |
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) |
414 | 416 |
|
415 | 417 | return HttpResponse(json.dumps(data, indent=2), mimetype='text/plain') |
416 | 418 |
|
|
0 commit comments