- Legacy-Id: 5898
This commit is contained in:
Adam Roach 2013-07-27 12:26:24 +00:00
parent 451043d138
commit b14a8d0cee
3 changed files with 66 additions and 29 deletions

View file

@ -62,6 +62,8 @@ class SearchForm(forms.Form):
sort = forms.ChoiceField(choices=(("document", "Document"), ("title", "Title"), ("date", "Date"), ("status", "Status"), ("ipr", "Ipr"), ("ad", "AD")), required=False, widget=forms.HiddenInput)
doctypes = DocTypeName.objects.exclude(slug='draft').order_by('name');
def __init__(self, *args, **kwargs):
super(SearchForm, self).__init__(*args, **kwargs)
responsible = Document.objects.values_list('ad', flat=True).distinct()
@ -155,12 +157,16 @@ def fill_in_search_attributes(docs):
else:
d.latest_revision_date = d.time
if d.get_state_slug() == "rfc":
d.search_heading = "RFCs"
elif d.get_state_slug() == "active":
d.search_heading = "Active Internet-Drafts"
if d.type_id == "draft":
if d.get_state_slug() == "rfc":
d.search_heading = "RFCs"
elif d.get_state_slug() in ("ietf-rm", "auth-rm"):
d.search_heading = "Internet-Drafts %s" % d.get_state()
else:
d.search_heading = "%s Internet-Drafts" % d.get_state()
else:
d.search_heading = "Old Internet-Drafts"
d.search_heading = "%s (%s)" % (d.type,d.get_state());
d.expirable = expirable_draft(d)
@ -196,22 +202,38 @@ def fill_in_search_attributes(docs):
l.sort()
def retrieve_search_results(form, types=['draft']):
def retrieve_search_results(form, all_types=False):
"""Takes a validated SearchForm and return the results."""
if not form.is_valid():
raise ValueError("SearchForm doesn't validate: %s" % form.errors)
query = form.cleaned_data
if not (query['activedrafts'] or query['olddrafts'] or query['rfcs']):
types=[];
meta = {}
if (query['activedrafts'] or query['olddrafts'] or query['rfcs']):
types.append('draft')
# Advanced document types are data-driven, so we need to read them from the
# raw form.data field (and track their checked/unchecked state ourselves)
meta['checked'] = {}
alltypes = DocTypeName.objects.exclude(slug='draft').order_by('name');
for doctype in alltypes:
if form.data.__contains__('include-' + doctype.slug):
types.append(doctype.slug)
meta['checked'][doctype.slug] = True
if len(types) == 0 and not all_types:
return ([], {})
MAX = 500
if types and len(types) > 0:
docs = Document.objects.filter(type__in=types)
else:
if all_types:
docs = Document.objects.all()
else:
docs = Document.objects.filter(type__in=types)
# name
if query["name"]:
@ -219,16 +241,16 @@ def retrieve_search_results(form, types=['draft']):
Q(title__icontains=query["name"])).distinct()
# rfc/active/old check buttons
if types == ['draft']:
allowed_states = []
if query["rfcs"]:
allowed_states.append("rfc")
if query["activedrafts"]:
allowed_states.append("active")
if query["olddrafts"]:
allowed_states.extend(['repl', 'expired', 'auth-rm', 'ietf-rm'])
allowed_draft_states = []
if query["rfcs"]:
allowed_draft_states.append("rfc")
if query["activedrafts"]:
allowed_draft_states.append("active")
if query["olddrafts"]:
allowed_draft_states.extend(['repl', 'expired', 'auth-rm', 'ietf-rm'])
docs = docs.filter(states__type="draft", states__slug__in=allowed_states)
docs = docs.filter(Q(states__slug__in=allowed_draft_states) |
~Q(type__slug='draft')).distinct()
# radio choices
by = query["by"]
@ -259,12 +281,19 @@ def retrieve_search_results(form, types=['draft']):
rfc_num = d.rfc_number()
if rfc_num != None:
res.append(2)
elif d.get_state_slug() == "active":
res.append(1)
if d.type_id == "draft":
if rfc_num != None:
res.append(2)
elif d.get_state_slug() == "active":
res.append(1)
else:
res.append(3)
else:
res.append(3)
res.append(d.type_id);
res.append("-");
res.append(d.get_state_slug());
res.append("-");
if query["sort"] == "title":
res.append(d.title)
@ -296,11 +325,10 @@ def retrieve_search_results(form, types=['draft']):
results.sort(key=sort_key)
# fill in a meta dict with some information for rendering the result table
meta = {}
if len(results) == MAX:
meta['max'] = MAX
meta['by'] = query['by']
meta['advanced'] = bool(query['by'])
meta['advanced'] = bool(query['by'] or len(meta['checked']))
meta['headers'] = [{'title': 'Document', 'key':'document'},
{'title': 'Title', 'key':'title'},
@ -316,7 +344,6 @@ def retrieve_search_results(form, types=['draft']):
h["sort_url"] = "?" + d.urlencode()
if h['key'] == query.get('sort'):
h['sorted'] = True
return (results, meta)
@ -477,7 +504,7 @@ def docs_for_ad(request, name):
form = SearchForm({'by':'ad','ad': ad.id,
'rfcs':'on', 'activedrafts':'on', 'olddrafts':'on',
'sort': 'status'})
results, meta = retrieve_search_results(form, types=None)
results, meta = retrieve_search_results(form, all_types=True)
results.sort(key=ad_dashboard_sort_key)
del meta["headers"][-1]
#

View file

@ -52,6 +52,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<b class="toggle_advanced"><img src="/images/{% if meta.advanced %}minus{% else %}plus{% endif %}.png" alt="" /> Advanced</b>
<div id="search_advanced" style="{% if not meta.advanced %}display:none;{%endif%}">
<div class="search_field">
<label>Additional Document Types:</label>
<table id="search_types">
{% for doc_type in form.doctypes %}
<tr><td><label><input type="checkbox" {% if doc_type.slug in meta.checked %}checked="checked"{% endif %}name="include-{{doc_type.slug}}"/>{{doc_type}}</label></td></tr>
{% endfor %}
</table>
</div>
Additional search criteria:
<div class="search_field">

View file

@ -61,7 +61,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% regroup docs by search_heading as grouped_docs %}
{% for doc_group in grouped_docs %}
<tr class="header"><td colspan="10">{{ doc_group.grouper }}{{doc_group.list|length|pluralize}}</td></tr>
<tr class="header"><td colspan="10">{{ doc_group.grouper }}</td></tr>
{% for doc in doc_group.list %}
{% include "idrfc/search_result_row.html" %}