forked from Minecraft/minecraft_manager
parent
b44210e922
commit
02ab21aafc
16
admin.py
16
admin.py
|
@ -4,7 +4,7 @@ from django.contrib import admin
|
|||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from minecraft_manager.models import Application, Warning, Ticket, Player, IP, UserSettings, Alert, Note
|
||||
from minecraft_manager.models import Application, Note, Ticket, TicketNote, Player, IP, UserSettings, Alert
|
||||
from minecraft_manager.api.admin import register as api_register
|
||||
|
||||
|
||||
|
@ -61,9 +61,9 @@ class TicketAdmin(admin.ModelAdmin):
|
|||
list_filter = (TicketPriorityFilter,)
|
||||
|
||||
|
||||
class WarningSeverityFilter(admin.SimpleListFilter):
|
||||
title = _('Severity')
|
||||
parameter_name = 'severity'
|
||||
class NoteImportanceFilter(admin.SimpleListFilter):
|
||||
title = _('Importance')
|
||||
parameter_name = 'importance'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return (
|
||||
|
@ -81,9 +81,9 @@ class WarningSeverityFilter(admin.SimpleListFilter):
|
|||
return queryset.filter(priority='H')
|
||||
|
||||
|
||||
class WarningAdmin(admin.ModelAdmin):
|
||||
class NoteAdmin(admin.ModelAdmin):
|
||||
search_fields = ["player__username", "staff__username"]
|
||||
list_filter = (WarningSeverityFilter,)
|
||||
list_filter = (NoteImportanceFilter,)
|
||||
|
||||
|
||||
class IPAdmin(admin.ModelAdmin):
|
||||
|
@ -95,12 +95,12 @@ try:
|
|||
admin.site.register(User, UserAdmin)
|
||||
admin.site.register(UserSettings)
|
||||
admin.site.register(Application, ApplicationAdmin)
|
||||
admin.site.register(Warning, WarningAdmin)
|
||||
admin.site.register(Ticket, TicketAdmin)
|
||||
admin.site.register(TicketNote)
|
||||
admin.site.register(Note, NoteAdmin)
|
||||
admin.site.register(Player, PlayerAdmin)
|
||||
admin.site.register(IP, IPAdmin)
|
||||
admin.site.register(Alert)
|
||||
admin.site.register(Note)
|
||||
api_register()
|
||||
except admin.sites.AlreadyRegistered:
|
||||
pass
|
||||
|
|
|
@ -12,7 +12,7 @@ from django.views.generic import View
|
|||
from django.forms import modelform_factory
|
||||
|
||||
import minecraft_manager.forms as mcm_forms
|
||||
from minecraft_manager.models import Player, UserSettings, Application, IP, Ticket, Warning
|
||||
from minecraft_manager.models import Player, UserSettings, Application, IP, Ticket, Note
|
||||
import minecraft_manager.api.api as mcm_api
|
||||
from minecraft_manager.api.models import Token
|
||||
import minecraft_manager.utils as mcm_utils
|
||||
|
@ -306,10 +306,10 @@ class PluginAPI(View):
|
|||
player = Player.objects.get(uuid=post['player'])
|
||||
staff = Player.objects.get(uuid=post['staff'])
|
||||
try:
|
||||
warning = Warning(player=player, message=post['message'], severity=post['severity'], staff=staff.auth_user)
|
||||
warning = Note(player=player, message=post['message'], importance=post['severity'], staff=staff.auth_user)
|
||||
warning.save()
|
||||
json['message'] = "Warning issued."
|
||||
link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/warning', warning.id))
|
||||
link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/note', warning.id))
|
||||
msg = mcm_utils.build_warning(warning, link)
|
||||
mcm_api.discord_mcm(embeds=msg)
|
||||
except Exception as ex:
|
||||
|
|
19
forms.py
19
forms.py
|
@ -1,9 +1,9 @@
|
|||
from django.forms import ModelForm, Textarea, HiddenInput, TextInput
|
||||
from minecraft_manager.models import UserSettings, Application, Alert, Ticket, Warning, Note
|
||||
from minecraft_manager.models import UserSettings, Application, Alert, Ticket, TicketNote, Note
|
||||
|
||||
|
||||
def __all__():
|
||||
return [UserSettingsForm, ApplicationForm, AlertForm, TicketForm, WarningForm, NoteForm]
|
||||
return [UserSettingsForm, ApplicationForm, AlertForm, TicketForm, TicketNoteForm, NoteForm]
|
||||
|
||||
|
||||
class UserSettingsForm(ModelForm):
|
||||
|
@ -34,20 +34,19 @@ class TicketForm(ModelForm):
|
|||
}
|
||||
|
||||
|
||||
class WarningForm(ModelForm):
|
||||
class NoteForm(ModelForm):
|
||||
class Meta:
|
||||
model = Warning
|
||||
fields = ['player', 'message', 'severity']
|
||||
model = Note
|
||||
fields = ['player', 'message', 'importance']
|
||||
widgets = {
|
||||
'message': Textarea
|
||||
}
|
||||
|
||||
|
||||
class NoteForm(ModelForm):
|
||||
class TicketNoteForm(ModelForm):
|
||||
class Meta:
|
||||
model = Note
|
||||
fields = ['ref_id', 'ref_table', 'message']
|
||||
model = TicketNote
|
||||
fields = ['ticket', 'message']
|
||||
widgets = {
|
||||
'ref_id': HiddenInput,
|
||||
'ref_table': HiddenInput
|
||||
'ticket': HiddenInput
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# Generated by Django 2.0.7 on 2018-11-23 15:20
|
||||
|
||||
from django.db import migrations, models
|
||||
import minecraft_manager.api.api
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('minecraft_manager', '0010_auto_20180921_2306'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Token',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('key', models.CharField(default=minecraft_manager.api.api.generate_password, max_length=50, unique=True, verbose_name='Key')),
|
||||
('active', models.BooleanField(default=True, verbose_name='Active')),
|
||||
('web_get_permission', models.BooleanField(default=False, verbose_name='Web GET')),
|
||||
('web_post_permission', models.BooleanField(default=False, verbose_name='Web POST')),
|
||||
('plugin_get_permission', models.BooleanField(default=False, verbose_name='Plugin GET')),
|
||||
('plugin_post_permission', models.BooleanField(default=False, verbose_name='Plugin POST')),
|
||||
('form_get_permission', models.BooleanField(default=False, verbose_name='Form GET')),
|
||||
('form_post_permission', models.BooleanField(default=False, verbose_name='Form POST')),
|
||||
('model_get_permission', models.BooleanField(default=False, verbose_name='Model GET')),
|
||||
('model_post_permission', models.BooleanField(default=False, verbose_name='Model POST')),
|
||||
('stats_get_permission', models.BooleanField(default=False, verbose_name='Stats GET')),
|
||||
('stats_post_permission', models.BooleanField(default=False, verbose_name='Stats POST')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.0.7 on 2018-11-23 15:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('minecraft_manager', '0011_token'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='token',
|
||||
name='description',
|
||||
field=models.CharField(blank=True, max_length=200, verbose_name='Description'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,48 @@
|
|||
# Generated by Django 2.0.5 on 2018-12-13 20:20
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def migrate_notes(apps, schema_editor):
|
||||
Note = apps.get_model('minecraft_manager', 'Note')
|
||||
TicketNote = apps.get_model('minecraft_manager', 'TicketNote')
|
||||
for note in Note.objects.all():
|
||||
ticket_note = TicketNote(author=note.author, ticket_id=note.ref_id, message=note.message, last_update=note.last_update, date=note.date)
|
||||
ticket_note.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('minecraft_manager', '0012_token_description'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TicketNote',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('message', models.TextField(max_length=1000)),
|
||||
('last_update', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('date', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('ticket',
|
||||
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='minecraft_manager.Ticket')),
|
||||
],
|
||||
),
|
||||
migrations.RunPython(migrate_notes),
|
||||
migrations.DeleteModel(
|
||||
name='Note',
|
||||
),
|
||||
migrations.RenameModel(
|
||||
old_name='Warning',
|
||||
new_name='Note'
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='Note',
|
||||
old_name='severity',
|
||||
new_name='importance'
|
||||
)
|
||||
]
|
112
models.py
112
models.py
|
@ -52,7 +52,7 @@ class UserSettings(models.Model):
|
|||
verbose_name_plural = "User Settings"
|
||||
|
||||
def __str__(self):
|
||||
return "User Settings : %s" % self.auth_user.username
|
||||
return self.auth_user.username
|
||||
|
||||
def __repr__(self):
|
||||
return self.auth_user.username
|
||||
|
@ -86,22 +86,8 @@ class Application(models.Model):
|
|||
def date_display(self):
|
||||
return str(self.date).split(".")[0]
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
return {'id': self.id, 'username': self.username, 'age': self.age, 'player_type': self.player_type,
|
||||
'ever_banned': self.ever_banned, 'ever_banned_explanation': self.ever_banned_explanation,
|
||||
'reference': self.reference, 'read_rules': self.read_rules, 'status': self.status,
|
||||
'date': self.date_display}
|
||||
|
||||
@property
|
||||
def skript(self):
|
||||
return "{0}<:>{1}<:>{2}<:>{3}<:>{4}<:>{5}<:>{6}<:>{7}<:>{8}<:>{9}<:>{10}".format(
|
||||
"success", self.id, self.username, self.age, self.player_type, self.ever_banned,
|
||||
self.ever_banned_explanation, self.reference, self.read_rules, self.status, self.date_display
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return "Application: %s" % self.username
|
||||
return self.username
|
||||
|
||||
def __repr__(self):
|
||||
return self.username
|
||||
|
@ -177,7 +163,7 @@ class Player(models.Model):
|
|||
return " ".join(ips)
|
||||
|
||||
def __str__(self):
|
||||
return self.username + " (" + self.uuid + ")"
|
||||
return "{} ({})".format(self.username, self.uuid)
|
||||
|
||||
|
||||
class Ticket(models.Model):
|
||||
|
@ -270,25 +256,34 @@ class Ticket(models.Model):
|
|||
return str(self.date).split(".")[0]
|
||||
|
||||
def __str__(self):
|
||||
username = "Unknown"
|
||||
try:
|
||||
pl = Player.objects.get(id=self.player_id)
|
||||
username = pl.username
|
||||
except:
|
||||
pass
|
||||
return "Ticket from %s" % username
|
||||
return "{}: {}".format(self.issuer, self.snippet)
|
||||
|
||||
|
||||
class Warning(models.Model):
|
||||
SEVERITY = (
|
||||
class TicketNote(models.Model):
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
|
||||
message = models.TextField(max_length=1000)
|
||||
last_update = models.DateTimeField(auto_now_add=True, blank=True, null=True)
|
||||
date = models.DateTimeField(auto_now_add=True, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Ticket Note"
|
||||
verbose_name_plural = "Ticket Notes"
|
||||
|
||||
def __str__(self):
|
||||
return "Ticket: {0}".format(self.ticket.snippet)
|
||||
|
||||
|
||||
class Note(models.Model):
|
||||
IMPORTANCE = (
|
||||
('L', 'Low'),
|
||||
('M', 'Medium'),
|
||||
('H', 'High')
|
||||
)
|
||||
player = models.ForeignKey(Player, related_name="warning_player", on_delete=models.CASCADE)
|
||||
player = models.ForeignKey(Player, related_name="note_player", on_delete=models.CASCADE)
|
||||
message = models.CharField(max_length=200)
|
||||
severity = models.CharField(max_length=1, choices=SEVERITY)
|
||||
staff = models.ForeignKey(User, related_name="warning_staff", on_delete=models.CASCADE, null=True, blank=True, limit_choices_to=Q(is_active=True))
|
||||
importance = models.CharField(max_length=1, choices=IMPORTANCE)
|
||||
staff = models.ForeignKey(User, related_name="note_staff", on_delete=models.CASCADE, null=True, blank=True, limit_choices_to=Q(is_active=True))
|
||||
date = models.DateTimeField(auto_now_add=True, blank=True, null=True)
|
||||
|
||||
@property
|
||||
|
@ -299,26 +294,19 @@ class Warning(models.Model):
|
|||
return self.message
|
||||
|
||||
@property
|
||||
def severity_display(self):
|
||||
for S in self.SEVERITY:
|
||||
if S[0] == self.severity:
|
||||
def importance_display(self):
|
||||
for S in self.IMPORTANCE:
|
||||
if S[0] == self.importance:
|
||||
return S[1]
|
||||
return "Unknown"
|
||||
|
||||
@staticmethod
|
||||
def severity_code_to_display(severity_code):
|
||||
for S in Warning.SEVERITY:
|
||||
if S[0] == severity_code:
|
||||
def importance_code_to_display(importance_code):
|
||||
for S in Note.IMPORTANCE:
|
||||
if S[0] == importance_code:
|
||||
return S[1]
|
||||
return "Unknown"
|
||||
|
||||
@staticmethod
|
||||
def resolve(severity):
|
||||
for S in Warning.SEVERITY:
|
||||
if severity.lower() in (S[0].lower(), S[1].lower()):
|
||||
return S[0]
|
||||
return 'L'
|
||||
|
||||
@property
|
||||
def issuer(self):
|
||||
if self.staff:
|
||||
|
@ -340,13 +328,7 @@ class Warning(models.Model):
|
|||
return str(self.date).split(".")[0]
|
||||
|
||||
def __str__(self):
|
||||
username = "Unknown"
|
||||
try:
|
||||
pl = Player.objects.get(id=self.player_id)
|
||||
username = pl.username
|
||||
except:
|
||||
pass
|
||||
return "Warning for %s" % username
|
||||
return "{}: {}".format(self.issuee, self.snippet)
|
||||
|
||||
|
||||
class IPManager(models.Manager):
|
||||
|
@ -393,7 +375,7 @@ class IP(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
player = Player.objects.get(id=self.player_id)
|
||||
return player.username + " - " + self.ip
|
||||
return "{}: {}".format(player.username, self.ip)
|
||||
|
||||
|
||||
class Alert(models.Model):
|
||||
|
@ -410,34 +392,8 @@ class Alert(models.Model):
|
|||
return self.message
|
||||
|
||||
def __str__(self):
|
||||
return "Alert for %s" % self.user.username
|
||||
|
||||
|
||||
class Note(models.Model):
|
||||
NOTABLE = (
|
||||
('PL', 'Player'),
|
||||
('TI', 'Ticket'),
|
||||
('WA', 'Warning')
|
||||
)
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
ref_table = models.CharField(max_length=2, choices=NOTABLE)
|
||||
ref_id = models.CharField(max_length=4)
|
||||
message = models.TextField(max_length=1000)
|
||||
last_update = models.DateTimeField(auto_now_add=True, blank=True, null=True)
|
||||
date = models.DateTimeField(auto_now_add=True, blank=True, null=True)
|
||||
|
||||
@property
|
||||
def ref_model(self):
|
||||
if self.ref_table == 'PL':
|
||||
return Player
|
||||
elif self.ref_table == 'TI':
|
||||
return Ticket
|
||||
elif self.ref_table == 'WA':
|
||||
return Warning
|
||||
|
||||
def __str__(self):
|
||||
ref = self.ref_model.objects.get(id=self.ref_id)
|
||||
return "Note: {0}".format(ref)
|
||||
return "Alert for {}".format(self.user.username)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from django.conf import settings
|
||||
from minecraft_manager.models import Application, Player, Ticket, Warning, IP
|
||||
from minecraft_manager.models import Application, Player, Ticket, Note, IP
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ def overview_data():
|
|||
'unresolved': Ticket.objects.filter(resolved=False).count(),
|
||||
'all': Ticket.objects.count()
|
||||
},
|
||||
'warning': Warning.objects.count(),
|
||||
'note': Note.objects.count(),
|
||||
'ip': IP.objects.count()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "minecraft_manager/dashboard.html" %}
|
||||
{% block title %}Warnings{% endblock %}
|
||||
{% block title %}Notes{% endblock %}
|
||||
{% block section %}
|
||||
<div id="content" hidden="hidden">
|
||||
<table id="model-table" class="table table-hover link-table">
|
||||
|
@ -7,25 +7,25 @@
|
|||
<tr>
|
||||
<th>Player</th>
|
||||
<th>Message</th>
|
||||
<th>Severity</th>
|
||||
<th>Importance</th>
|
||||
<td>Issued By</td>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for warning in warnings %}
|
||||
<tr {% if warning.severity == 'L' %}class="info"{% endif %}{% if warning.severity == 'M' %}class="warning"{% endif %}{% if warning.severity == 'H' %}class="danger"{% endif %} data-id="{{ warning.id }}">
|
||||
<!-- <td>{{ warning.id }}</td> -->
|
||||
<td>{{ warning.issuee }}</td>
|
||||
<td>{{ warning.snippet }}</td>
|
||||
<td>{{ warning.severity_display }}</td>
|
||||
<td>{{ warning.issuer }}</td>
|
||||
<td>{{ warning.date }}</td>
|
||||
{% for note in notes %}
|
||||
<tr {% if note.importance == 'L' %}class="info"{% endif %}{% if note.importance == 'M' %}class="warning"{% endif %}{% if note.importance == 'H' %}class="danger"{% endif %} data-id="{{ note.id }}">
|
||||
<!-- <td>{{ note.id }}</td> -->
|
||||
<td>{{ note.issuee }}</td>
|
||||
<td>{{ note.snippet }}</td>
|
||||
<td>{{ note.importance_display }}</td>
|
||||
<td>{{ note.issuer }}</td>
|
||||
<td>{{ note.date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<a class="btn btn-primary" href="{% url "warning_add" %}">Add Warning</a>
|
||||
<a class="btn btn-primary" href="{% url "note_add" %}">Add Note</a>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
|
@ -1,9 +1,9 @@
|
|||
{% extends "minecraft_manager/dashboard.html" %}
|
||||
{% load csrf_html %}
|
||||
{% block title %}Add Warning{% endblock %}
|
||||
{% block title %}Add Note{% endblock %}
|
||||
{% block section %}
|
||||
<div id="content">
|
||||
<h2 class="sub-header">New Warning</h2>
|
||||
<h2 class="sub-header">New Note</h2>
|
||||
<div class="row">
|
||||
<div class="col-xs-18 col-md-12">
|
||||
<form action="" method="post">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %}
|
|
@ -1,32 +1,32 @@
|
|||
{% extends "minecraft_manager/dashboard.html" %}
|
||||
{% load csrf_html %}
|
||||
{% load reverse_player %}
|
||||
{% block title %}Warning Info{% endblock %}
|
||||
{% block title %}Note Info{% endblock %}
|
||||
{% block section %}
|
||||
<div id="content">
|
||||
<h2 class="sub-header">Warning Info ({% player_reverse_id warning.player.id %})</h2>
|
||||
<h2 class="sub-header">Note Info ({% player_reverse_id note.player.id %})</h2>
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-md-4">
|
||||
<!-- <p>Username: {{ application.username }}</p> -->
|
||||
<p>Message: </p>
|
||||
<p class="well">{{ warning.message }}</p>
|
||||
<p>Warning Date: {{ warning.date }}</p>
|
||||
<p class="well">{{ note.message }}</p>
|
||||
<p>Note Date: {{ note.date }}</p>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-8">
|
||||
<form action="" method="post">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %}
|
||||
<p>Issuer: {{ warning.staff.username }} </p>
|
||||
<p>Severity:
|
||||
{% if user.is_staff or user == warning.staff %}
|
||||
<select id="warningSeverity" name="severity">
|
||||
{% for p in form.severity %}
|
||||
<option value="{{ p.0 }}" {% if warning.severity == p.0 %}selected="selected"{% endif %}>{{ p.1 }}</option>
|
||||
<p>Issuer: {{ note.staff.username }} </p>
|
||||
<p>Importance:
|
||||
{% if user.is_staff or user == note.staff %}
|
||||
<select id="noteImportance" name="importance">
|
||||
{% for p in form.importance %}
|
||||
<option value="{{ p.0 }}" {% if note.importance == p.0 %}selected="selected"{% endif %}>{{ p.1 }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% else %}
|
||||
{{ warning.severity_display }}
|
||||
{{ note.importance_display }}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if user.is_staff or warning.staff and user == warning.staff %}
|
||||
{% if user.is_staff or note.staff and user == note.staff %}
|
||||
<button id="saveButton" class="btn btn-primary" type="submit">Save</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
@ -43,8 +43,8 @@
|
|||
</div>
|
||||
<script>
|
||||
$("#saveButton").hide();
|
||||
$("#warningSeverity").change(function() {
|
||||
if (("{{ user.username }}" == "{{ warning.staff.username }}" || "{{ user.is_staff }}" == "True") && $(this).val() != "{{ warning.severity }}") {
|
||||
$("#noteImportance").change(function() {
|
||||
if (("{{ user.username }}" == "{{ note.staff.username }}" || "{{ user.is_staff }}" == "True") && $(this).val() != "{{ note.importance }}") {
|
||||
$("#saveButton").show();
|
||||
} else {
|
||||
$("#saveButton").hide();
|
|
@ -39,7 +39,7 @@
|
|||
<p>Not Banned: {{ data.total.player.unbanned }}</p>
|
||||
<p>Banned: {{ data.total.player.banned }}</p>
|
||||
<br/>
|
||||
<h3>Warnings: {{ data.total.warning }}</h3>
|
||||
<h3>Notes: {{ data.total.note }}</h3>
|
||||
<br/>
|
||||
<h3>IPs: {{ data.total.ip }}</h3>
|
||||
</div>
|
||||
|
|
|
@ -37,22 +37,22 @@
|
|||
</table>
|
||||
<br/>
|
||||
<table class="table table-hover link-table">
|
||||
<h4>Warnings</h4>
|
||||
<h4>Notes</h4>
|
||||
<tbody>
|
||||
{% if form.warnings %}
|
||||
{% for warning in form.warnings %}
|
||||
<tr {% if warning.severity == 'L' %}class="info"{% endif %}{% if warning.severity == 'M' %}class="warning"{% endif %}{% if warning.severity == 'H' %}class="danger"{% endif %} data-id="{{ warning.id }}" data-url="{% url "warning" %}">
|
||||
<!-- {{ warning.id }} -->
|
||||
<td>{{ warning.snippet }}</td>
|
||||
<td>{{ warning.severity_display }}</td>
|
||||
{% if form.notes %}
|
||||
{% for note in form.notes %}
|
||||
<tr {% if note.importance == 'L' %}class="info"{% endif %}{% if note.importance == 'M' %}class="note"{% endif %}{% if note.importance == 'H' %}class="danger"{% endif %} data-id="{{ note.id }}" data-url="{% url "note" %}">
|
||||
<!-- {{ note.id }} -->
|
||||
<td>{{ note.snippet }}</td>
|
||||
<td>{{ note.importance_display }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr><td colspan="3">No Warnings Found</td></tr>
|
||||
<tr><td colspan="3">No Notes Found</td></tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
<a class="btn btn-primary" href="{% url 'warning_add' %}?player={{ player.id }}">Add Warning</a>
|
||||
<a class="btn btn-primary" href="{% url 'note_add' %}?player={{ player.id }}">Add Note</a>
|
||||
<br/><br/>
|
||||
<table class="table table-striped table-hover link-table">
|
||||
<h4>IPs</h4>
|
||||
|
|
|
@ -64,31 +64,31 @@
|
|||
</div>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
{% for note in form.notes %}
|
||||
{% for ticket_note in form.ticket_notes %}
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3>Note by {{ note.author.username }}</h3>
|
||||
<h3>Note by {{ ticket_note.author.username }}</h3>
|
||||
<p>Message:</p>
|
||||
<p class="well">{{ note.message }}</p>
|
||||
{% if note.author == user %}
|
||||
<p class="well">{{ ticket_note.message }}</p>
|
||||
{% if ticket_note.author == user %}
|
||||
<button id="editBtn" class="btn btn-primary" onClick="showNote();">Edit</button>
|
||||
{% endif %}
|
||||
<p>Created: {{ note.date }}</p>
|
||||
<p>Last Update: {{ note.last_update }}</p>
|
||||
<p>Created: {{ ticket_note.date }}</p>
|
||||
<p>Last Update: {{ ticket_note.last_update }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if not form.has_note and not form.show_note %}
|
||||
{% if not form.has_ticket_note and not form.show_ticket_note %}
|
||||
<div id="createDiv" class="row">
|
||||
<button class="btn btn-primary" onClick="showNote()">Create Note</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div id="noteDiv" class="row" {% if not form.show_note %}style="display: none;"{% endif %}>
|
||||
<div id="ticket_noteDiv" class="row" {% if not form.show_ticket_note %}style="display: none;"{% endif %}>
|
||||
<br/>
|
||||
<h3>Note</h3>
|
||||
<form action="" method="POST">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %}
|
||||
{{ form.note_form }}
|
||||
{{ form.ticket_note_form }}
|
||||
<br/>
|
||||
<button type="submit" class="btn btn-primary" name="note" value="{% if form.has_note %}edit{% else %}create{% endif %}">Save</button>
|
||||
<button type="submit" class="btn btn-primary" name="ticket_note" value="{% if form.has_ticket_note %}edit{% else %}create{% endif %}">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
@ -123,7 +123,7 @@
|
|||
}
|
||||
|
||||
function showNote() {
|
||||
$("#noteDiv").show();
|
||||
$("#ticket_noteDiv").show();
|
||||
$("#createDiv").hide();
|
||||
$("#editBtn").hide();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ def get_sidebar(current_app, request):
|
|||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-file"></span> Applications</a></li>'.format('class="active"' if current_app == 'application' else '', reverse('application'))
|
||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-user"></span> Players</a></li>'.format('class="active"' if current_app == 'player' else '', reverse('player'))
|
||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-tags"></span> Tickets</a></li>'.format('class="active"' if current_app == 'ticket' else '', reverse('ticket'))
|
||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-warning-sign"></span> Warnings</a></li>'.format('class="active"' if current_app == 'warning' else '', reverse('warning'))
|
||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-blackboard"></span> Notes</a></li>'.format('class="active"' if current_app == 'note' else '', reverse('note'))
|
||||
|
||||
# Split up MCM and "other"
|
||||
ret += "<hr/>"
|
||||
|
|
6
urls.py
6
urls.py
|
@ -25,9 +25,9 @@ urlpatterns = [
|
|||
url(r'^dashboard/ticket/$', login_required(mcm.Ticket.as_view()), name="ticket"),
|
||||
url(r'^dashboard/ticket/(?P<ticket_id>[0-9]{1,5})/$', login_required(mcm.TicketInfo.as_view())),
|
||||
#Warnings
|
||||
url(r'^dashboard/warning/$', login_required(mcm.Warning.as_view()), name="warning"),
|
||||
url(r'^dashboard/warning/(?P<warning_id>[0-9]{1,5})/$', login_required(mcm.WarningInfo.as_view())),
|
||||
url(r'^dashboard/warning/add$', login_required(mcm.WarningAdd.as_view()), name="warning_add"),
|
||||
url(r'^dashboard/note/$', login_required(mcm.Note.as_view()), name="note"),
|
||||
url(r'^dashboard/note/(?P<note_id>[0-9]{1,5})/$', login_required(mcm.NoteInfo.as_view())),
|
||||
url(r'^dashboard/note/add$', login_required(mcm.NoteAdd.as_view()), name="note_add"),
|
||||
#IP
|
||||
url(r'^dashboard/ip/(?P<ip_id>[0-9]{1,5})/$', login_required(mcm.IP.as_view()), name="ip"),
|
||||
#Report
|
||||
|
|
146
views.py
146
views.py
|
@ -13,8 +13,8 @@ from django.conf import settings
|
|||
from django.views.generic import View
|
||||
from django.contrib.auth.models import User
|
||||
from django.forms.widgets import HiddenInput
|
||||
from minecraft_manager.models import Application as AppModel, Player as PlayerModel, Ticket as TicketModel, Warning as WarningModel, IP as IPModel, Alert as AlertModel, Note as NoteModel, UserSettings as UserSettingsModel
|
||||
from minecraft_manager.forms import WarningForm, NoteForm
|
||||
from minecraft_manager.models import Application as AppModel, Player as PlayerModel, Ticket as TicketModel, TicketNote as TicketNoteModel, Note as NoteModel, IP as IPModel, Alert as AlertModel, UserSettings as UserSettingsModel
|
||||
from minecraft_manager.forms import TicketNoteForm, NoteForm
|
||||
from minecraft_manager.overview import overview_data
|
||||
import minecraft_manager.api.api as API
|
||||
|
||||
|
@ -198,8 +198,8 @@ class PlayerInfo(View):
|
|||
player = PlayerModel.objects.get(id=player_id)
|
||||
ips = IPModel.api.filter(player=player)
|
||||
tickets = TicketModel.objects.filter(player=player)
|
||||
warnings = WarningModel.objects.filter(player=player)
|
||||
form = {'ips': ips, 'tickets': tickets, 'warnings': warnings}
|
||||
notes = NoteModel.objects.filter(player=player)
|
||||
form = {'ips': ips, 'tickets': tickets, 'notes': notes}
|
||||
return render(request, 'minecraft_manager/player_info.html',
|
||||
{'current_app': 'player', 'player': player, 'form': form})
|
||||
|
||||
|
@ -207,8 +207,8 @@ class PlayerInfo(View):
|
|||
player = PlayerModel.objects.get(id=player_id)
|
||||
ips = IPModel.api.filter(player=player)
|
||||
tickets = TicketModel.objects.filter(player=player)
|
||||
warnings = WarningModel.objects.filter(player=player)
|
||||
form = {'ips': ips, 'tickets': tickets, 'warnings': warnings}
|
||||
notes = NoteModel.objects.filter(player=player)
|
||||
form = {'ips': ips, 'tickets': tickets, 'notes': notes}
|
||||
return render(request, 'minecraft_manager/player_info.html',
|
||||
{'current_app': 'player', 'player': player, 'form': form})
|
||||
|
||||
|
@ -230,19 +230,18 @@ class TicketInfo(View):
|
|||
ticket = TicketModel.objects.get(id=ticket_id)
|
||||
active_staff = User.objects.filter(is_active=True)
|
||||
inactive_staff = User.objects.filter(is_active=False)
|
||||
notes = NoteModel.objects.filter(ref_id=ticket_id, ref_table='TI')
|
||||
note_form = NoteForm(instance=request.user)
|
||||
has_note = False
|
||||
for note in notes:
|
||||
if note.author == request.user:
|
||||
note_form = NoteForm(instance=note)
|
||||
has_note = True
|
||||
if not has_note:
|
||||
note_form.fields['ref_table'].initial = 'TI'
|
||||
note_form.fields['ref_id'].initial = ticket_id
|
||||
ticket_notes = TicketNoteModel.objects.filter(ticket=ticket)
|
||||
ticket_note_form = TicketNoteForm(instance=request.user)
|
||||
has_ticket_note = False
|
||||
for ticket_note in ticket_notes:
|
||||
if ticket_note.author == request.user:
|
||||
ticket_note_form = TicketNoteForm(instance=ticket_note)
|
||||
has_ticket_note = True
|
||||
if not has_ticket_note:
|
||||
ticket_note_form.fields['ticket'].initial = ticket_id
|
||||
form = {'active_staff': active_staff, 'inactive_staff': inactive_staff, 'priority': TicketModel.PRIORITY,
|
||||
'resolved': ticket.resolved, 'note_form': note_form.as_p(), 'notes': notes, 'has_note': has_note,
|
||||
'show_note': False}
|
||||
'resolved': ticket.resolved, 'ticket_note_form': ticket_note_form.as_p(), 'ticket_notes': ticket_notes, 'has_ticket_note': has_ticket_note,
|
||||
'show_ticket_note': False}
|
||||
return render(request, 'minecraft_manager/ticket_info.html', {'current_app': 'ticket', 'ticket': ticket, 'form': form})
|
||||
|
||||
def post(self, request, ticket_id):
|
||||
|
@ -273,100 +272,99 @@ class TicketInfo(View):
|
|||
ticket.resolved = True
|
||||
ticket.save()
|
||||
|
||||
show_note = False
|
||||
if 'note' in post:
|
||||
note_form = NoteForm(post)
|
||||
if note_form.is_valid():
|
||||
n = note_form.save(commit=False)
|
||||
if post['note'] == 'create':
|
||||
show_ticket_note = False
|
||||
if 'ticket_note' in post:
|
||||
ticket_note_form = TicketNoteForm(post)
|
||||
if ticket_note_form.is_valid():
|
||||
n = ticket_note_form.save(commit=False)
|
||||
if post['ticket_note'] == 'create':
|
||||
n.author = request.user
|
||||
n.save()
|
||||
elif post['note'] == 'edit':
|
||||
db = NoteModel.objects.get(ref_id=ticket_id, ref_table='TI', author=request.user)
|
||||
elif post['ticket_note'] == 'edit':
|
||||
db = TicketNoteModel.objects.get(ticket=ticket, author=request.user)
|
||||
db.message = n.message
|
||||
db.last_update = timezone.now()
|
||||
db.save()
|
||||
else:
|
||||
show_note = True
|
||||
show_ticket_note = True
|
||||
else:
|
||||
note_form = NoteForm(instance=request.user)
|
||||
notes = NoteModel.objects.filter(ref_id=ticket_id, ref_table='TI')
|
||||
has_note = False
|
||||
for note in notes:
|
||||
if note.author == request.user:
|
||||
note_form = NoteForm(instance=note)
|
||||
has_note = True
|
||||
if not has_note:
|
||||
note_form.fields['ref_table'].initial = 'TI'
|
||||
note_form.fields['ref_id'].initial = ticket_id
|
||||
ticket_note_form = TicketNoteForm(instance=request.user)
|
||||
ticket_notes = TicketNoteModel.objects.filter(ticket=ticket)
|
||||
has_ticket_note = False
|
||||
for ticket_note in ticket_notes:
|
||||
if ticket_note.author == request.user:
|
||||
ticket_note_form = TicketNoteForm(instance=ticket_note)
|
||||
has_ticket_note = True
|
||||
if not has_ticket_note:
|
||||
ticket_note_form.fields['ticket'].initial = ticket_id
|
||||
active_staff = User.objects.filter(is_active=True)
|
||||
inactive_staff = User.objects.filter(is_active=False)
|
||||
form = {'active_staff': active_staff, 'inactive_staff': inactive_staff, 'priority': TicketModel.PRIORITY,
|
||||
'resolved': ticket.resolved, 'note_form': note_form.as_p(), 'notes': notes, 'has_note': has_note,
|
||||
'show_note': show_note}
|
||||
'resolved': ticket.resolved, 'ticket_note_form': ticket_note_form.as_p(), 'ticket_notes': ticket_notes, 'has_ticket_note': has_ticket_note,
|
||||
'show_ticket_note': show_ticket_note}
|
||||
return render(request, 'minecraft_manager/ticket_info.html',
|
||||
{'current_app': 'ticket', 'ticket': ticket, 'form': form})
|
||||
|
||||
|
||||
class Warning(View):
|
||||
class Note(View):
|
||||
|
||||
def get(self, request):
|
||||
warnings = WarningModel.objects.order_by('-id')
|
||||
return render(request, 'minecraft_manager/warning.html', {'current_app': 'warning', 'warnings': warnings})
|
||||
notes = NoteModel.objects.order_by('-id')
|
||||
return render(request, 'minecraft_manager/note.html', {'current_app': 'note', 'notes': notes})
|
||||
|
||||
|
||||
class WarningInfo(View):
|
||||
class NoteInfo(View):
|
||||
|
||||
@method_decorator(csrf_protect)
|
||||
def get(self, request, warning_id):
|
||||
warning = WarningModel.objects.get(id=warning_id)
|
||||
form = {'severity': WarningModel.SEVERITY}
|
||||
return render(request, 'minecraft_manager/warning_info.html', {'current_app': 'warning', 'form': form, 'warning': warning})
|
||||
def get(self, request, note_id):
|
||||
note = NoteModel.objects.get(id=note_id)
|
||||
form = {'importance': NoteModel.IMPORTANCE}
|
||||
return render(request, 'minecraft_manager/note_info.html', {'current_app': 'note', 'form': form, 'note': note})
|
||||
|
||||
def post(self, request, warning_id):
|
||||
def post(self, request, note_id):
|
||||
post = request.POST
|
||||
warning = WarningModel.objects.get(id=warning_id)
|
||||
if 'severity' in post:
|
||||
API.discord_mcm("Warning #**{0}**'s severity was changed from {1} to {2} by {3}".format(warning.id,
|
||||
warning.severity_display,
|
||||
WarningModel.severity_code_to_display(
|
||||
note = NoteModel.objects.get(id=note_id)
|
||||
if 'importance' in post:
|
||||
API.discord_mcm("Note #**{0}**'s importance was changed from {1} to {2} by {3}".format(note.id,
|
||||
note.importance_display,
|
||||
NoteModel.importance_code_to_display(
|
||||
post[
|
||||
'severity']),
|
||||
'importance']),
|
||||
request.user.player.username))
|
||||
warning.severity = post['severity']
|
||||
warning.save()
|
||||
form = {'severity': WarningModel.SEVERITY}
|
||||
return render(request, 'minecraft_manager/warning_info.html',
|
||||
{'current_app': 'warning', 'form': form, 'warning': warning})
|
||||
note.importance = post['importance']
|
||||
note.save()
|
||||
form = {'importance': NoteModel.IMPORTANCE}
|
||||
return render(request, 'minecraft_manager/note_info.html',
|
||||
{'current_app': 'note', 'form': form, 'note': note})
|
||||
|
||||
|
||||
class WarningAdd(View):
|
||||
class NoteAdd(View):
|
||||
|
||||
@method_decorator(csrf_protect)
|
||||
def get(self, request):
|
||||
get = request.GET
|
||||
form = WarningForm()
|
||||
form = NoteForm()
|
||||
if 'player' in get:
|
||||
form.initial = {'player': get['player']}
|
||||
return render(request, 'minecraft_manager/warning_add.html',
|
||||
{'current_app': 'warning', 'form': form.as_p()})
|
||||
return render(request, 'minecraft_manager/note_add.html',
|
||||
{'current_app': 'note', 'form': form.as_p()})
|
||||
|
||||
def post(self, request):
|
||||
post = request.POST
|
||||
form = WarningForm(post)
|
||||
form = NoteForm(post)
|
||||
if form.is_valid():
|
||||
warning = form.save()
|
||||
warning.staff = request.user
|
||||
warning.save()
|
||||
note = form.save()
|
||||
note.staff = request.user
|
||||
note.save()
|
||||
API.discord_mcm(
|
||||
"**{0}** issued a **{1}** severity warning to **{2}**\nPreview: {3}".format(warning.staff.player.username,
|
||||
warning.severity_display,
|
||||
warning.player.username,
|
||||
warning.snippet))
|
||||
return redirect("{0}{1}".format(reverse('warning'), warning.id))
|
||||
"**{0}** made a **{1}** importance note for **{2}**\nPreview: {3}".format(note.staff.player.username,
|
||||
note.importance_display,
|
||||
note.player.username,
|
||||
note.snippet))
|
||||
return redirect("{0}{1}".format(reverse('note'), note.id))
|
||||
else:
|
||||
return render(request, 'minecraft_manager/warning_add.html',
|
||||
{'current_app': 'warning', 'form': form})
|
||||
return render(request, 'minecraft_manager/note_add.html',
|
||||
{'current_app': 'note', 'form': form})
|
||||
|
||||
|
||||
class IP(View):
|
||||
|
|
Loading…
Reference in New Issue