From 1652b235900e6db256ef6f5e8c9d13e2a54382de Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 4 Sep 2018 08:30:20 -0400 Subject: [PATCH] prevent samefagging, show user votes on pageload, add todo list --- quest/events.py | 14 ++++++--- quest/jinja2/quest/quest.html | 2 +- quest/migrations/0012_auto_20180904_0732.py | 17 +++++++++++ quest/models.py | 3 ++ quest/static/quest.js | 8 +++++ todo | 34 +++++++++++++++++++++ 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 quest/migrations/0012_auto_20180904_0732.py create mode 100644 todo diff --git a/quest/events.py b/quest/events.py index d5ef839..44d611f 100644 --- a/quest/events.py +++ b/quest/events.py @@ -11,6 +11,7 @@ import types import random import bleach +from django.db import IntegrityError from django.utils.timezone import localtime from quest.models import * @@ -341,12 +342,15 @@ def vote(socket, data): ) if user.username: v.user = user - v.save() + try: + v.save() + except IntegrityError: # shouldn't we check this first? + return - data = {} - data['option_id'] = option_id - data['polarity'] = polarity - socket.send('vote', data) + data = {} + data['option_id'] = option_id + data['polarity'] = polarity + socket.send('vote', data) events = {} diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index bd93db4..38da27b 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -71,7 +71,7 @@ {% for option in poll_options.filter(poll=post.poll).order_by("id") %} - + {{ option.text }} diff --git a/quest/migrations/0012_auto_20180904_0732.py b/quest/migrations/0012_auto_20180904_0732.py new file mode 100644 index 0000000..eb987ca --- /dev/null +++ b/quest/migrations/0012_auto_20180904_0732.py @@ -0,0 +1,17 @@ +# Generated by Django 2.1 on 2018-09-04 11:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('quest', '0011_auto_20180902_2007'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='pollvote', + unique_together={('option', 'ip_address')}, + ), + ] diff --git a/quest/models.py b/quest/models.py index e8196ac..e9a4a5c 100644 --- a/quest/models.py +++ b/quest/models.py @@ -126,6 +126,9 @@ class PollVote(models.Model): null=True) ip_address = models.GenericIPAddressField() + class Meta: + unique_together = ('option', 'ip_address') + class PageTitle(models.Model): """ diff --git a/quest/static/quest.js b/quest/static/quest.js index d17bea4..e8fece6 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -140,6 +140,14 @@ function vote(post_id, option_id) { let polarity = document.getElementById('pollInput-' + option_id).checked; socket.send('vote', {post_id: post_id, option_id: option_id, polarity: polarity, quest_id: quest_id}); } +function submitWritein(post_id) { + let writeinInput = document.getElementById('writeinInput'); + if (!writeinInput) { return; } + let option_text = writeinInput.value; + writeinInput.value = ''; + if (!option_text) { return; } + socket.emit('write_in', {option_text: option_text, post_id: post_id, room: room_id}); +} /* Helpers */ function padToTwo(number) { diff --git a/todo b/todo new file mode 100644 index 0000000..ca52b9b --- /dev/null +++ b/todo @@ -0,0 +1,34 @@ +New Features: +Pages/appendixes +Live indicator/countdown +Notifications +Anonymous names +Banner images +Search page +Front page to show new quests +Webm posting +(you) counter +Enable namefagging +Account managament/logout +Display profile link in header bar +Tagging system +Quote backlinks +Make chat hideable + +Improvements: +Revamp post editing +More options for text posts (lists and so on) +More rigorous input checking in events.py +New post displays chat message +Record email on signup +Change urls +Poll vote highlights entire option +Poll vote doesn't disappear checkbox +Total voters per poll +Chat archives +Only last 100 (50?) chat messages are loaded on page load +Adjust quote preview postioning + +Port from old code: +Edit post +Writein