A little filter to add a space to strings like 'RFC1234' to get 'RFC 1234'

- Legacy-Id: 386
This commit is contained in:
Henrik Levkowetz 2007-06-14 23:38:51 +00:00
parent 109b1b4fdc
commit d989d0aa21
7 changed files with 225 additions and 15 deletions

View file

@ -105,7 +105,7 @@ def square_brackets(value):
@register.filter(name='fill') @register.filter(name='fill')
def fill(text, width): def fill(text, width):
"""Wraps the single paragraph in text (a string) so every line """Wraps each paragraph in text (a string) so every line
is at most width characters long, and returns a single string is at most width characters long, and returns a single string
containing the wrapped paragraph. containing the wrapped paragraph.
""" """
@ -125,3 +125,17 @@ def fill(text, width):
def allononeline(text): def allononeline(text):
"""Simply removes CRs, LFs, leading and trailing whitespace from the given string.""" """Simply removes CRs, LFs, leading and trailing whitespace from the given string."""
return text.replace("\r", "").replace("\n", "").strip() return text.replace("\r", "").replace("\n", "").strip()
@register.filter(name='rfcspace')
def rfcspace(string):
"""
If the string is an RFC designation, and doesn't have
a space between 'RFC' and the rfc-number, a space is
added
"""
string = str(string)
if string[:3].lower() == "rfc" and string[3] != " ":
return string[:3] + " " + string[3:]
else:
return string

View file

@ -1,3 +1,4 @@
# -*- conf-mode -*-
200 /ipr/ https://datatracker.ietf.org/public/ipr_list.cgi 200 /ipr/ https://datatracker.ietf.org/public/ipr_list.cgi
200 /ipr/ipr-657/ https://datatracker.ietf.org/public/ipr_detail_show.cgi?&ipr_id=657 # Generic disclosure 200 /ipr/ipr-657/ https://datatracker.ietf.org/public/ipr_detail_show.cgi?&ipr_id=657 # Generic disclosure
200 /ipr/ipr-834/ https://datatracker.ietf.org/public/ipr_detail_show.cgi?&ipr_id=834 # Specific disclosure 200 /ipr/ipr-834/ https://datatracker.ietf.org/public/ipr_detail_show.cgi?&ipr_id=834 # Specific disclosure
@ -7,4 +8,6 @@
200 /ipr/new-specific/ https://datatracker.ietf.org/public/ipr_notify.cgi 200 /ipr/new-specific/ https://datatracker.ietf.org/public/ipr_notify.cgi
200 /ipr/update/ https://datatracker.ietf.org/public/ipr_update_list.cgi 200 /ipr/update/ https://datatracker.ietf.org/public/ipr_update_list.cgi
200 /ipr/search/ https://datatracker.ietf.org/public/ipr_search.cgi 200 /ipr/search/ https://datatracker.ietf.org/public/ipr_search.cgi
# /ipr/update 302 /ipr/search/?option=document_search # incomplete argument set gives redirect
200 /ipr/search/?option=document_search&document_search=mod https://datatracker.ietf.org/public/ipr_search.cgi?option=document_search&document_search=mod
200 /ipr/search/?option=document_search&id_document_tag=2220 https://datatracker.ietf.org/public/ipr_search.cgi?option=document_search&id_document_tag=2220

View file

@ -9,7 +9,6 @@ urlpatterns = patterns('',
(r'^update/(?P<ipr_id>\d+)/$', views.update), (r'^update/(?P<ipr_id>\d+)/$', views.update),
(r'^new-(?P<type>(specific|generic|third-party))/$', views.new), (r'^new-(?P<type>(specific|generic|third-party))/$', views.new),
(r'^search/$', views.search), (r'^search/$', views.search),
(r'^search/\?((option=(?P<option>[^&]*)|.*search=(?P<search>[^&]*)|submit=(?P<submit>[^&]*))&?)+/$', views.search),
) )
queryset = models.IprDetail.objects.all() queryset = models.IprDetail.objects.all()

View file

@ -1,10 +1,12 @@
import models import re
import django.utils.html import django.utils.html
from django.shortcuts import render_to_response as render from django.shortcuts import render_to_response as render
from django.utils.html import escape from django.utils.html import escape
from ietf.idtracker.models import IETFWG, InternetDraft, Rfc
from ietf.ipr.models import IprRfc, IprDraft, IprDetail, SELECT_CHOICES, LICENSE_CHOICES
from ietf.ipr.view_sections import section_table from ietf.ipr.view_sections import section_table
from ietf.ipr.view_new import new from ietf.ipr.view_new import new
from ietf.idtracker.models import IETFWG from ietf.utils import log
def linebreaks(value): def linebreaks(value):
if value: if value:
@ -18,15 +20,15 @@ def default(request):
def showlist(request): def showlist(request):
"""Display a list of existing disclosures""" """Display a list of existing disclosures"""
return list(request, 'ipr/list.html') return list_all(request, 'ipr/list.html')
def updatelist(request): def updatelist(request):
"""Display a list of existing disclosures, with links to update forms""" """Display a list of existing disclosures, with links to update forms"""
return list(request, 'ipr/update_list.html') return list_all(request, 'ipr/update_list.html')
def list(request, template): def list_all(request, template):
"""Display a list of existing disclosures, using the provided template""" """Display a list of existing disclosures, using the provided template"""
disclosures = models.IprDetail.objects.all() disclosures = ietf.ipr.models.IprDetail.objects.all()
generic_disclosures = disclosures.filter(status__in=[1,3], generic=1) generic_disclosures = disclosures.filter(status__in=[1,3], generic=1)
specific_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=0) specific_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=0)
thirdpty_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=1) thirdpty_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=1)
@ -43,7 +45,7 @@ def list(request, template):
def show(request, ipr_id=None): def show(request, ipr_id=None):
"""Show a specific IPR disclosure""" """Show a specific IPR disclosure"""
assert ipr_id != None assert ipr_id != None
ipr = models.IprDetail.objects.get(ipr_id=ipr_id) ipr = IprDetail.objects.get(ipr_id=ipr_id)
section_list = get_section_list(ipr) section_list = get_section_list(ipr)
contacts = ipr.contact.all() contacts = ipr.contact.all()
for contact in contacts: for contact in contacts:
@ -63,11 +65,11 @@ def show(request, ipr_id=None):
ipr.other_notes = linebreaks(escape(ipr.other_notes)) ipr.other_notes = linebreaks(escape(ipr.other_notes))
if ipr.licensing_option: if ipr.licensing_option:
ipr.licensing_option = dict(models.LICENSE_CHOICES)[ipr.licensing_option] ipr.licensing_option = dict(LICENSE_CHOICES)[ipr.licensing_option]
if ipr.selecttype: if ipr.selecttype:
ipr.selecttype = dict(models.SELECT_CHOICES)[ipr.selecttype] ipr.selecttype = dict(SELECT_CHOICES)[ipr.selecttype]
if ipr.selectowned: if ipr.selectowned:
ipr.selectowned = dict(models.SELECT_CHOICES)[ipr.selectowned] ipr.selectowned = dict(SELECT_CHOICES)[ipr.selectowned]
return render("ipr/details.html", {"ipr": ipr, "section_list": section_list}) return render("ipr/details.html", {"ipr": ipr, "section_list": section_list})
def update(request, ipr_id=None): def update(request, ipr_id=None):
@ -76,10 +78,127 @@ def update(request, ipr_id=None):
return show(request, ipr_id) return show(request, ipr_id)
def search(request, option="", search="", submit=""): inverse = {
'updates': 'is_updated_by',
'is_updated_by': 'updates',
'obsoletes': 'is_obsoleted_by',
'is_obsoleted_by': 'obsoletes',
'replaces': 'is_replaced_by',
'is_replaced_by': 'replaces',
'is_rfc_of': 'is_draft_of',
'is_draft_of': 'is_rfc_of',
}
display_relation = {
'updates': 'that updates',
'is_updated_by': 'that was updated by',
'obsoletes': 'that obsoleted',
'is_obsoleted_by': 'that was obsoleted by',
'replaces': 'that replaced',
'is_replaced_by': 'that was replaced by',
'is_rfc_of': 'which came from',
'is_draft_of': 'that was published as',
}
def set_related(obj, rel, target):
print obj, rel, target
# remember only the first relationship we find.
if not hasattr(obj, "related"):
obj.related = target
obj.relation = display_relation[rel]
def set_relation(first, rel, second):
set_related(first, rel, second)
set_related(second, inverse[rel], first)
def related_docs(doc, found = []):
print "\nrelated_docs(%s, %s)" % (doc, found)
found.append(doc)
if isinstance(doc, Rfc):
try:
item = InternetDraft.objects.get(rfc_number=doc.rfc_number)
if not item in found:
set_relation(doc, 'is_rfc_of', item)
found = related_docs(item, found)
except InternetDraft.DoesNotExist:
pass
for entry in doc.updated_or_obsoleted_by.all():
item = entry.rfc
if not item in found:
action = inverse[entry.action.lower()]
set_relation(doc, action, item)
found = related_docs(item, found)
for entry in doc.updates_or_obsoletes.all():
item = entry.rfc_acted_on
if not item in found:
action = entry.action.lower()
set_relation(doc, action, item)
found = related_docs(item, found)
if isinstance(doc, InternetDraft):
if doc.replaced_by_id:
item = doc.replaced_by_id
if not item in found:
set_relation(doc, 'replaced_by', item)
found = related_docs(item, found)
for item in doc.replaces_set.all():
if not item in found:
set_relation(doc, 'replaces', item)
found = related_docs(item, found)
if doc.rfc_number:
item = Rfc.objects.get(rfc_number=doc.rfc_number)
if not item in found:
set_relation(doc, 'is_draft_of', item)
found = related_docs(item, found)
return found
def search(request, type="", q="", id=""):
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym') wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')
args = request.REQUEST.items()
if args:
for key, value in args:
if key == "option":
type = value
if re.match(".*search", key):
q = value
if re.match(".*id", key):
id = value
if type and q or id:
log("Got query: type=%s, q=%s, id=%s" % (type, q, id))
if type == "document_search":
log("Got document_search")
if q:
start = InternetDraft.objects.filter(filename__contains=q)
log("Found %s drafts containing %s" % (start.count(), q))
if id:
start = InternetDraft.objects.filter(id_document_tag=id)
log("Found %s drafts with id %s" % (start.count(), id))
if start.count() == 1:
first = start[0]
# get all related drafts, then search for IPRs on all
docs = related_docs(first, [])
iprs = []
for doc in docs:
if isinstance(doc, InternetDraft):
disclosures = [ item.ipr for item in IprDraft.objects.filter(document=doc) ]
elif isinstance(doc, Rfc):
disclosures = [ item.ipr for item in IprRfc.objects.filter(document=doc) ]
else:
raise ValueError("Neither draft nor rfc: %s" % doc)
if disclosures:
doc.iprs = disclosures
iprs += disclosures
iprs = list(set(iprs))
return render("ipr/search_result.html", {"first": first, "iprs": iprs, "docs": docs})
elif start.count():
return render("ipr/search_list.html", {"docs": start })
return django.http.HttpResponseRedirect(request.path)
return render("ipr/search.html", {"wgs": wgs}) return render("ipr/search.html", {"wgs": wgs})
def form(request):
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')
log("Search form")
return render("ipr/search.html", {"wgs": wgs})
# ---- Helper functions ------------------------------------------------------ # ---- Helper functions ------------------------------------------------------

View file

@ -0,0 +1,16 @@
<html>
<head><title>IPR Search Engine </title></head>
<body>
<center>
<h2>IPR Disclosures</h2></center>
<hr width="100%">
<blockquote>
<h3>Please select one of following I-Ds</h3>
<ul>
{% for doc in docs %}
<li> <a href="?option=document_search&id_document_tag={{ doc.id_document_tag }}">{{ doc.filename }}</a></li>
{% endfor %}
</ul>
</body>

View file

@ -0,0 +1,58 @@
{% load ietf_filters %}
<html>
<head><title>IPR Search Engine </title></head>
<body>
<center>
<h2>IPR Disclosures</h2></center>
<hr width="100%">
<blockquote>
<table cellpadding="1" cellspacing="0" border="0">
<tr><td colspan="3">Total number of IPR disclosures found: {{ iprs|length }} </td></tr>
{% for ipr in iprs|dictsort:"submitted_date" %}
<tr valign="top" bgcolor="#dadada">
<td width="100">{{ ipr.submitted_date }}</td>
<td width="90"><li>ID # {{ ipr.ipr_id }}</li></td>
<td><a href="{% url ietf.ipr.views.show ipr_id=ipr.ipr_id %}">"{{ ipr.document_title }}"</a></td>
</tr>
{% endfor %}
<tr><td colspan="3"><hr>Total number of documents searched: {{ docs|length}}</td></tr>
{% for doc in docs %}
<tbody bgcolor="#{% cycle dadada,eaeaea as bgcolor %}">
<tr >
<td colspan="3">
Search result on {{ doc }}, "{{ doc.title }}"{% ifnotequal doc first %}{% if doc.related %}, {{ doc.relation }} {{ doc.related }}, "{{ doc.related.title }}"{% endif %}
{% endifnotequal %}
</td>
</tr>
{% if doc.iprs %}
{% for ipr in doc.iprs %}
<tr valign="top">
<td width="100">{{ ipr.submitted_date }}</td>
<td width="90"><li>ID # {{ ipr.ipr_id }}</li></td>
<td><a href="{% url ietf.ipr.views.show %}{{ ipr.ipr_id }}">"{{ ipr.document_title }}"</a></td>
</tr>
{% endfor %}
{% else %}
<tr>
<td></td>
<td colspan="2"><b>No IPR disclosures related to <i>{{ doc|rfcspace }}</i> have been submitted</b></td>
</tr>
{% endif %}
</tbody>
{% endfor %}
</table>
<hr><br>
<a href="{% url ietf.ipr.views.search %}"><img src="http://www.ietf.org/images/blue.gif" hspace="3" border="0">IPR Search Main Page</a><br>
<a href="{% url ietf.ipr.views.list %}"><img src="http://www.ietf.org/images/blue.gif" hspace="3" border="0">IPR Disclosure Page</a>
<br>
</body></html>

View file

@ -22,11 +22,12 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
return django.test.simple.run_tests(module_list, verbosity, extra_tests) return django.test.simple.run_tests(module_list, verbosity, extra_tests)
def reduce(html): def reduce(html):
html = re.sub(" :", ":", html) html = re.sub(" :", ": ", html)
if html.count("<li>") > 5*html.count("</li>"): if html.count("<li>") > 5*html.count("</li>"):
html = html.replace("<li>", "</li><li>") html = html.replace("<li>", "</li><li>")
text = html2text(html) text = html2text(html)
text = re.sub('\."', '".', text) text = re.sub('\."', '".', text)
text = re.sub(',"', '",', text)
text = [ line.strip() for line in text.split("\n") ] text = [ line.strip() for line in text.split("\n") ]
return text return text