|
6 | 6 | from django.shortcuts import render_to_response as render |
7 | 7 | from ietf.utils import log |
8 | 8 | from ietf.ipr.view_sections import section_table |
| 9 | +from ietf.idtracker.models import Rfc, InternetDraft |
9 | 10 |
|
10 | 11 | # ---------------------------------------------------------------- |
11 | 12 | # Callback methods for special field cases. |
@@ -111,11 +112,48 @@ def __init__(self, *args, **kw): |
111 | 112 |
|
112 | 113 | BaseIprForm.__init__(self, *args, **kw) |
113 | 114 | # Special validation code |
114 | | - def clean(self): |
115 | | - # Required: |
116 | | - # Submitter form filled in or 'same-as-ietf-contact' marked |
117 | | - # Only one of rfc, draft, and other info fields filled in |
118 | | - # RFC exists or draft exists and has right rev. or ... |
| 115 | + def clean_rfclist(self): |
| 116 | + rfclist = self.clean_data.get("rfclist", None) |
| 117 | + if rfclist: |
| 118 | + rfclist = re.sub("(?i) *[,;]? *rfc[- ]?", " ", rfclist) |
| 119 | + rfclist = rfclist.strip().split() |
| 120 | + for rfc in rfclist: |
| 121 | + try: |
| 122 | + Rfc.objects.get(rfc_number=int(rfc)) |
| 123 | + except: |
| 124 | + raise forms.ValidationError("Unknown RFC number: %s - please correct this." % rfc) |
| 125 | + rfclist = " ".join(rfclist) |
| 126 | + else: |
| 127 | + # Check that not all three fields are empty. We only need to |
| 128 | + # do this for one of the fields. |
| 129 | + draftlist = self.clean_data.get("draftlist", None) |
| 130 | + other = self.clean_data.get("other_designations", None) |
| 131 | + if not draftlist and not other: |
| 132 | + raise forms.ValidationError("One of the Document fields below must be filled in") |
| 133 | + return rfclist |
| 134 | + def clean_draftlist(self): |
| 135 | + draftlist = self.clean_data.get("draftlist", None) |
| 136 | + if draftlist: |
| 137 | + draftlist = re.sub(" *[,;] *", " ", draftlist) |
| 138 | + draftlist = draftlist.strip().split() |
| 139 | + for draft in draftlist: |
| 140 | + if draft.endswith(".txt"): |
| 141 | + draft = draft[:-4] |
| 142 | + if re.search("-[0-9][0-9]$", draft): |
| 143 | + filename = draft[:-3] |
| 144 | + rev = draft[-2:] |
| 145 | + else: |
| 146 | + filename = draft |
| 147 | + rev = None |
| 148 | + #log("ID: %s, rev %s" % (filename, rev)) |
| 149 | + try: |
| 150 | + id = InternetDraft.objects.get(filename=filename) |
| 151 | + #log("ID Lookup result: %s, %s" % (id.filename, id.revision)) |
| 152 | + except Exception, e: |
| 153 | + log("Exception: %s" % e) |
| 154 | + raise forms.ValidationError("Unknown Internet-Draft: %s - please correct this." % filename) |
| 155 | + if rev and id.revision != rev: |
| 156 | + raise forms.ValidationError("Unexpected revision '%s' for draft %s - the current revision is %s. Please check this." % (rev, filename, id.revision)) |
119 | 157 | pass |
120 | 158 |
|
121 | 159 | if request.method == 'POST': |
|
0 commit comments