|
3 | 3 | from election.models import Election
|
4 | 4 | from issue.models import Issue
|
5 | 5 |
|
| 6 | + |
6 | 7 | @jsonize
|
7 | 8 | def recent_activity(request):
|
8 | 9 |
|
9 | 10 | # Names prefixed with "q_" to distinguish them as queries. We will be
|
10 | 11 | # returning the same data in JSON format, which we will call "issues" and
|
11 | 12 | # "elections".
|
12 |
| - q_issues = Issue.objects.select_related('polity').recent().order_by('polity__id', '-deadline_votes') |
13 |
| - q_elections = Election.objects.prefetch_related( |
14 |
| - 'electionvote_set', |
15 |
| - 'candidate_set' |
16 |
| - ).select_related( |
17 |
| - 'result' |
18 |
| - ).recent() |
| 13 | + q_issues = ( |
| 14 | + Issue.objects.select_related('polity') |
| 15 | + .recent() |
| 16 | + .order_by('polity__id', '-deadline_votes') |
| 17 | + ) |
| 18 | + q_elections = ( |
| 19 | + Election.objects.prefetch_related('electionvote_set', 'candidate_set') |
| 20 | + .select_related('result') |
| 21 | + .recent() |
| 22 | + ) |
19 | 23 |
|
20 | 24 | issues = []
|
21 | 25 | for q_issue in q_issues:
|
22 |
| - issues.append({ |
23 |
| - # Web location for further info on the issue. |
24 |
| - 'url': request.build_absolute_uri( |
25 |
| - reverse('issue', args=(q_issue.polity_id, q_issue.id)) |
26 |
| - ), |
27 |
| - |
28 |
| - # The polity to which this issue belongs. |
29 |
| - 'polity': q_issue.polity.name, |
30 |
| - |
31 |
| - # The polity's short name, if available. |
32 |
| - 'polity_shortname': q_issue.polity.name_short, |
33 |
| - |
34 |
| - # A unique identifier for formal reference. Example: 6/2019 |
35 |
| - 'log_number': '%d/%d' % (q_issue.issue_num, q_issue.issue_year), |
36 |
| - |
37 |
| - # The issue's name or title. |
38 |
| - 'name': q_issue.name, |
39 |
| - |
40 |
| - # Options are: concluded/voting/accepting_proposals/discussion |
41 |
| - # Note that the state does not give the *result*, i.e. whether the |
42 |
| - # proposal was accepted or rejected, but rather where the issue is |
43 |
| - # currently in the decision-making process. Therefore "concluded" |
44 |
| - # only means that the issue has concluded, but does not tell us |
45 |
| - # *how* it concluded. |
46 |
| - 'state': q_issue.issue_state(), |
47 |
| - |
48 |
| - # Translated, human-readable version of the issue state. |
49 |
| - 'state_human_readable': q_issue.get_issue_state_display(), |
50 |
| - |
51 |
| - # A boolean indicating whether the issue has been approved or not. |
52 |
| - 'majority_reached': q_issue.majority_reached(), |
53 |
| - |
54 |
| - # Translated, human-readable version of the result. |
55 |
| - 'majority_reached_human_readable': q_issue.get_majority_reached_display(), |
56 |
| - |
57 |
| - # When the issue's fate is not determined by vote from within |
58 |
| - # Wasa2il, for example when a vote is made outside of Wasa2il but |
59 |
| - # still placed here for reference or historical reasons, or when |
60 |
| - # an issue is retracted without ever coming to a vote. |
61 |
| - # |
62 |
| - # Consider displaying only this value if it is non-null, and the |
63 |
| - # `majority_reached` value only if this is null. |
64 |
| - 'special_process': q_issue.special_process, |
65 |
| - |
66 |
| - # Translated, human-readable version of the result. |
67 |
| - 'special_process_human_readable': q_issue.get_special_process_display(), |
68 |
| - |
69 |
| - # Comment count. |
70 |
| - 'comment_count': q_issue.comment_count, |
71 |
| - |
72 |
| - # Vote count. |
73 |
| - 'vote_count': q_issue.votecount, |
74 |
| - }) |
| 26 | + issues.append( |
| 27 | + { |
| 28 | + # Web location for further info on the issue. |
| 29 | + 'url': request.build_absolute_uri( |
| 30 | + reverse('issue', args=(q_issue.polity_id, q_issue.id)) |
| 31 | + ), |
| 32 | + # The polity to which this issue belongs. |
| 33 | + 'polity': q_issue.polity.name, |
| 34 | + # The polity's short name, if available. |
| 35 | + 'polity_shortname': q_issue.polity.name_short, |
| 36 | + # A unique identifier for formal reference. Example: 6/2019 |
| 37 | + 'log_number': '%d/%d' |
| 38 | + % (q_issue.issue_num, q_issue.issue_year), |
| 39 | + # The issue's name or title. |
| 40 | + 'name': q_issue.name, |
| 41 | + # Options are: concluded/voting/accepting_proposals/discussion |
| 42 | + # Note that the state does not give the *result*, i.e. whether the |
| 43 | + # proposal was accepted or rejected, but rather where the issue is |
| 44 | + # currently in the decision-making process. Therefore "concluded" |
| 45 | + # only means that the issue has concluded, but does not tell us |
| 46 | + # *how* it concluded. |
| 47 | + 'state': q_issue.issue_state(), |
| 48 | + # Translated, human-readable version of the issue state. |
| 49 | + 'state_human_readable': q_issue.get_issue_state_display(), |
| 50 | + # A boolean indicating whether the issue has been approved or not. |
| 51 | + 'majority_reached': q_issue.majority_reached(), |
| 52 | + # Translated, human-readable version of the result. |
| 53 | + 'majority_reached_human_readable': q_issue.get_majority_reached_display(), |
| 54 | + # When the issue's fate is not determined by vote from within |
| 55 | + # Wasa2il, for example when a vote is made outside of Wasa2il but |
| 56 | + # still placed here for reference or historical reasons, or when |
| 57 | + # an issue is retracted without ever coming to a vote. |
| 58 | + # |
| 59 | + # Consider displaying only this value if it is non-null, and the |
| 60 | + # `majority_reached` value only if this is null. |
| 61 | + 'special_process': q_issue.special_process, |
| 62 | + # Translated, human-readable version of the result. |
| 63 | + 'special_process_human_readable': q_issue.get_special_process_display(), |
| 64 | + # Comment count. |
| 65 | + 'comment_count': q_issue.comment_count, |
| 66 | + # Vote count. |
| 67 | + 'vote_count': q_issue.votecount, |
| 68 | + } |
| 69 | + ) |
75 | 70 |
|
76 | 71 | elections = []
|
77 | 72 | for q_election in q_elections:
|
78 | 73 | # See comments for issue above, which are more detailed but are mostly
|
79 | 74 | # applicable to this section as well.
|
80 |
| - elections.append({ |
81 |
| - 'url': request.build_absolute_uri(reverse('election', args=(q_election.polity_id, q_election.id))), |
82 |
| - 'polity': q_election.polity.name, |
83 |
| - 'polity_shortname': q_election.polity.name_short, |
84 |
| - 'name': q_election.name, |
85 |
| - 'state': q_election.election_state(), |
86 |
| - 'state_human_readable': q_election.get_election_state_display(), |
87 |
| - 'candidate_count': q_election.candidate_set.count(), |
88 |
| - 'vote_count': q_election.get_vote_count(), |
89 |
| - }) |
| 75 | + elections.append( |
| 76 | + { |
| 77 | + 'url': request.build_absolute_uri( |
| 78 | + reverse( |
| 79 | + 'election', args=(q_election.polity_id, q_election.id) |
| 80 | + ) |
| 81 | + ), |
| 82 | + 'polity': q_election.polity.name, |
| 83 | + 'polity_shortname': q_election.polity.name_short, |
| 84 | + 'name': q_election.name, |
| 85 | + 'state': q_election.election_state(), |
| 86 | + 'state_human_readable': q_election.get_election_state_display(), |
| 87 | + 'candidate_count': q_election.candidate_set.count(), |
| 88 | + 'vote_count': q_election.get_vote_count(), |
| 89 | + } |
| 90 | + ) |
90 | 91 |
|
91 | 92 | return {
|
92 | 93 | 'elections': elections,
|
|
0 commit comments