|
3 | 3 | from ietf.doc.models import Document |
4 | 4 | from ietf.group.models import Group |
5 | 5 | from ietf.person.models import Person |
| 6 | +from ietf.doc.models import State |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class RuleManager(object): |
@@ -133,5 +134,161 @@ class WithTextRule(RuleManager): |
133 | 134 | def get_documents(self): |
134 | 135 | return Document.objects.filter(type='draft', states__slug='active').filter(name__icontains=self.value).distinct() |
135 | 136 |
|
| 137 | +class IABInState(RuleManager): |
| 138 | + codename = 'in_iab_state' |
| 139 | + description = 'All I-Ds that are in a particular IAB state' |
| 140 | + |
| 141 | + def get_documents(self): |
| 142 | + return Document.objects.filter(states__type='draft-stream-iab', states__slug=self.value).distinct() |
| 143 | + |
| 144 | + def options(self): |
| 145 | + return [(i.slug, i.name) for i in State.objects.filter(type='draft-stream-iab').order_by('name')] |
| 146 | + |
| 147 | + def show_value(self): |
| 148 | + try: |
| 149 | + return State.objects.get(type='draft-stream-iab', slug=self.value).name |
| 150 | + except State.DoesNotExist: |
| 151 | + return self.value |
| 152 | + |
| 153 | +class IANAInState(RuleManager): |
| 154 | + codename = 'in_iana_state' |
| 155 | + description = 'All I-Ds that are in a particular IANA state' |
| 156 | + |
| 157 | + def get_documents(self): |
| 158 | + return Document.objects.filter(states__type='draft-iana-review', states__slug=self.value).distinct() |
| 159 | + |
| 160 | + def options(self): |
| 161 | + return [(i.slug, i.name) for i in State.objects.filter(type='draft-iana-review').order_by('name')] |
| 162 | + |
| 163 | + def show_value(self): |
| 164 | + try: |
| 165 | + return State.objects.get(type='draft-iana-review', slug=self.value).name |
| 166 | + except State.DoesNotExist: |
| 167 | + return self.value |
| 168 | + |
| 169 | +class IESGInState(RuleManager): |
| 170 | + codename = 'in_iesg_state' |
| 171 | + description = 'All I-Ds that are in a particular IESG state' |
| 172 | + |
| 173 | + def get_documents(self): |
| 174 | + return Document.objects.filter(states__type='draft-iesg', states__slug=self.value).distinct() |
| 175 | + |
| 176 | + def options(self): |
| 177 | + return [(i.slug, i.name) for i in State.objects.filter(type='draft-iesg').order_by('name')] |
| 178 | + |
| 179 | + def show_value(self): |
| 180 | + try: |
| 181 | + return State.objects.get(type='draft-iesg', slug=self.value).name |
| 182 | + except State.DoesNotExist: |
| 183 | + return self.value |
| 184 | + |
| 185 | +class IRTFInState(RuleManager): |
| 186 | + codename = 'in_irtf_state' |
| 187 | + description = 'All I-Ds that are in a particular IRTF state' |
| 188 | + |
| 189 | + def get_documents(self): |
| 190 | + return Document.objects.filter(states__type='draft-stream-irtf', states__slug=self.value).distinct() |
| 191 | + |
| 192 | + def options(self): |
| 193 | + return [(i.slug, i.name) for i in State.objects.filter(type='draft-stream-irtf').order_by('name')] |
| 194 | + |
| 195 | + def show_value(self): |
| 196 | + try: |
| 197 | + return State.objects.get(type='draft-stream-irtf', slug=self.value).name |
| 198 | + except State.DoesNotExist: |
| 199 | + return self.value |
| 200 | + |
| 201 | +class ISEInState(RuleManager): |
| 202 | + codename = 'in_ise_state' |
| 203 | + description = 'All I-Ds that are in a particular ISE state' |
| 204 | + |
| 205 | + def get_documents(self): |
| 206 | + return Document.objects.filter(states__type='draft-stream-ise', states__slug=self.value).distinct() |
| 207 | + |
| 208 | + def options(self): |
| 209 | + return [(i.slug, i.name) for i in State.objects.filter(type='draft-stream-ise').order_by('name')] |
| 210 | + |
| 211 | + def show_value(self): |
| 212 | + try: |
| 213 | + return State.objects.get(type='draft-stream-ise', slug=self.value).name |
| 214 | + except State.DoesNotExist: |
| 215 | + return self.value |
| 216 | + |
| 217 | +class RfcEditorInState(RuleManager): |
| 218 | + codename = 'in_rfcEdit_state' |
| 219 | + description = 'All I-Ds that are in a particular RFC Editor state' |
| 220 | + |
| 221 | + def get_documents(self): |
| 222 | + return Document.objects.filter(states__type='draft-rfceditor', states__slug=self.value).distinct() |
| 223 | + |
| 224 | + def options(self): |
| 225 | + return [(i.slug, i.type_id + ": " + i.name) for i in State.objects.filter(type='draft-rfceditor').order_by('name')] |
| 226 | + |
| 227 | + def show_value(self): |
| 228 | + try: |
| 229 | + return State.objects.get(type='draft-rfceditor', slug=self.value).name |
| 230 | + except State.DoesNotExist: |
| 231 | + return self.value |
| 232 | + |
| 233 | +class WGInState(RuleManager): |
| 234 | + codename = 'in_wg_state' |
| 235 | + description = 'All I-Ds that are in a particular Working Group state' |
| 236 | + |
| 237 | + def get_documents(self): |
| 238 | + return Document.objects.filter(states__type='draft-stream-ietf', states__slug=self.value).distinct() |
| 239 | + |
| 240 | + def options(self): |
| 241 | + return [(i.slug, i.type_id + ": " + i.name) for i in State.objects.filter(type='draft-stream-ietf').order_by('name')] |
| 242 | + |
| 243 | + def show_value(self): |
| 244 | + try: |
| 245 | + return State.objects.get(type='draft-stream-ietf', slug=self.value).name |
| 246 | + except State.DoesNotExist: |
| 247 | + return self.value |
| 248 | + |
| 249 | +class RfcWgAsociatedRule(RuleManager): |
| 250 | + codename = 'wg_asociated_rfc' |
| 251 | + description = 'All RFCs associated with a particular WG' |
| 252 | + |
| 253 | + def get_documents(self): |
| 254 | + return Document.objects.filter(type='draft', states__slug='rfc').filter(group__acronym=self.value).distinct() |
| 255 | + |
| 256 | + def options(self): |
| 257 | + return [(i.acronym, "%s — %s"%(i.acronym, i.name)) for i in Group.objects.filter(type='wg').distinct().order_by('acronym')] |
| 258 | + |
| 259 | + def show_value(self): |
| 260 | + try: |
| 261 | + return Group.objects.get(type='draft', acronym=self.value).name |
| 262 | + except Group.DoesNotExist: |
| 263 | + return self.value |
| 264 | + |
| 265 | + |
| 266 | +class RfcAreaAsociatedRule(RuleManager): |
| 267 | + codename = 'area_asociated_rfc' |
| 268 | + description = 'All RFCs associated with all WGs in a particular Area' |
| 269 | + |
| 270 | + def get_documents(self): |
| 271 | + return Document.objects.filter(type='draft', states__slug='rfc').filter(group__parent__acronym=self.value, group__parent__type='area').distinct() |
| 272 | + |
| 273 | + def options(self): |
| 274 | + return [(i.acronym, "%s — %s"%(i.acronym, i.name)) for i in Group.objects.filter(type='area').distinct().order_by('name')] |
| 275 | + |
| 276 | + def show_value(self): |
| 277 | + try: |
| 278 | + return Group.objects.get(type='draft', acronym=self.value).name |
| 279 | + except Group.DoesNotExist: |
| 280 | + return self.value |
| 281 | + |
| 282 | + |
| 283 | +class RfcAuthorRule(RuleManager): |
| 284 | + codename = 'author_rfc' |
| 285 | + description = 'All RFCs with a particular author' |
| 286 | + |
| 287 | + def get_documents(self): |
| 288 | + return Document.objects.filter(type='draft', states__slug='rfc').filter(authors__person__name__icontains=self.value).distinct() |
| 289 | + |
| 290 | + |
136 | 291 |
|
137 | 292 | TYPES_OF_RULES = [(i.codename, i.description) for i in RuleManager.__subclasses__()] |
| 293 | + |
| 294 | + |
0 commit comments