parent
27cd7616ba
commit
2059aeb2d1
47
admin.py
47
admin.py
|
@ -1,8 +1,53 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.admin import widgets as admin_widgets
|
||||
from django import forms
|
||||
import ast
|
||||
from django_coreprotect.utils import time_to_form, form_to_time
|
||||
|
||||
from django_coreprotect.models import CoArtMap, CoBlock, CoBlockdataMap, CoChat, CoCommand, CoContainer, CoDatabaseLock, \
|
||||
CoEntity, CoEntityMap, CoMaterialMap, CoSession, CoSign, CoSkull, CoUser, CoUsernameLog, CoVersion, CoWorld, Preset
|
||||
|
||||
|
||||
class PresetAdminForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PresetAdminForm, self).__init__(*args, **kwargs)
|
||||
|
||||
worlds = tuple([(world.id, world.world) for world in CoWorld.objects.all()])
|
||||
self.fields['worlds'].widget = forms.SelectMultiple(choices=worlds)
|
||||
self.fields['date_from'].widget = admin_widgets.AdminSplitDateTime()
|
||||
self.fields['date_to'].widget = admin_widgets.AdminSplitDateTime()
|
||||
|
||||
if self.instance:
|
||||
if "worlds" in self.initial and self.initial["worlds"]:
|
||||
self.initial["worlds"] = tuple(self.initial["worlds"])
|
||||
if "date_from" in self.initial and self.initial["date_from"]:
|
||||
self.initial["date_from"] = time_to_form(self.initial["date_from"])
|
||||
if "date_to" in self.initial and self.initial["date_to"]:
|
||||
self.initial["date_to"] = time_to_form(self.initial["date_to"])
|
||||
|
||||
def clean(self):
|
||||
cleaned = super(PresetAdminForm, self).clean()
|
||||
worlds = cleaned.get("worlds", "")
|
||||
if worlds:
|
||||
worlds = ast.literal_eval(worlds)
|
||||
cleaned.update({"worlds": ",".join(worlds)})
|
||||
date_from = cleaned.get("date_from", "")
|
||||
if date_from:
|
||||
cleaned.update({"date_from": form_to_time(date_from)})
|
||||
date_to = cleaned.get("date_to", "")
|
||||
if date_to:
|
||||
cleaned.update({"date_to": form_to_time(date_to)})
|
||||
return cleaned
|
||||
|
||||
class Meta:
|
||||
model = Preset
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class PresetAdmin(admin.ModelAdmin):
|
||||
form = PresetAdminForm
|
||||
|
||||
|
||||
try:
|
||||
pass
|
||||
# admin.site.register(CoArtMap)
|
||||
|
@ -22,6 +67,6 @@ try:
|
|||
# admin.site.register(CoUsernameLog)
|
||||
# admin.site.register(CoVersion)
|
||||
# admin.site.register(CoWorld)
|
||||
admin.site.register(Preset)
|
||||
admin.site.register(Preset, PresetAdmin)
|
||||
except admin.sites.AlreadyRegistered:
|
||||
pass
|
||||
|
|
22
gui.py
22
gui.py
|
@ -1,5 +1,5 @@
|
|||
from django_coreprotect.models import CoWorld, GUIResult
|
||||
from django_coreprotect.utils import safe_int, checkbox
|
||||
from django_coreprotect.utils import safe_int, checkbox, time_to_form
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
@ -86,8 +86,12 @@ def gui_data(request):
|
|||
form.blocks = request_data["blocks"] if "blocks" in request_data else ""
|
||||
|
||||
# Date and Time
|
||||
form.date_from = request_data["date_from"] if "date_from" in request_data else ""
|
||||
form.date_to = request_data["date_to"] if "date_to" in request_data else ""
|
||||
form.date_from = time_to_form(request_data["date_from"]) if "date_from" in request_data else ""
|
||||
if form.date_from:
|
||||
form.date_from = form.date_from.timestamp()
|
||||
form.date_to = time_to_form(request_data["date_to"]) if "date_to" in request_data else ""
|
||||
if form.date_to:
|
||||
form.date_to = form.date_to.timestamp()
|
||||
|
||||
return form
|
||||
|
||||
|
@ -116,10 +120,14 @@ def gui_results(form):
|
|||
|
||||
blocks = []
|
||||
blocks_clause = ""
|
||||
chat_clause = ""
|
||||
command_clause = ""
|
||||
if form.blocks:
|
||||
for block in form.blocks.split(","):
|
||||
blocks.append(block.strip())
|
||||
blocks_clause = " AND ({})".format(" OR ".join(["cmm.material LIKE 'minecraft:{}%%'".format(b) for b in blocks]))
|
||||
chat_clause = " AND ({})".format(" OR ".join(["cc.message LIKE '%%{}%%'".format(b) for b in blocks]))
|
||||
command_clause = " AND ({})".format(" OR ".join(["cc.message LIKE '%%{}%%'".format(b) for b in blocks]))
|
||||
|
||||
worlds_clause = ""
|
||||
worlds = [world["id"] for world in form.worlds if world["checked"]]
|
||||
|
@ -133,7 +141,7 @@ def gui_results(form):
|
|||
dt = datetime.now().timestamp()
|
||||
if form.date_to and not form.date_from:
|
||||
df = datetime.now().timestamp()
|
||||
time_clause = " HAVING unix BETWEEN {} AND {} ".format(df, dt)
|
||||
time_clause = " GROUP BY unix HAVING unix BETWEEN {} AND {} ".format(df, dt)
|
||||
|
||||
# Block Break, Block Place, and Interact
|
||||
block_actions = []
|
||||
|
@ -168,8 +176,9 @@ def gui_results(form):
|
|||
JOIN co_user cu ON cc.user = cu.rowid
|
||||
WHERE 1 = 1
|
||||
{players}
|
||||
{chat}
|
||||
{time}
|
||||
'''.format(players=players_clause, time=time_clause))
|
||||
'''.format(players=players_clause, chat=chat_clause, time=time_clause))
|
||||
|
||||
# Chest Use
|
||||
if form.chest_use:
|
||||
|
@ -195,9 +204,10 @@ def gui_results(form):
|
|||
JOIN co_user cu ON cc.user = cu.rowid
|
||||
WHERE 1 = 1
|
||||
{players}
|
||||
{command}
|
||||
{coords}
|
||||
{time}
|
||||
'''.format(players=players_clause, coords=coords_clause, time=time_clause))
|
||||
'''.format(players=players_clause, command=command_clause, coords=coords_clause, time=time_clause))
|
||||
|
||||
# Login/Logout
|
||||
if form.login_logout:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 2.2.3 on 2019-09-30 21:59
|
||||
# Generated by Django 2.2.3 on 2019-10-01 04:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
@ -23,17 +23,17 @@ class Migration(migrations.Migration):
|
|||
('interact', models.BooleanField(default=False)),
|
||||
('login_logout', models.BooleanField(default=False)),
|
||||
('sign_place', models.BooleanField(default=False)),
|
||||
('worlds', models.CharField(default='', max_length=20)),
|
||||
('worlds', models.CharField(blank=True, 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)),
|
||||
('players', models.CharField(blank=True, max_length=50)),
|
||||
('x', models.CharField(blank=True, default='', max_length=10)),
|
||||
('y', models.CharField(blank=True, default='', max_length=10)),
|
||||
('z', models.CharField(blank=True, default='', max_length=10)),
|
||||
('radius', models.CharField(blank=True, default='', max_length=10)),
|
||||
('blocks', models.CharField(blank=True, default='', max_length=50)),
|
||||
('date_from', models.CharField(blank=True, default='', max_length=50)),
|
||||
('date_to', models.CharField(blank=True, default='', max_length=50)),
|
||||
('enabled', models.BooleanField(default=True)),
|
||||
],
|
||||
),
|
||||
|
|
10
models.py
10
models.py
|
@ -312,8 +312,8 @@ class Preset(models.Model):
|
|||
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)
|
||||
date_from = models.CharField(max_length=50, default="", blank=True)
|
||||
date_to = models.CharField(max_length=50, default="", blank=True)
|
||||
enabled = models.BooleanField(default=True)
|
||||
|
||||
@property
|
||||
|
@ -337,7 +337,8 @@ class Preset(models.Model):
|
|||
if self.sign_place:
|
||||
params.append("sign_place=on")
|
||||
if self.worlds:
|
||||
params.append("world=" + self.worlds)
|
||||
for world in self.worlds.split(","):
|
||||
params.append("world=" + world)
|
||||
if self.ignore_environment:
|
||||
params.append("ignore_environment=on")
|
||||
if self.oldest_first:
|
||||
|
@ -360,6 +361,9 @@ class Preset(models.Model):
|
|||
params.append("date_to=" + self.date_to)
|
||||
return url + "&".join(params)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class GUIResult(models.Model):
|
||||
type = models.TextField()
|
||||
|
|
|
@ -75,30 +75,25 @@
|
|||
<label for="oldest_first">Oldest Results First</label>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
{% if presets %}
|
||||
<br/>
|
||||
|
||||
<h4 class="title is-5 has-text-primary">
|
||||
Page Size
|
||||
</h4>
|
||||
<div class="field">
|
||||
<h4 class="title is-5 has-text-primary">
|
||||
Presets
|
||||
</h4>
|
||||
<div class="field">
|
||||
<p class="control">
|
||||
<span class="select">
|
||||
<select id="page_size" name="page_size">
|
||||
<option value="20" {% if form.page_size == "20" %}selected{% endif %}>20</option>
|
||||
<option value="50" {% if form.page_size == "50" %}selected{% endif %}>50</option>
|
||||
<option value="100" {% if form.page_size == "100" %}selected{% endif %}>100</option>
|
||||
<option value="200" {% if form.page_size == "200" %}selected{% endif %}>200</option>
|
||||
<option value="500" {% if form.page_size == "500" %}selected{% endif %}>500</option>
|
||||
<option value="1000" {% if form.page_size == "1000" %}selected{% endif %}>1000</option>
|
||||
<select id="preset">
|
||||
<option></option>
|
||||
{% for preset in presets %}
|
||||
<option value="{{ preset.link }}">{{ preset.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</span>
|
||||
</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>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -159,6 +154,27 @@
|
|||
|
||||
<br/>
|
||||
|
||||
<h4 class="title is-5 has-text-primary">
|
||||
Page Size
|
||||
</h4>
|
||||
<div class="field">
|
||||
<p class="control">
|
||||
<span class="select">
|
||||
<select id="page_size" name="page_size">
|
||||
<option value="20" {% if form.page_size == "20" %}selected{% endif %}>20</option>
|
||||
<option value="50" {% if form.page_size == "50" %}selected{% endif %}>50</option>
|
||||
<option value="100" {% if form.page_size == "100" %}selected{% endif %}>100</option>
|
||||
<option value="200" {% if form.page_size == "200" %}selected{% endif %}>200</option>
|
||||
<option value="500" {% if form.page_size == "500" %}selected{% endif %}>500</option>
|
||||
<option value="1000" {% if form.page_size == "1000" %}selected{% endif %}>1000</option>
|
||||
</select>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<input type="hidden" id="page" name="page" value="{{form.page}}"/>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="field is-grouped">
|
||||
<p class="control">
|
||||
<button class="button is-primary" id="search" type="button">Search</button>
|
||||
|
@ -282,5 +298,13 @@
|
|||
document.getElementById("export").addEventListener("click", function() {
|
||||
exportTableToCSV("coreprotect.csv", "results");
|
||||
});
|
||||
|
||||
{% if presets %}
|
||||
document.getElementById("preset").addEventListener("change", function() {
|
||||
if (this.value !== "") {
|
||||
location.href = this.value;
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endblock %}
|
26
utils.py
26
utils.py
|
@ -1,3 +1,6 @@
|
|||
from datetime import datetime, timedelta
|
||||
import ast
|
||||
|
||||
def checkbox(value):
|
||||
return True if value == "on" else False
|
||||
|
||||
|
@ -7,3 +10,26 @@ def safe_int(value):
|
|||
return int(value)
|
||||
except:
|
||||
return 0
|
||||
|
||||
|
||||
def time_to_form(date_time):
|
||||
if date_time == "~T":
|
||||
return datetime.today()
|
||||
elif date_time == "~N":
|
||||
return datetime.now()
|
||||
elif date_time == "~Y":
|
||||
return datetime.today() - timedelta(days=1)
|
||||
elif date_time == "":
|
||||
return ""
|
||||
else:
|
||||
return datetime.utcfromtimestamp(float(date_time))
|
||||
|
||||
|
||||
def form_to_time(date_time):
|
||||
dt = ast.literal_eval(date_time)
|
||||
if dt[0] in ["~T", "~N", "~Y"]:
|
||||
return dt[0]
|
||||
else:
|
||||
dt[0] = dt[0] if dt[0] else datetime.now().strftime("%Y-%m-%d")
|
||||
dt[1] = dt[1] if dt[1] else "00:00:00"
|
||||
return datetime.strptime(" ".join(dt), "%Y-%m-%d %H:%M:%S").timestamp()
|
||||
|
|
Loading…
Reference in New Issue