Start work on presets

Signed-off-by: Etzelia <etzelia@hotmail.com>
preset
Etzelia 2019-09-30 17:02:21 -05:00
parent 10dff6e266
commit 27cd7616ba
No known key found for this signature in database
GPG Key ID: 3CAEB74806C4ADE5
5 changed files with 118 additions and 2 deletions

View File

@ -1,7 +1,7 @@
from django.contrib import admin from django.contrib import admin
from django_coreprotect.models import CoArtMap, CoBlock, CoBlockdataMap, CoChat, CoCommand, CoContainer, CoDatabaseLock, \ 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: try:
pass pass
@ -22,5 +22,6 @@ try:
# admin.site.register(CoUsernameLog) # admin.site.register(CoUsernameLog)
# admin.site.register(CoVersion) # admin.site.register(CoVersion)
# admin.site.register(CoWorld) # admin.site.register(CoWorld)
admin.site.register(Preset)
except admin.sites.AlreadyRegistered: except admin.sites.AlreadyRegistered:
pass 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 import models
from django.db.models import Q
from django.shortcuts import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from datetime import datetime from datetime import datetime
from django_coreprotect.utils import safe_int from django_coreprotect.utils import safe_int
@ -291,6 +293,74 @@ class CoWorld(models.Model):
return self.world 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): class GUIResult(models.Model):
type = models.TextField() type = models.TextField()
unix = models.TextField() unix = models.TextField()

View File

@ -95,6 +95,10 @@
</p> </p>
</div> </div>
<input type="hidden" id="page" name="page" value="{{form.page}}"/> <input type="hidden" id="page" name="page" value="{{form.page}}"/>
{% for preset in presets %}
<a href="{{ preset.link }}">{{ preset.name }}</a>
{% endfor %}
</div> </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.gui import gui_data, gui_results
from django_coreprotect.activity import activity_data, activity_results from django_coreprotect.activity import activity_data, activity_results
from django_coreprotect.utils import safe_int from django_coreprotect.utils import safe_int
from django_coreprotect.models import Preset
class GUI(View): class GUI(View):
def get(self, request): def get(self, request):
form = gui_data(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): def post(self, request):
pass pass