Implement DocumentWrapper class, which isn't a model but has enough
of the same API as IDInternal to allow the template to render it. When fetching lists of document IDs, use values() to fetch only the ID to reduce database overhead (and model object creation overhead) - Legacy-Id: 373
This commit is contained in:
parent
18f7fd0c4e
commit
2ad2219895
|
@ -867,3 +867,18 @@ class IRTFChair(models.Model):
|
|||
db_table = 'irtf_chairs'
|
||||
class Admin:
|
||||
pass
|
||||
|
||||
# Not a model, but it's related.
|
||||
# This is used in the view to represent documents
|
||||
# in "I-D Exists".
|
||||
#
|
||||
class DocumentWrapper(object):
|
||||
'''A wrapper for a document, used to synthesize I-D Exists.'''
|
||||
document = None
|
||||
synthetic = True
|
||||
job_owner = "Not Assigned Yet"
|
||||
docstate = "I-D Exists"
|
||||
cur_state = "I-D Exists"
|
||||
cur_state_id = 100
|
||||
def __init__(self, document):
|
||||
self.document = document
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.template import RequestContext
|
|||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.db.models import Q
|
||||
from django.views.generic.list_detail import object_detail, object_list
|
||||
from ietf.idtracker.models import InternetDraft, IDInternal, IDState, IDSubState, Rfc
|
||||
from ietf.idtracker.models import InternetDraft, IDInternal, IDState, IDSubState, Rfc, DocumentWrapper
|
||||
from ietf.idtracker.forms import IDSearch, EmailFeedback
|
||||
from ietf.utils.mail import send_mail_text
|
||||
|
||||
|
@ -47,12 +47,12 @@ def search(request):
|
|||
if searching:
|
||||
group = args.get('search_group_acronym', '')
|
||||
if group != '':
|
||||
rfclist = [rfc.rfc_number for rfc in Rfc.objects.all().filter(group_acronym=group)]
|
||||
draftlist = [draft.id_document_tag for draft in InternetDraft.objects.all().filter(group__acronym=group)]
|
||||
rfclist = [rfc['rfc_number'] for rfc in Rfc.objects.all().filter(group_acronym=group).values('rfc_number')]
|
||||
draftlist = [draft['id_document_tag'] for draft in InternetDraft.objects.all().filter(group__acronym=group).values('id_document_tag')]
|
||||
q_objs.append(Q(draft__in=draftlist)&Q(rfc_flag=0)|Q(draft__in=rfclist)&Q(rfc_flag=1))
|
||||
rfc_number = args.get('search_rfcnumber', '')
|
||||
if rfc_number != '':
|
||||
draftlist = [draft.id_document_tag for draft in InternetDraft.objects.all().filter(rfc_number=rfc_number)]
|
||||
draftlist = [draft['id_document_tag'] for draft in InternetDraft.objects.all().filter(rfc_number=rfc_number).values('id_document_tag')]
|
||||
q_objs.append(Q(draft__in=draftlist)&Q(rfc_flag=0)|Q(draft=rfc_number)&Q(rfc_flag=1))
|
||||
filename = args.get('search_filename', '')
|
||||
if filename != '':
|
||||
|
@ -62,6 +62,42 @@ def search(request):
|
|||
q_objs.append(Q(draft__status=status,rfc_flag=0))
|
||||
matches = IDInternal.objects.all().filter(*q_objs)
|
||||
matches = matches.order_by('cur_state', 'cur_sub_state', 'ballot')
|
||||
#
|
||||
# Now search by I-D exists, if there could be any results.
|
||||
# If searching by job owner, current state or substate, there
|
||||
# can't be any "I-D exists" matches.
|
||||
if not(args.get('search_job_owner', 0) or args.get('search_cur_state', 0) or args.get('sub_state_id', 0)):
|
||||
if not(args.get('search_rfcnumber', 0)):
|
||||
in_tracker=[i['draft'] for i in IDInternal.objects.filter(rfc_flag=0).values('draft')]
|
||||
qdict = {
|
||||
'search_area_acronym': 'group__ietfwg__areagroup__area',
|
||||
'search_group_acronym': 'group__acronym',
|
||||
'search_filename': 'filename__icontains',
|
||||
'search_status_id': 'status',
|
||||
}
|
||||
q_objs = [Q(**{qdict[k]: args[k]}) for k in qdict.keys() if args.get(k, '') != '']
|
||||
idmatches = InternetDraft.objects.filter(*q_objs).exclude(id_document_tag__in=in_tracker)
|
||||
print "queryset is %s, idmatches is %s" % (matches, idmatches)
|
||||
# resolve the queryset, append wrapper objects.
|
||||
matches = list(matches) + [DocumentWrapper(id) for id in idmatches]
|
||||
if not(args.get('search_filename', '') or args.get('search_status_id', 0)) and args.get('search_rfcnumber', 0):
|
||||
# the existing area acronym support in this function
|
||||
# in pidtracker.cgi is broken, since it compares an
|
||||
# area acronym string in the database against an
|
||||
# area acronym number in the form. We just ignore
|
||||
# the area (resulting in a different search, but
|
||||
# given that this search is only performed when there's
|
||||
# an explicit rfc number, it seems more or less silly
|
||||
# to filter it further anyway.)
|
||||
in_tracker=[i['draft'] for i in IDInternal.objects.filter(rfc_flag=1).values('draft')]
|
||||
qdict = {
|
||||
'search_group_acronym': 'group_acronym',
|
||||
'search_rfcnumber': 'rfc_number',
|
||||
'search_status_id': 'status',
|
||||
}
|
||||
q_objs = [Q(**{qdict[k]: args[k]}) for k in qdict.keys() if args.get(k, '') != '']
|
||||
rfcmatches = Rfc.objects.filter(*q_objs).exclude(rfc_number__in=in_tracker)
|
||||
matches = list(matches) + [DocumentWrapper(rfc) for rfc in rfcmatches]
|
||||
else:
|
||||
matches = None
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
<tr bgcolor="#{% if match.primary_flag %}{% cycle F8D6F8,E2AFE2 as ballotcolor %}{% else %}{{ ballotcolor }}{% endif %}">
|
||||
{% if match.synthetic %}
|
||||
<td> </td>
|
||||
{% else %}
|
||||
<!-- this form element technically belongs inside the <td>
|
||||
but that actually changes the visible spacing in most
|
||||
browsers, so we let layout concerns make us write
|
||||
invalid HTML. -->
|
||||
<form method="GET" action="{% url ietf.idtracker.views.view_id match.document.filename %}"><td><input type="submit" value="DETAIL"></td></form>
|
||||
{# todo: conditionalize doclink properly #}
|
||||
{% endif %}
|
||||
<td>{% if match.primary_flag %}<li>{% else %}<dd>{% endif %}{{ match.document.filename_with_link }} ({{ match.document.intended_status }})
|
||||
{% ifequal match.document.status.status "Replaced" %}
|
||||
<br> Replaced by
|
||||
|
@ -27,7 +30,7 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
<td>{{ match.document.revision }}</td>
|
||||
<td>{{ match.job_owner }}</td>
|
||||
<td>{% firstof match.job_owner "Not Assigned Yet" %}</td>
|
||||
<td>{% firstof match.status_date "" %}</td>
|
||||
<td>{{ match.event_date }}</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in a new issue