Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vote results updates not filtered by trackers in list #266

Open
GPHemsley opened this issue Feb 9, 2021 · 0 comments
Open

Vote results updates not filtered by trackers in list #266

GPHemsley opened this issue Feb 9, 2021 · 0 comments

Comments

@GPHemsley
Copy link
Contributor

I have multiple tracker lists with different people tracked in each. However, when an e-mail update comes out, each vote record shows the votes for every person across all trackers. This leads to duplicated information and, in many cases (like the recent vote-a-rama), very long e-mails.

I think the code responsible is here:

def render_event(self, eventid, feeds):
if feeds:
from person.models import Person
my_reps = set()
for f in feeds:
try:
my_reps.add(Person.from_feed(f))
except ValueError:
pass # not a person-related feed
my_reps = sorted(my_reps, key = lambda p : p.sortname)
else:
my_reps = []
# fetch the whole vote and our summary, and keep it cached with this object
# because in email updates this object is held in memory for the duration of
# sending out all email updates
if not hasattr(self, "_cached_event_data"):
oursummary = self.get_summary()
all_votes = {
vv.person: vv.option
for vv in
self.voters.select_related('person', 'option')
}
self._cached_event_data = [oursummary, all_votes]
else:
oursummary, all_votes = self._cached_event_data
return {
"type": "Vote",
"date": self.created,
"title": self.question,
"url": self.get_absolute_url(),
"body_text_template":
"""{{summary|safe}}
{% for voter in voters %}{{voter.name|safe}}: {{voter.vote|safe}}
{% endfor %}
{% if oursummary %}{{oursummary.plain_text|truncatewords:120|safe}}{% endif %}""",
"body_html_template":
"""<p>{{summary}}</p>
{% for voter in voters %}
<p><a href="{{SITE_ROOT}}{{voter.url}}">{{voter.name}}</a>: {{voter.vote}}</p>
{% endfor %}
{% if oursummary %}{{oursummary.as_html|truncatewords_html:120|safe}}{% endif %}
""",
"context": {
"summary": self.summary(),
"oursummary": oursummary,
"voters":
[
{ "url": p.get_absolute_url(), "name": p.name_lastonly(), "vote": all_votes[p].value }
for p in my_reps if p in all_votes
]
if feeds != None else []
},
"thumbnail_url": self.get_thumbnail_url(),
"large_thumbnail_url": self.get_absolute_url() + "/card",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant