Start work on presets

Signed-off-by: Etzelia <etzelia@hotmail.com>
coords
Etzelia 2019-09-30 17:02:21 -05:00 committed by jolheiser
parent 10b5995856
commit 7dfc0dd1a8
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
5 changed files with 118 additions and 2 deletions

View File

@ -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

View File

@ -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)),
],
),
]

View File

@ -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()

View File

@ -95,6 +95,10 @@
</p>
</div>
<input type="hidden" id="page" name="page" value="{{form.page}}"/>
{% for preset in presets %}
<a href="{{ preset.link }}">{{ preset.name }}</a>
{% endfor %}
</div>

View File

@ -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