From c99a6ba24ec65208cd5dca356e164062183fccc0 Mon Sep 17 00:00:00 2001 From: iou1name Date: Mon, 15 Apr 2019 11:37:02 -0400 Subject: [PATCH] Removed need for 'Server' user --- README.md | 4 ++-- quest/events.py | 15 ++++++--------- quest/jinja2/quest/chat.html | 2 +- quest/migrations/0011_message_server.py | 18 ++++++++++++++++++ quest/models.py | 1 + 5 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 quest/migrations/0011_message_server.py diff --git a/README.md b/README.md index 878d076..6bf1eb5 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ titivillus=# \q 1. Get on the floor 2. Walk the dinosaur 3. Set `STATIC_ROOT` under `settings.py` appropriately -4. Run `python manage.py collectstatic` -5. Create \[super\]user named `Server` and set id in settings.py +4. Run `python manage.py collectstatic --link` +5. Run `python manage.py makemigrations` and `python manage.py migrate` ## Usage `gunicorn -b localhost:5100 -e SCRIPT_NAME=/titivillus titivillus.wsgi` diff --git a/quest/events.py b/quest/events.py index 23e8b18..4cf7dd9 100644 --- a/quest/events.py +++ b/quest/events.py @@ -191,10 +191,9 @@ def text_post(socket, data): data['post_id'] = p.id socket.send('new_post', data) - server = User.objects.get(id=settings.SERVER_USER_ID) m = Message( quest=quest, - user=server, + server=True, message=f"{quest.owner.username} made a new post!", ) m.save() @@ -202,7 +201,7 @@ def text_post(socket, data): data['message_id'] = m.id data['message'] = m.message data['date'] = int(time.time()) - data['name'] = server.username + data['name'] = 'Server' data['anonymize'] = False socket.send('message', data) @@ -273,10 +272,9 @@ def dice_post(socket, data): data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M') socket.send('new_post', data) - server = User.objects.get(id=settings.SERVER_USER_ID) m = Message( quest=quest, - user=server, + server=True, message=f"{quest.owner.username} made a new dice call!", ) m.save() @@ -284,7 +282,7 @@ def dice_post(socket, data): data['message_id'] = m.id data['message'] = m.message data['date'] = int(time.time()) - data['name'] = server.username + data['name'] = 'Server' data['anonymize'] = False socket.send('message', data) @@ -343,10 +341,9 @@ def poll_post(socket, data): data['allow_writein'] = allow_writein socket.send('new_post', data) - server = User.objects.get(id=settings.SERVER_USER_ID) m = Message( quest=quest, - user=server, + server=True, message=f"{quest.owner.username} made a new poll!", ) m.save() @@ -354,7 +351,7 @@ def poll_post(socket, data): data['message_id'] = m.id data['message'] = m.message data['date'] = int(time.time()) - data['name'] = server.username + data['name'] = 'Server' data['anonymize'] = False socket.send('message', data) diff --git a/quest/jinja2/quest/chat.html b/quest/jinja2/quest/chat.html index c879a36..b988fc4 100644 --- a/quest/jinja2/quest/chat.html +++ b/quest/jinja2/quest/chat.html @@ -5,7 +5,7 @@ {% for message in chat_messages %}
- {% if quest.owner == message.user or message.user.id == server_user_id or not quest.anonymize %}{{ message.user.username or quest.anon_name }}{% else %}{{ quest.anon_name }}{% endif %} + {% if message.server %}Server{% else %}{% if quest.owner == message.user or message.user.id == server_user_id or not quest.anonymize %}{{ message.user.username or quest.anon_name }}{% else %}{{ quest.anon_name }}{% endif %}{% endif %} {{ localtime(message.timestamp).strftime('%Y-%m-%d %H:%M:%S') }} No.{{ message.id }}
diff --git a/quest/migrations/0011_message_server.py b/quest/migrations/0011_message_server.py new file mode 100644 index 0000000..b7c67cf --- /dev/null +++ b/quest/migrations/0011_message_server.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-15 14:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('quest', '0010_quest_banner_url'), + ] + + operations = [ + migrations.AddField( + model_name='message', + name='server', + field=models.BooleanField(default=False), + ), + ] diff --git a/quest/models.py b/quest/models.py index d37b284..3f37d7e 100644 --- a/quest/models.py +++ b/quest/models.py @@ -43,6 +43,7 @@ class Message(models.Model): on_delete=models.CASCADE, blank=True, null=True) + server = models.BooleanField(default=False) timestamp = models.DateTimeField(auto_now=True) message = models.TextField(max_length=512)