From 1fbc398a9a2a18960a024bb6b3af488222dc1617 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 21 Sep 2018 14:18:54 -0400 Subject: [PATCH] anonymous names are editable --- quest/forms.py | 6 ++++++ quest/jinja2/quest/edit_quest.html | 2 +- quest/jinja2/quest/quest.html | 3 ++- quest/migrations/0003_quest_anon_name.py | 18 ++++++++++++++++++ quest/models.py | 1 + quest/static/quest.js | 2 +- quest/views.py | 9 ++++++++- todo | 3 --- 8 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 quest/migrations/0003_quest_anon_name.py diff --git a/quest/forms.py b/quest/forms.py index 335f402..e57d1f1 100644 --- a/quest/forms.py +++ b/quest/forms.py @@ -36,3 +36,9 @@ class PollForm(forms.Form): if not value: continue self.fields[key] = forms.CharField(max_length=200) + +class EditQuest(forms.Form): + """ + Form for the /edit_quest page. + """ + anon_name = forms.CharField(max_length=20) diff --git a/quest/jinja2/quest/edit_quest.html b/quest/jinja2/quest/edit_quest.html index cc0ae4a..71b7a7c 100644 --- a/quest/jinja2/quest/edit_quest.html +++ b/quest/jinja2/quest/edit_quest.html @@ -15,7 +15,7 @@ Anonymous Name: - + Live: diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index e43080e..bcf0e28 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -9,6 +9,7 @@ const quest_id = {{ quest.id }}; const page_num = {{ page_num }}; const SCRIPT_NAME = '{{ request.META["SCRIPT_NAME"] }}'; + const anon_name = '{{ quest.anon_name }}'; {% if request.user == quest.owner %} @@ -148,7 +149,7 @@ {% for message in messages %}
- {{ message.user.username or 'Anonymous' }} + {{ message.user.username or quest.anon_name }} {{ localtime(message.timestamp).strftime('%Y-%m-%d %H:%M:%S') }} No.{{ message.id }}
diff --git a/quest/migrations/0003_quest_anon_name.py b/quest/migrations/0003_quest_anon_name.py new file mode 100644 index 0000000..afe5371 --- /dev/null +++ b/quest/migrations/0003_quest_anon_name.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.1 on 2018-09-21 16:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quest', '0002_auto_20180905_1344'), + ] + + operations = [ + migrations.AddField( + model_name='quest', + name='anon_name', + field=models.CharField(default='Anonymous', max_length=20), + ), + ] diff --git a/quest/models.py b/quest/models.py index e9a4a5c..74e7257 100644 --- a/quest/models.py +++ b/quest/models.py @@ -14,6 +14,7 @@ class Quest(models.Model): owner = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + anon_name = models.CharField(max_length=20, default="Anonymous") class Message(models.Model): diff --git a/quest/static/quest.js b/quest/static/quest.js index dfdd152..479fdc3 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -50,7 +50,7 @@ function load() { /* Websocket receive */ socket.events['message'] = function(data) { let msg_str = '
'; - msg_str = '
' + data.name + ' '; + msg_str = '
' + ((data.name) ? data.name : anon_name) + ' '; msg_str += '' + strftime(data.date) + ' '; msg_str += 'No.' + data.message_id + '
'; msg_str += '
' + data.message + '

'; diff --git a/quest/views.py b/quest/views.py index a73fcb9..9edcb89 100644 --- a/quest/views.py +++ b/quest/views.py @@ -6,6 +6,7 @@ from django.shortcuts import render, redirect from django.http import HttpResponse from .models import Quest, DiceRoll, PollOption, PollVote, PageTitle +from .forms import EditQuest def index(request): """ @@ -38,7 +39,13 @@ def edit_quest(request, quest_id, page_num=1): if quest.owner != request.user: return redirect('quest:quest', quest_id=quest_id, page_num=page_num) if request.method == 'POST': - pass + form = EditQuest(request.POST) + if form.is_valid(): + quest.anon_name = form.cleaned_data['anon_name'] + quest.save() + return redirect('quest:quest',quest_id=quest.id, page_num=page_num) + else: + messages.error(request, "Error") else: pass context = locals() diff --git a/todo b/todo index 15654be..4f136c5 100644 --- a/todo +++ b/todo @@ -2,18 +2,15 @@ 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: More options for text posts (lists and so on)