|
5 | 5 | from django.db.models import Avg, Count, F, Max, Q
|
6 | 6 |
|
7 | 7 | from caps.models import Council
|
| 8 | +from caps.utils import clean_links |
8 | 9 |
|
9 | 10 |
|
10 | 11 | # define this here as mixins imports PlanScore so if we import that then we get
|
@@ -531,6 +532,13 @@ def pretty_code(self):
|
531 | 532 | def is_council_operations_only(self):
|
532 | 533 | return self.code in self.COUNCIL_OPS_QUESTION_CODES
|
533 | 534 |
|
| 535 | + # the questions answered methods of PlanScore return PlanQuestion objects that |
| 536 | + # are used like PlanQuestionScore objects in some cases so we need this in both |
| 537 | + # classes |
| 538 | + @property |
| 539 | + def evidence_links_cleaned(self): |
| 540 | + return clean_links(self.evidence_links) |
| 541 | + |
534 | 542 | @classmethod
|
535 | 543 | def get_average_scores(cls, section=None, council_group=None):
|
536 | 544 | qs = PlanQuestionScore.objects.all()
|
@@ -582,22 +590,7 @@ class PlanQuestionScore(ScoreFilterMixin, models.Model):
|
582 | 590 |
|
583 | 591 | @property
|
584 | 592 | def evidence_links_cleaned(self):
|
585 |
| - # Evidence "links" can be one of: |
586 |
| - # - an empty line |
587 |
| - # - a string like "Airports:" |
588 |
| - # - a string like "www.whatever.com/…" |
589 |
| - # - a string like "http://www…" |
590 |
| - # So attempt to tidy them up, before passing to |
591 |
| - # a template filter like domain_human or urlizetrunc. |
592 |
| - links = [] |
593 |
| - for line in self.evidence_links.splitlines(): |
594 |
| - if line == "": |
595 |
| - pass |
596 |
| - elif line.startswith("www."): |
597 |
| - links.append(f"http://{line}") |
598 |
| - else: |
599 |
| - links.append(line) |
600 |
| - return links |
| 593 | + return clean_links(self.evidence_links) |
601 | 594 |
|
602 | 595 | @classmethod
|
603 | 596 | def all_question_max_score_counts(
|
|
0 commit comments