Repository navigation
Migrate:
require("community.schema").run_migrations(45)Additions
- Add polls to topics. A topic can have one poll with a question, a set of choices, single or multiple choice voting, anonymous or named voters, and results that are either public or only visible to the topic author and moderators. Polls open when created and close at an end date (default one day, max 30 days).
Polls are off by default. Override Categories\allowed_to_create_poll(user) to enable them.
TopicPolls
- Models:
TopicPolls,PollChoices,PollVotes, withTopicsgetting apollrelation vote_typeenum:single,multipleanonymoushides voter names from everyone but moderators,hide_resultshides vote counts from everyone but the author and moderatorsversionis incremented when the question or choices change so a stale vote form is rejectedallowed_to_vote,allowed_to_view_results,allowed_to_view_voters,is_open,is_closed,has_votes,total_vote_count,reset_votesTopicPolls\filter_text(text)is called on the question, choices and descriptions before saving. Override it to filter or reject text, likePosts\filter_bodyPollChoices\vote(user)creates a vote, replacing the user's existing vote forsinglepolls. Whether the vote is counted comes fromCommunityUsers\count_poll_vote_for(poll_choice), an override point that defaults totruePollChoices\preload_recent_votes(choices)loads the newest voters on each choice
TopicPollsFlow (community.flows.topic_polls)
votewithchoice_id,action(createordelete) andpoll_version. Sets@poll,@choiceand@votechoice_voterspaginates the voters of a choice, sets@votesand@next_pageclose_pollfor the topic author or a moderator. A moderator closing someone else's poll writes atopic.close_pollmoderation logdelete_pollandreset_poll_votesfor moderators, logged astopic.delete_pollandtopic.reset_poll_votes
Posting with polls
new_topicacceptstopic[poll]withpoll_question,description,vote_type,anonymous,hide_results,end_date(UTCYYYY-MM-DD HH:MM:SS) andchoices[n][choice_text],choices[n][description]. A poll on a topic that goes to the pending queue is created when the pending post is promoted, with the duration measured from promotionedit_poston a topic post accepts the same fields aspost[poll], withchoices[n][id]to keep an existing choice. Choices not submitted are deleted along with their votes. Once a poll has votes the question, vote type and existing choices are locked for the author, a moderator can still change them and the edit is logged astopic.edit_poll. The end date can be changed while the poll is open, a closed poll can't be reopenedBrowsingFlow\topic_postspreloads the topic's poll, choices and the viewing user's votes.preload_poll_votersis opt-in for views that list voters
Other
shapes.utc_timestampfor validating aYYYY-MM-DD HH:MM:SSstringAsyncCounter\syncreturns the number of counters synced- Spec factories for
TopicPollsandPollChoices
Changes
- Moderating a pending post from
CategoriesFlow\edit_pending_postorPendingPostsFlownow writes a moderation log for every action:post.approve_pendingon promote andpending_post.status(...)otherwise, with the user and topic as log objects.edit_pending_postaccepts theignoredstatus.ModerationLogshas apending_postobject type ModerationLogs\get_action_textcovers the poll actions- Blocks no longer prevent admins or moderators from replying to the user who blocked them
Posts\pin_torefuses to pin a reply above the topic post, andunpinputs the post back in date order instead of one position earlyPosts\hard_deleteusesModel.delete