@@ -227,44 +227,44 @@ def get_context_data(self, **kwargs):
227
227
228
228
return context
229
229
230
- class AffectedURLsListView (LoginRequiredMixin , ListView ):
230
+ class BaseAffectedURLsListView (LoginRequiredMixin , ListView ):
231
231
"""
232
- Display a list of URLs affected by a match pattern
232
+ Base view for displaying a list of URLs affected by a match pattern
233
233
"""
234
-
235
234
model = CandidateURL
236
235
template_name = "sde_collections/affected_urls.html"
237
236
context_object_name = "affected_urls"
237
+ pattern_model = None
238
+ pattern_type = None
238
239
239
240
def get_queryset (self ):
240
-
241
- if 'exclude-pattern' in self .request .path :
242
- self .pattern = ExcludePattern .objects .get (id = self .kwargs ["id" ])
243
- self .pattern_type = "Exclude"
244
- elif 'include-pattern' in self .request .path :
245
- self .pattern = IncludePattern .objects .get (id = self .kwargs ["id" ])
246
- self .pattern_type = "Include"
247
- elif 'title-pattern' in self .request .path :
248
- self .pattern = TitlePattern .objects .get (id = self .kwargs ["id" ])
249
- self .pattern_type = "Title"
250
- elif 'document-type-pattern' in self .request .path :
251
- self .pattern = DocumentTypePattern .objects .get (id = self .kwargs ["id" ])
252
- self .pattern_type = "Document Type"
253
- else :
254
- return super ().get_queryset ()
255
-
256
- queryset = self .pattern .matched_urls ()
257
- return queryset
241
+ self .pattern = self .pattern_model .objects .get (id = self .kwargs ["id" ])
242
+ return self .pattern .matched_urls ()
258
243
259
244
def get_context_data (self , ** kwargs ):
260
245
context = super ().get_context_data (** kwargs )
261
246
context ["pattern" ] = self .pattern
262
- context ["url_count" ] = self .pattern . matched_urls ().count ()
247
+ context ["url_count" ] = self .get_queryset ().count ()
263
248
context ["collection" ] = self .pattern .collection
264
249
context ["pattern_type" ] = self .pattern_type
265
-
266
250
return context
267
251
252
+ class ExcludePatternAffectedURLsListView (BaseAffectedURLsListView ):
253
+ pattern_model = ExcludePattern
254
+ pattern_type = "Exclude"
255
+
256
+ class IncludePatternAffectedURLsListView (BaseAffectedURLsListView ):
257
+ pattern_model = IncludePattern
258
+ pattern_type = "Include"
259
+
260
+ class TitlePatternAffectedURLsListView (BaseAffectedURLsListView ):
261
+ pattern_model = TitlePattern
262
+ pattern_type = "Title"
263
+
264
+ class DocumentTypePatternAffectedURLsListView (BaseAffectedURLsListView ):
265
+ pattern_model = DocumentTypePattern
266
+ pattern_type = "Document Type"
267
+
268
268
class SdeDashboardView (LoginRequiredMixin , ListView ):
269
269
model = Collection
270
270
template_name = "sde_collections/sde_dashboard.html"
0 commit comments