From 7dfc0dd1a85b9b1937726136a2eef5f0c7aa4ec0 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Mon, 30 Sep 2019 17:02:21 -0500 Subject: [PATCH] Start work on presets Signed-off-by: Etzelia --- admin.py | 3 +- migrations/0002_preset.py | 40 +++++++++++++++ models.py | 70 ++++++++++++++++++++++++++ templates/coreprotect/coreprotect.html | 4 ++ views.py | 3 +- 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 migrations/0002_preset.py diff --git a/admin.py b/admin.py index 1c6e392..6cdea8d 100644 --- a/admin.py +++ b/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django_coreprotect.models import CoArtMap, CoBlock, CoBlockdataMap, CoChat, CoCommand, CoContainer, CoDatabaseLock, \ - CoEntity, CoEntityMap, CoMaterialMap, CoSession, CoSign, CoSkull, CoUser, CoUsernameLog, CoVersion, CoWorld + CoEntity, CoEntityMap, CoMaterialMap, CoSession, CoSign, CoSkull, CoUser, CoUsernameLog, CoVersion, CoWorld, Preset try: pass @@ -22,5 +22,6 @@ try: # admin.site.register(CoUsernameLog) # admin.site.register(CoVersion) # admin.site.register(CoWorld) + admin.site.register(Preset) except admin.sites.AlreadyRegistered: pass diff --git a/migrations/0002_preset.py b/migrations/0002_preset.py new file mode 100644 index 0000000..8dd2cdc --- /dev/null +++ b/migrations/0002_preset.py @@ -0,0 +1,40 @@ +# Generated by Django 2.2.3 on 2019-09-30 21:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_coreprotect', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Preset', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('block_break', models.BooleanField(default=False)), + ('block_place', models.BooleanField(default=False)), + ('chat', models.BooleanField(default=False)), + ('chest_use', models.BooleanField(default=False)), + ('command', models.BooleanField(default=False)), + ('interact', models.BooleanField(default=False)), + ('login_logout', models.BooleanField(default=False)), + ('sign_place', models.BooleanField(default=False)), + ('worlds', models.CharField(default='', max_length=20)), + ('ignore_environment', models.BooleanField(default=False)), + ('oldest_first', models.BooleanField(default=False)), + ('players', models.CharField(max_length=50)), + ('x', models.CharField(default='', max_length=10)), + ('y', models.CharField(default='', max_length=10)), + ('z', models.CharField(default='', max_length=10)), + ('radius', models.CharField(default='', max_length=10)), + ('blocks', models.CharField(default='', max_length=50)), + ('date_from', models.CharField(default='', max_length=10)), + ('date_to', models.CharField(default='', max_length=10)), + ('enabled', models.BooleanField(default=True)), + ], + ), + ] diff --git a/models.py b/models.py index 4a1885f..0702fdf 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,6 @@ from django.db import models +from django.db.models import Q +from django.shortcuts import reverse from django.contrib.auth.models import User from datetime import datetime from django_coreprotect.utils import safe_int @@ -291,6 +293,74 @@ class CoWorld(models.Model): return self.world +class Preset(models.Model): + name = models.CharField(max_length=50) + block_break = models.BooleanField(default=False) + block_place = models.BooleanField(default=False) + chat = models.BooleanField(default=False) + chest_use = models.BooleanField(default=False) + command = models.BooleanField(default=False) + interact = models.BooleanField(default=False) + login_logout = models.BooleanField(default=False) + sign_place = models.BooleanField(default=False) + worlds = models.CharField(max_length=20, default="", blank=True) + ignore_environment = models.BooleanField(default=False) + oldest_first = models.BooleanField(default=False) + players = models.CharField(max_length=50, blank=True) + x = models.CharField(max_length=10, default="", blank=True) + y = models.CharField(max_length=10, default="", blank=True) + z = models.CharField(max_length=10, default="", blank=True) + radius = models.CharField(max_length=10, default="", blank=True) + blocks = models.CharField(max_length=50, default="", blank=True) + date_from = models.CharField(max_length=10, default="", blank=True) + date_to = models.CharField(max_length=10, default="", blank=True) + enabled = models.BooleanField(default=True) + + @property + def link(self): + url = reverse("coreprotect_gui") + "?" + params = [] + if self.block_break: + params.append("block_break=on") + if self.block_place: + params.append("block_place=on") + if self.chat: + params.append("chat=on") + if self.chest_use: + params.append("chest_use=on") + if self.command: + params.append("command=on") + if self.interact: + params.append("interact=on") + if self.login_logout: + params.append("login_logout=on") + if self.sign_place: + params.append("sign_place=on") + if self.worlds: + params.append("world=" + self.worlds) + if self.ignore_environment: + params.append("ignore_environment=on") + if self.oldest_first: + params.append("oldest_first=on") + if self.players: + params.append("players=" + self.players) + if self.x: + params.append("x=" + self.x) + if self.y: + params.append("y=" + self.y) + if self.z: + params.append("z=" + self.z) + if self.radius: + params.append("radius=" + self.radius) + if self.blocks: + params.append("blocks=" + self.blocks) + if self.date_from: + params.append("date_from=" + self.date_from) + if self.date_to: + params.append("date_to=" + self.date_to) + return url + "&".join(params) + + class GUIResult(models.Model): type = models.TextField() unix = models.TextField() diff --git a/templates/coreprotect/coreprotect.html b/templates/coreprotect/coreprotect.html index b8b8dd6..3d1326d 100644 --- a/templates/coreprotect/coreprotect.html +++ b/templates/coreprotect/coreprotect.html @@ -95,6 +95,10 @@

+ + {% for preset in presets %} + {{ preset.name }} + {% endfor %} diff --git a/views.py b/views.py index f92f30e..3a80f30 100644 --- a/views.py +++ b/views.py @@ -4,13 +4,14 @@ from django.http.response import JsonResponse from django_coreprotect.gui import gui_data, gui_results from django_coreprotect.activity import activity_data, activity_results from django_coreprotect.utils import safe_int +from django_coreprotect.models import Preset class GUI(View): def get(self, request): form = gui_data(request) - return render(request, "coreprotect/coreprotect.html", {"form": form}) + return render(request, "coreprotect/coreprotect.html", {"form": form, "presets": Preset.objects.filter(enabled=True)}) def post(self, request): pass