Skip to content

Commit 55d8a49

Browse files
committed
Refactored the new AD dashboard view to re-use code and templates the same way the refactored previous view did.
- Legacy-Id: 5846
1 parent cf3fac2 commit 55d8a49

7 files changed

Lines changed: 66 additions & 164 deletions

File tree

ietf/idrfc/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
url(r'^search/$', views_search.search, name="doc_search"),
4242
url(r'^in-last-call/$', views_search.drafts_in_last_call, name="drafts_in_last_call"),
4343
url(r'^ad/(?P<name>[A-Za-z0-9.-]+)/$', views_search.drafts_for_ad, name="drafts_for_ad"),
44+
# url(r'^ad2/(?P<name>[A-Za-z0-9.-]+)/$', views_search.docs_for_ad, name="docs_for_ad"),
4445
url(r'^ad2/(?P<name>[A-Za-z0-9.-]+)/$', views_search.docs_for_ad, name="docs_for_ad"),
4546

4647
# (r'^all/$', views_search.all), # XXX CHECK MERGE

ietf/idrfc/views_search.py

Lines changed: 58 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def fill_in_search_attributes(docs):
196196
l.sort()
197197

198198

199-
def retrieve_search_results(form):
199+
def retrieve_search_results(form, types=['draft']):
200200
"""Takes a validated SearchForm and return the results."""
201201
if not form.is_valid():
202202
raise ValueError("SearchForm doesn't validate: %s" % form.errors)
@@ -208,23 +208,27 @@ def retrieve_search_results(form):
208208

209209
MAX = 500
210210

211-
docs = Document.objects.filter(type="draft")
211+
if types and len(types) > 0:
212+
docs = Document.objects.filter(type__in=types)
213+
else:
214+
docs = Document.objects.all()
212215

213216
# name
214217
if query["name"]:
215218
docs = docs.filter(Q(docalias__name__icontains=query["name"]) |
216219
Q(title__icontains=query["name"])).distinct()
217220

218221
# rfc/active/old check buttons
219-
allowed_states = []
220-
if query["rfcs"]:
221-
allowed_states.append("rfc")
222-
if query["activedrafts"]:
223-
allowed_states.append("active")
224-
if query["olddrafts"]:
225-
allowed_states.extend(['repl', 'expired', 'auth-rm', 'ietf-rm'])
222+
if types == ['draft']:
223+
allowed_states = []
224+
if query["rfcs"]:
225+
allowed_states.append("rfc")
226+
if query["activedrafts"]:
227+
allowed_states.append("active")
228+
if query["olddrafts"]:
229+
allowed_states.extend(['repl', 'expired', 'auth-rm', 'ietf-rm'])
226230

227-
docs = docs.filter(states__type="draft", states__slug__in=allowed_states)
231+
docs = docs.filter(states__type="draft", states__slug__in=allowed_states)
228232

229233
# radio choices
230234
by = query["by"]
@@ -342,36 +346,6 @@ def search(request):
342346
{'form':form, 'docs':results, 'meta':meta, 'show_add_to_list': True },
343347
context_instance=RequestContext(request))
344348

345-
def drafts_for_ad(request, name):
346-
ad = None
347-
responsible = Document.objects.values_list('ad', flat=True).distinct()
348-
for p in Person.objects.filter(Q(role__name__in=("pre-ad", "ad"),
349-
role__group__type="area",
350-
role__group__state="active")
351-
| Q(pk__in=responsible)).distinct():
352-
if name == p.full_name_as_key():
353-
ad = p
354-
break
355-
if not ad:
356-
raise Http404
357-
form = SearchForm({'by':'ad','ad': ad.id,
358-
'rfcs':'on', 'activedrafts':'on', 'olddrafts':'on',
359-
'sort': 'status'})
360-
results, meta = retrieve_search_results(form)
361-
362-
for d in results:
363-
if d.get_state_slug() == "active":
364-
iesg_state = d.get_state("draft-iesg")
365-
if iesg_state:
366-
if iesg_state.slug == "dead":
367-
d.search_heading = "IESG Dead Internet-Drafts"
368-
else:
369-
d.search_heading = "%s Internet-Drafts" % iesg_state.name
370-
371-
return render_to_response('doc/drafts_for_ad.html',
372-
{ 'form':form, 'docs':results, 'meta':meta, 'ad_name': ad.plain_name() },
373-
context_instance=RequestContext(request))
374-
375349
def ad_dashboard_group(doc):
376350

377351
if doc.type.slug=='draft':
@@ -457,8 +431,8 @@ def ad_dashboard_sort_key(doc):
457431
return "1%d%s%s%010d" % (state[0].order,seed,doc.type.slug,ageseconds)
458432

459433
return "3%s" % seed
460-
461-
def docs_for_ad(request, name):
434+
435+
def drafts_for_ad(request, name):
462436
ad = None
463437
responsible = Document.objects.values_list('ad', flat=True).distinct()
464438
for p in Person.objects.filter(Q(role__name__in=("pre-ad", "ad"),
@@ -470,37 +444,49 @@ def docs_for_ad(request, name):
470444
break
471445
if not ad:
472446
raise Http404
447+
form = SearchForm({'by':'ad','ad': ad.id,
448+
'rfcs':'on', 'activedrafts':'on', 'olddrafts':'on',
449+
'sort': 'status'})
450+
results, meta = retrieve_search_results(form)
451+
del meta["headers"][-1]
452+
#
453+
for d in results:
454+
if d.get_state_slug() == "active":
455+
iesg_state = d.get_state("draft-iesg")
456+
if iesg_state:
457+
if iesg_state.slug == "dead":
458+
d.search_heading = "IESG Dead Internet-Drafts"
459+
else:
460+
d.search_heading = "%s Internet-Drafts" % iesg_state.name
461+
return render_to_response('doc/drafts_for_ad.html',
462+
{ 'form':form, 'docs':results, 'meta':meta, 'ad_name': ad.plain_name() },
463+
context_instance=RequestContext(request))
473464

474-
docqueryset = Document.objects.filter(ad__id=ad.id)
475-
docs=[]
476-
for doc in docqueryset:
477-
doc.ad_dashboard_sort_key = ad_dashboard_sort_key(doc)
478-
doc.ad_dashboard_group = ad_dashboard_group(doc)
479-
if doc.get_state_slug() == 'rfc':
480-
doc.display_date = doc.latest_event(type='published_rfc').time
481-
else:
482-
revision = doc.latest_event(type='new_revision')
483-
if revision:
484-
doc.display_date = revision.time
485-
# This might be better handled as something Documents know about themselves
486-
now = datetime.datetime.now()
487-
doc.can_expire = (doc.type.slug=='draft' and doc.get_state_slug('draft')=='active' and ( not doc.get_state('draft-iesg') or doc.get_state('draft-iesg').order >= 42) and doc.expires>now)
488-
if doc.get_state_slug('draft') == 'rfc':
489-
doc.obsoleted_by = ", ".join([ 'RFC %04d' % int(rel.source.rfc_number()) for alias in doc.docalias_set.all() for rel in alias.relateddocument_set.filter(relationship='obsoletes') ] )
490-
doc.updated_by = ", ".join([ 'RFC %04d' % int(rel.source.rfc_number()) for alias in doc.docalias_set.all() for rel in alias.relateddocument_set.filter(relationship='updates') ] )
491-
doc.has_errata = bool(doc.tags.filter(slug="errata"))
492-
else:
493-
s = doc.get_state("draft-rfceditor")
494-
if s:
495-
# extract possible extra annotations
496-
tags = doc.tags.filter(slug__in=("iana", "ref"))
497-
doc.rfc_editor_state = "*".join([s.name] + [t.slug.upper() for t in tags])
498-
if doc.type.slug == 'draft':
499-
doc.iprCount = IprDocAlias.objects.filter(doc_alias__document=doc, ipr__status__in=[1,3]).count()
500-
doc.iprUrl = "/ipr/search?option=document_search&id_document_tag=%s" % doc.name
501-
docs.append(doc)
502-
docs.sort(key=ad_dashboard_sort_key)
503-
return render_to_response('doc/by_ad2.html',{'docs':docs,'ad_name':ad.plain_name()}, context_instance=RequestContext(request))
465+
def docs_for_ad(request, name):
466+
ad = None
467+
responsible = Document.objects.values_list('ad', flat=True).distinct()
468+
for p in Person.objects.filter(Q(role__name__in=("pre-ad", "ad"),
469+
role__group__type="area",
470+
role__group__state="active")
471+
| Q(pk__in=responsible)).distinct():
472+
if name == p.full_name_as_key():
473+
ad = p
474+
break
475+
if not ad:
476+
raise Http404
477+
form = SearchForm({'by':'ad','ad': ad.id,
478+
'rfcs':'on', 'activedrafts':'on', 'olddrafts':'on',
479+
'sort': 'status'})
480+
results, meta = retrieve_search_results(form, types=None)
481+
results.sort(key=ad_dashboard_sort_key)
482+
del meta["headers"][-1]
483+
#
484+
for d in results:
485+
d.search_heading = ad_dashboard_group(d)
486+
#
487+
return render_to_response('doc/drafts_for_ad.html',
488+
{ 'form':form, 'docs':results, 'meta':meta, 'ad_name': ad.plain_name() },
489+
context_instance=RequestContext(request))
504490

505491
def drafts_in_last_call(request):
506492
lc_state = State.objects.get(type="draft-iesg", slug="lc").pk

ietf/templates/base_leftmenu.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
<li><a href="{% url account_index %}">{% if request.user.is_authenticated %}Manage Account{% else %}New Account{% endif %}</a></li>
4141
{% if user|has_role:"Area Director" %}
4242
<li class="sect first">AD Dashboard</li>
43-
<li><a href="{% url drafts_for_ad name=user.get_profile.full_name_as_key %}">My Documents</a></li>
43+
<li><a href="{% url drafts_for_ad name=user.get_profile.full_name_as_key %}">My Documents (Old)</a></li>
44+
<li><a href="{% url docs_for_ad name=user.get_profile.full_name_as_key %}">My Documents (New)</a></li>
4445
<li><a href="{% url ietf.iesg.views.agenda_documents %}">Next Telechat</a></li>
4546
<li><a href="{% url ietf.iesg.views.discusses %}">Discusses</a></li>
4647
<li><a href="{% url ietf.iesg.views.milestones_needing_review %}">Milestones</a></li>

ietf/templates/doc/by_ad2.html

Lines changed: 0 additions & 88 deletions
This file was deleted.

ietf/templates/doc/drafts_for_ad.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{% extends "base.html" %}
22

3-
{% block title %}Internet-Drafts and RFCs for {{ ad_name }}{% endblock %}
3+
{% block title %}Documents for {{ ad_name }}{% endblock %}
44

55
{% block content %}
6-
<h1>Internet-Drafts and RFCs for {{ ad_name }}</h1>
6+
<h1>Documents for {{ ad_name }}</h1>
77

88
{% include "idrfc/search_results.html" %}
99

ietf/templates/idrfc/search_result_row.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
{% endif %}
7171
</td>
7272

73+
{% if ad_name != doc.ad.plain_name %}
7374
<td class="ad">{{ doc.ad|default:"" }}<div class="search-text-shepherd">{{doc.shepherd|default:""}}</div></td>
75+
{% endif %}
7476

7577
</tr>

ietf/templates/idrfc/search_results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2>Too many documents match the query! Returning partial result only.</h2>
6161
{% regroup docs by search_heading as grouped_docs %}
6262

6363
{% for doc_group in grouped_docs %}
64-
<tr class="header"><td colspan="10">{{ doc_group.grouper }}</td></tr>
64+
<tr class="header"><td colspan="10">{{ doc_group.grouper }}{{doc_group.list|length|pluralize}}</td></tr>
6565

6666
{% for doc in doc_group.list %}
6767
{% include "idrfc/search_result_row.html" %}

0 commit comments

Comments
 (0)