|
1 | 1 | import re |
| 2 | +import os.path |
2 | 3 | import django.utils.html |
3 | 4 | from django.shortcuts import render_to_response as render |
4 | 5 | from django.template import RequestContext |
| 6 | +from django.conf import settings |
5 | 7 | from ietf.idtracker.models import IETFWG, InternetDraft, Rfc |
6 | 8 | from ietf.ipr.models import IprRfc, IprDraft, IprDetail |
7 | 9 | from ietf.ipr.related import related_docs |
|
10 | 12 |
|
11 | 13 | def mark_last_doc(iprs): |
12 | 14 | for item in iprs: |
13 | | - if item.drafts.count(): |
14 | | - item.last_draft = item.drafts.all()[int(item.drafts.count())-1] |
15 | | - if item.rfcs.count(): |
16 | | - item.last_rfc = item.rfcs.all()[int(item.rfcs.count())-1] |
| 15 | + docs = item.docs() |
| 16 | + count = len(docs) |
| 17 | + if count > 1: |
| 18 | + item.last_draft = docs[count-1] |
17 | 19 |
|
18 | 20 | def mark_related_doc(iprs): |
19 | 21 | for item in iprs: |
@@ -46,6 +48,19 @@ def iprs_from_docs(docs): |
46 | 48 | iprs = list(set(iprs)) |
47 | 49 | return iprs, docs |
48 | 50 |
|
| 51 | +def patent_file_search(url, q): |
| 52 | + if url: |
| 53 | + fname = url.split("/")[-1] |
| 54 | + fpath = os.path.join(settings.IPR_DOCUMENT_PATH, fname) |
| 55 | + #print "*** Checking file", fpath |
| 56 | + if os.path.exists(fpath): |
| 57 | + #print "*** Found file", fpath |
| 58 | + file = open(fpath) |
| 59 | + text = file.read() |
| 60 | + file.close |
| 61 | + return q in text |
| 62 | + return False |
| 63 | + |
49 | 64 | def search(request, type="", q="", id=""): |
50 | 65 | wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym') |
51 | 66 | args = request.REQUEST.items() |
@@ -101,7 +116,28 @@ def search(request, type="", q="", id=""): |
101 | 116 | # Search by content of email or pagent_info field |
102 | 117 | # IPR list with documents |
103 | 118 | elif type == "patent_info_search": |
104 | | - pass |
| 119 | + if len(q) < 3: |
| 120 | + return render("ipr/search_error.html", {"q": q, "error": "The search string must contain at least three characters" }, |
| 121 | + context_instance=RequestContext(request) ) |
| 122 | + digits = re.search("[0-9]", q) |
| 123 | + if not digits: |
| 124 | + return render("ipr/search_error.html", {"q": q, "error": "The search string must contain at least one digit" }, |
| 125 | + context_instance=RequestContext(request) ) |
| 126 | + iprs = [] |
| 127 | + for ipr in IprDetail.objects.filter(status__in=[1,3]): |
| 128 | + if ((q in ipr.patents) | |
| 129 | + patent_file_search(ipr.legacy_url_0, q) | |
| 130 | + patent_file_search(ipr.legacy_url_1, q) | |
| 131 | + patent_file_search(ipr.legacy_url_2, q) ): |
| 132 | + iprs.append(ipr) |
| 133 | + count = len(iprs) |
| 134 | + iprs = [ ipr for ipr in iprs if not ipr.updated_by.all() ] |
| 135 | + # Some extra information, to help us render 'and' between the |
| 136 | + # last two documents in a sequence |
| 137 | + iprs.sort(key=lambda x: x.ipr_id, reverse=True) # Reverse sort |
| 138 | + mark_last_doc(iprs) |
| 139 | + return render("ipr/search_patent_result.html", {"q": q, "iprs": iprs, "count": count }, |
| 140 | + context_instance=RequestContext(request) ) |
105 | 141 |
|
106 | 142 | # Search by wg acronym |
107 | 143 | # Document list with IPRs |
|
0 commit comments