Migration of Warnings to Notes

Notes to TicketNotes
Fixes #21
reminder
Etzelia 2018-12-13 15:18:29 -06:00
parent b44210e922
commit 02ab21aafc
18 changed files with 278 additions and 227 deletions

View File

@ -4,7 +4,7 @@ from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ 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 from minecraft_manager.api.admin import register as api_register
@ -61,9 +61,9 @@ class TicketAdmin(admin.ModelAdmin):
list_filter = (TicketPriorityFilter,) list_filter = (TicketPriorityFilter,)
class WarningSeverityFilter(admin.SimpleListFilter): class NoteImportanceFilter(admin.SimpleListFilter):
title = _('Severity') title = _('Importance')
parameter_name = 'severity' parameter_name = 'importance'
def lookups(self, request, model_admin): def lookups(self, request, model_admin):
return ( return (
@ -81,9 +81,9 @@ class WarningSeverityFilter(admin.SimpleListFilter):
return queryset.filter(priority='H') return queryset.filter(priority='H')
class WarningAdmin(admin.ModelAdmin): class NoteAdmin(admin.ModelAdmin):
search_fields = ["player__username", "staff__username"] search_fields = ["player__username", "staff__username"]
list_filter = (WarningSeverityFilter,) list_filter = (NoteImportanceFilter,)
class IPAdmin(admin.ModelAdmin): class IPAdmin(admin.ModelAdmin):
@ -95,12 +95,12 @@ try:
admin.site.register(User, UserAdmin) admin.site.register(User, UserAdmin)
admin.site.register(UserSettings) admin.site.register(UserSettings)
admin.site.register(Application, ApplicationAdmin) admin.site.register(Application, ApplicationAdmin)
admin.site.register(Warning, WarningAdmin)
admin.site.register(Ticket, TicketAdmin) admin.site.register(Ticket, TicketAdmin)
admin.site.register(TicketNote)
admin.site.register(Note, NoteAdmin)
admin.site.register(Player, PlayerAdmin) admin.site.register(Player, PlayerAdmin)
admin.site.register(IP, IPAdmin) admin.site.register(IP, IPAdmin)
admin.site.register(Alert) admin.site.register(Alert)
admin.site.register(Note)
api_register() api_register()
except admin.sites.AlreadyRegistered: except admin.sites.AlreadyRegistered:
pass pass

View File

@ -12,7 +12,7 @@ from django.views.generic import View
from django.forms import modelform_factory from django.forms import modelform_factory
import minecraft_manager.forms as mcm_forms 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 import minecraft_manager.api.api as mcm_api
from minecraft_manager.api.models import Token from minecraft_manager.api.models import Token
import minecraft_manager.utils as mcm_utils import minecraft_manager.utils as mcm_utils
@ -306,10 +306,10 @@ class PluginAPI(View):
player = Player.objects.get(uuid=post['player']) player = Player.objects.get(uuid=post['player'])
staff = Player.objects.get(uuid=post['staff']) staff = Player.objects.get(uuid=post['staff'])
try: 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() warning.save()
json['message'] = "Warning issued." 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) msg = mcm_utils.build_warning(warning, link)
mcm_api.discord_mcm(embeds=msg) mcm_api.discord_mcm(embeds=msg)
except Exception as ex: except Exception as ex:

View File

@ -1,9 +1,9 @@
from django.forms import ModelForm, Textarea, HiddenInput, TextInput 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__(): def __all__():
return [UserSettingsForm, ApplicationForm, AlertForm, TicketForm, WarningForm, NoteForm] return [UserSettingsForm, ApplicationForm, AlertForm, TicketForm, TicketNoteForm, NoteForm]
class UserSettingsForm(ModelForm): class UserSettingsForm(ModelForm):
@ -34,20 +34,19 @@ class TicketForm(ModelForm):
} }
class WarningForm(ModelForm): class NoteForm(ModelForm):
class Meta: class Meta:
model = Warning model = Note
fields = ['player', 'message', 'severity'] fields = ['player', 'message', 'importance']
widgets = { widgets = {
'message': Textarea 'message': Textarea
} }
class NoteForm(ModelForm): class TicketNoteForm(ModelForm):
class Meta: class Meta:
model = Note model = TicketNote
fields = ['ref_id', 'ref_table', 'message'] fields = ['ticket', 'message']
widgets = { widgets = {
'ref_id': HiddenInput, 'ticket': HiddenInput
'ref_table': HiddenInput
} }

View File

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

View File

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

View File

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

@ -52,7 +52,7 @@ class UserSettings(models.Model):
verbose_name_plural = "User Settings" verbose_name_plural = "User Settings"
def __str__(self): def __str__(self):
return "User Settings : %s" % self.auth_user.username return self.auth_user.username
def __repr__(self): def __repr__(self):
return self.auth_user.username return self.auth_user.username
@ -86,22 +86,8 @@ class Application(models.Model):
def date_display(self): def date_display(self):
return str(self.date).split(".")[0] 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): def __str__(self):
return "Application: %s" % self.username return self.username
def __repr__(self): def __repr__(self):
return self.username return self.username
@ -177,7 +163,7 @@ class Player(models.Model):
return " ".join(ips) return " ".join(ips)
def __str__(self): def __str__(self):
return self.username + " (" + self.uuid + ")" return "{} ({})".format(self.username, self.uuid)
class Ticket(models.Model): class Ticket(models.Model):
@ -270,25 +256,34 @@ class Ticket(models.Model):
return str(self.date).split(".")[0] return str(self.date).split(".")[0]
def __str__(self): def __str__(self):
username = "Unknown" return "{}: {}".format(self.issuer, self.snippet)
try:
pl = Player.objects.get(id=self.player_id)
username = pl.username
except:
pass
return "Ticket from %s" % username
class Warning(models.Model): class TicketNote(models.Model):
SEVERITY = ( 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'), ('L', 'Low'),
('M', 'Medium'), ('M', 'Medium'),
('H', 'High') ('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) message = models.CharField(max_length=200)
severity = models.CharField(max_length=1, choices=SEVERITY) importance = models.CharField(max_length=1, choices=IMPORTANCE)
staff = models.ForeignKey(User, related_name="warning_staff", on_delete=models.CASCADE, null=True, blank=True, limit_choices_to=Q(is_active=True)) 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) date = models.DateTimeField(auto_now_add=True, blank=True, null=True)
@property @property
@ -299,26 +294,19 @@ class Warning(models.Model):
return self.message return self.message
@property @property
def severity_display(self): def importance_display(self):
for S in self.SEVERITY: for S in self.IMPORTANCE:
if S[0] == self.severity: if S[0] == self.importance:
return S[1] return S[1]
return "Unknown" return "Unknown"
@staticmethod @staticmethod
def severity_code_to_display(severity_code): def importance_code_to_display(importance_code):
for S in Warning.SEVERITY: for S in Note.IMPORTANCE:
if S[0] == severity_code: if S[0] == importance_code:
return S[1] return S[1]
return "Unknown" 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 @property
def issuer(self): def issuer(self):
if self.staff: if self.staff:
@ -340,13 +328,7 @@ class Warning(models.Model):
return str(self.date).split(".")[0] return str(self.date).split(".")[0]
def __str__(self): def __str__(self):
username = "Unknown" return "{}: {}".format(self.issuee, self.snippet)
try:
pl = Player.objects.get(id=self.player_id)
username = pl.username
except:
pass
return "Warning for %s" % username
class IPManager(models.Manager): class IPManager(models.Manager):
@ -393,7 +375,7 @@ class IP(models.Model):
def __str__(self): def __str__(self):
player = Player.objects.get(id=self.player_id) player = Player.objects.get(id=self.player_id)
return player.username + " - " + self.ip return "{}: {}".format(player.username, self.ip)
class Alert(models.Model): class Alert(models.Model):
@ -410,34 +392,8 @@ class Alert(models.Model):
return self.message return self.message
def __str__(self): def __str__(self):
return "Alert for %s" % self.user.username return "Alert for {}".format(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)

View File

@ -2,7 +2,7 @@ import os
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.conf import settings 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 from django.contrib.auth.models import User
@ -33,7 +33,7 @@ def overview_data():
'unresolved': Ticket.objects.filter(resolved=False).count(), 'unresolved': Ticket.objects.filter(resolved=False).count(),
'all': Ticket.objects.count() 'all': Ticket.objects.count()
}, },
'warning': Warning.objects.count(), 'note': Note.objects.count(),
'ip': IP.objects.count() 'ip': IP.objects.count()
} }

View File

@ -1,5 +1,5 @@
{% extends "minecraft_manager/dashboard.html" %} {% extends "minecraft_manager/dashboard.html" %}
{% block title %}Warnings{% endblock %} {% block title %}Notes{% endblock %}
{% block section %} {% block section %}
<div id="content" hidden="hidden"> <div id="content" hidden="hidden">
<table id="model-table" class="table table-hover link-table"> <table id="model-table" class="table table-hover link-table">
@ -7,25 +7,25 @@
<tr> <tr>
<th>Player</th> <th>Player</th>
<th>Message</th> <th>Message</th>
<th>Severity</th> <th>Importance</th>
<td>Issued By</td> <td>Issued By</td>
<th>Date</th> <th>Date</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for warning in warnings %} {% for note in notes %}
<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 }}"> <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>{{ warning.id }}</td> --> <!-- <td>{{ note.id }}</td> -->
<td>{{ warning.issuee }}</td> <td>{{ note.issuee }}</td>
<td>{{ warning.snippet }}</td> <td>{{ note.snippet }}</td>
<td>{{ warning.severity_display }}</td> <td>{{ note.importance_display }}</td>
<td>{{ warning.issuer }}</td> <td>{{ note.issuer }}</td>
<td>{{ warning.date }}</td> <td>{{ note.date }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </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> </div>
<script> <script>
$(document).ready(function() { $(document).ready(function() {

View File

@ -1,9 +1,9 @@
{% extends "minecraft_manager/dashboard.html" %} {% extends "minecraft_manager/dashboard.html" %}
{% load csrf_html %} {% load csrf_html %}
{% block title %}Add Warning{% endblock %} {% block title %}Add Note{% endblock %}
{% block section %} {% block section %}
<div id="content"> <div id="content">
<h2 class="sub-header">New Warning</h2> <h2 class="sub-header">New Note</h2>
<div class="row"> <div class="row">
<div class="col-xs-18 col-md-12"> <div class="col-xs-18 col-md-12">
<form action="" method="post">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %} <form action="" method="post">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %}

View File

@ -1,32 +1,32 @@
{% extends "minecraft_manager/dashboard.html" %} {% extends "minecraft_manager/dashboard.html" %}
{% load csrf_html %} {% load csrf_html %}
{% load reverse_player %} {% load reverse_player %}
{% block title %}Warning Info{% endblock %} {% block title %}Note Info{% endblock %}
{% block section %} {% block section %}
<div id="content"> <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="row">
<div class="col-xs-6 col-md-4"> <div class="col-xs-6 col-md-4">
<!-- <p>Username: {{ application.username }}</p> --> <!-- <p>Username: {{ application.username }}</p> -->
<p>Message: </p> <p>Message: </p>
<p class="well">{{ warning.message }}</p> <p class="well">{{ note.message }}</p>
<p>Warning Date: {{ warning.date }}</p> <p>Note Date: {{ note.date }}</p>
</div> </div>
<div class="col-xs-12 col-md-8"> <div class="col-xs-12 col-md-8">
<form action="" method="post">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %} <form action="" method="post">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %}
<p>Issuer: {{ warning.staff.username }} </p> <p>Issuer: {{ note.staff.username }} </p>
<p>Severity: <p>Importance:
{% if user.is_staff or user == warning.staff %} {% if user.is_staff or user == note.staff %}
<select id="warningSeverity" name="severity"> <select id="noteImportance" name="importance">
{% for p in form.severity %} {% for p in form.importance %}
<option value="{{ p.0 }}" {% if warning.severity == p.0 %}selected="selected"{% endif %}>{{ p.1 }}</option> <option value="{{ p.0 }}" {% if note.importance == p.0 %}selected="selected"{% endif %}>{{ p.1 }}</option>
{% endfor %} {% endfor %}
</select> </select>
{% else %} {% else %}
{{ warning.severity_display }} {{ note.importance_display }}
{% endif %} {% endif %}
</p> </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> <button id="saveButton" class="btn btn-primary" type="submit">Save</button>
{% endif %} {% endif %}
</form> </form>
@ -43,8 +43,8 @@
</div> </div>
<script> <script>
$("#saveButton").hide(); $("#saveButton").hide();
$("#warningSeverity").change(function() { $("#noteImportance").change(function() {
if (("{{ user.username }}" == "{{ warning.staff.username }}" || "{{ user.is_staff }}" == "True") && $(this).val() != "{{ warning.severity }}") { if (("{{ user.username }}" == "{{ note.staff.username }}" || "{{ user.is_staff }}" == "True") && $(this).val() != "{{ note.importance }}") {
$("#saveButton").show(); $("#saveButton").show();
} else { } else {
$("#saveButton").hide(); $("#saveButton").hide();

View File

@ -39,7 +39,7 @@
<p>Not Banned: {{ data.total.player.unbanned }}</p> <p>Not Banned: {{ data.total.player.unbanned }}</p>
<p>Banned: {{ data.total.player.banned }}</p> <p>Banned: {{ data.total.player.banned }}</p>
<br/> <br/>
<h3>Warnings: {{ data.total.warning }}</h3> <h3>Notes: {{ data.total.note }}</h3>
<br/> <br/>
<h3>IPs: {{ data.total.ip }}</h3> <h3>IPs: {{ data.total.ip }}</h3>
</div> </div>

View File

@ -37,22 +37,22 @@
</table> </table>
<br/> <br/>
<table class="table table-hover link-table"> <table class="table table-hover link-table">
<h4>Warnings</h4> <h4>Notes</h4>
<tbody> <tbody>
{% if form.warnings %} {% if form.notes %}
{% for warning in form.warnings %} {% for note in form.notes %}
<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" %}"> <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" %}">
<!-- {{ warning.id }} --> <!-- {{ note.id }} -->
<td>{{ warning.snippet }}</td> <td>{{ note.snippet }}</td>
<td>{{ warning.severity_display }}</td> <td>{{ note.importance_display }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% else %} {% else %}
<tr><td colspan="3">No Warnings Found</td></tr> <tr><td colspan="3">No Notes Found</td></tr>
{% endif %} {% endif %}
</tbody> </tbody>
</table> </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/> <br/><br/>
<table class="table table-striped table-hover link-table"> <table class="table table-striped table-hover link-table">
<h4>IPs</h4> <h4>IPs</h4>

View File

@ -64,31 +64,31 @@
</div> </div>
<hr/> <hr/>
<div class="row"> <div class="row">
{% for note in form.notes %} {% for ticket_note in form.ticket_notes %}
<div class="col-xs-9 col-md-6"> <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>Message:</p>
<p class="well">{{ note.message }}</p> <p class="well">{{ ticket_note.message }}</p>
{% if note.author == user %} {% if ticket_note.author == user %}
<button id="editBtn" class="btn btn-primary" onClick="showNote();">Edit</button> <button id="editBtn" class="btn btn-primary" onClick="showNote();">Edit</button>
{% endif %} {% endif %}
<p>Created: {{ note.date }}</p> <p>Created: {{ ticket_note.date }}</p>
<p>Last Update: {{ note.last_update }}</p> <p>Last Update: {{ ticket_note.last_update }}</p>
</div> </div>
{% endfor %} {% endfor %}
</div> </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"> <div id="createDiv" class="row">
<button class="btn btn-primary" onClick="showNote()">Create Note</button> <button class="btn btn-primary" onClick="showNote()">Create Note</button>
</div> </div>
{% endif %} {% 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/> <br/>
<h3>Note</h3> <h3>Note</h3>
<form action="" method="POST">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %} <form action="" method="POST">{% autoescape off %}{% get_csrf_html request %}{% endautoescape %}
{{ form.note_form }} {{ form.ticket_note_form }}
<br/> <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> </form>
</div> </div>
@ -123,7 +123,7 @@
} }
function showNote() { function showNote() {
$("#noteDiv").show(); $("#ticket_noteDiv").show();
$("#createDiv").hide(); $("#createDiv").hide();
$("#editBtn").hide(); $("#editBtn").hide();
} }

View File

@ -23,7 +23,7 @@ def get_sidebar(current_app, request):
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-file"></span>&nbsp;&nbsp;Applications</a></li>'.format('class="active"' if current_app == 'application' else '', reverse('application')) ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-file"></span>&nbsp;&nbsp;Applications</a></li>'.format('class="active"' if current_app == 'application' else '', reverse('application'))
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;Players</a></li>'.format('class="active"' if current_app == 'player' else '', reverse('player')) ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;Players</a></li>'.format('class="active"' if current_app == 'player' else '', reverse('player'))
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-tags"></span>&nbsp;&nbsp;Tickets</a></li>'.format('class="active"' if current_app == 'ticket' else '', reverse('ticket')) ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-tags"></span>&nbsp;&nbsp;Tickets</a></li>'.format('class="active"' if current_app == 'ticket' else '', reverse('ticket'))
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-warning-sign"></span>&nbsp;&nbsp;Warnings</a></li>'.format('class="active"' if current_app == 'warning' else '', reverse('warning')) ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-blackboard"></span>&nbsp;&nbsp;Notes</a></li>'.format('class="active"' if current_app == 'note' else '', reverse('note'))
# Split up MCM and "other" # Split up MCM and "other"
ret += "<hr/>" ret += "<hr/>"

View File

@ -25,9 +25,9 @@ urlpatterns = [
url(r'^dashboard/ticket/$', login_required(mcm.Ticket.as_view()), name="ticket"), 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())), url(r'^dashboard/ticket/(?P<ticket_id>[0-9]{1,5})/$', login_required(mcm.TicketInfo.as_view())),
#Warnings #Warnings
url(r'^dashboard/warning/$', login_required(mcm.Warning.as_view()), name="warning"), url(r'^dashboard/note/$', login_required(mcm.Note.as_view()), name="note"),
url(r'^dashboard/warning/(?P<warning_id>[0-9]{1,5})/$', login_required(mcm.WarningInfo.as_view())), url(r'^dashboard/note/(?P<note_id>[0-9]{1,5})/$', login_required(mcm.NoteInfo.as_view())),
url(r'^dashboard/warning/add$', login_required(mcm.WarningAdd.as_view()), name="warning_add"), url(r'^dashboard/note/add$', login_required(mcm.NoteAdd.as_view()), name="note_add"),
#IP #IP
url(r'^dashboard/ip/(?P<ip_id>[0-9]{1,5})/$', login_required(mcm.IP.as_view()), name="ip"), url(r'^dashboard/ip/(?P<ip_id>[0-9]{1,5})/$', login_required(mcm.IP.as_view()), name="ip"),
#Report #Report

146
views.py
View File

@ -13,8 +13,8 @@ from django.conf import settings
from django.views.generic import View from django.views.generic import View
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.forms.widgets import HiddenInput 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.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 WarningForm, NoteForm from minecraft_manager.forms import TicketNoteForm, NoteForm
from minecraft_manager.overview import overview_data from minecraft_manager.overview import overview_data
import minecraft_manager.api.api as API import minecraft_manager.api.api as API
@ -198,8 +198,8 @@ class PlayerInfo(View):
player = PlayerModel.objects.get(id=player_id) player = PlayerModel.objects.get(id=player_id)
ips = IPModel.api.filter(player=player) ips = IPModel.api.filter(player=player)
tickets = TicketModel.objects.filter(player=player) tickets = TicketModel.objects.filter(player=player)
warnings = WarningModel.objects.filter(player=player) notes = NoteModel.objects.filter(player=player)
form = {'ips': ips, 'tickets': tickets, 'warnings': warnings} form = {'ips': ips, 'tickets': tickets, 'notes': notes}
return render(request, 'minecraft_manager/player_info.html', return render(request, 'minecraft_manager/player_info.html',
{'current_app': 'player', 'player': player, 'form': form}) {'current_app': 'player', 'player': player, 'form': form})
@ -207,8 +207,8 @@ class PlayerInfo(View):
player = PlayerModel.objects.get(id=player_id) player = PlayerModel.objects.get(id=player_id)
ips = IPModel.api.filter(player=player) ips = IPModel.api.filter(player=player)
tickets = TicketModel.objects.filter(player=player) tickets = TicketModel.objects.filter(player=player)
warnings = WarningModel.objects.filter(player=player) notes = NoteModel.objects.filter(player=player)
form = {'ips': ips, 'tickets': tickets, 'warnings': warnings} form = {'ips': ips, 'tickets': tickets, 'notes': notes}
return render(request, 'minecraft_manager/player_info.html', return render(request, 'minecraft_manager/player_info.html',
{'current_app': 'player', 'player': player, 'form': form}) {'current_app': 'player', 'player': player, 'form': form})
@ -230,19 +230,18 @@ class TicketInfo(View):
ticket = TicketModel.objects.get(id=ticket_id) ticket = TicketModel.objects.get(id=ticket_id)
active_staff = User.objects.filter(is_active=True) active_staff = User.objects.filter(is_active=True)
inactive_staff = User.objects.filter(is_active=False) inactive_staff = User.objects.filter(is_active=False)
notes = NoteModel.objects.filter(ref_id=ticket_id, ref_table='TI') ticket_notes = TicketNoteModel.objects.filter(ticket=ticket)
note_form = NoteForm(instance=request.user) ticket_note_form = TicketNoteForm(instance=request.user)
has_note = False has_ticket_note = False
for note in notes: for ticket_note in ticket_notes:
if note.author == request.user: if ticket_note.author == request.user:
note_form = NoteForm(instance=note) ticket_note_form = TicketNoteForm(instance=ticket_note)
has_note = True has_ticket_note = True
if not has_note: if not has_ticket_note:
note_form.fields['ref_table'].initial = 'TI' ticket_note_form.fields['ticket'].initial = ticket_id
note_form.fields['ref_id'].initial = ticket_id
form = {'active_staff': active_staff, 'inactive_staff': inactive_staff, 'priority': TicketModel.PRIORITY, 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, 'resolved': ticket.resolved, 'ticket_note_form': ticket_note_form.as_p(), 'ticket_notes': ticket_notes, 'has_ticket_note': has_ticket_note,
'show_note': False} 'show_ticket_note': False}
return render(request, 'minecraft_manager/ticket_info.html', {'current_app': 'ticket', 'ticket': ticket, 'form': form}) return render(request, 'minecraft_manager/ticket_info.html', {'current_app': 'ticket', 'ticket': ticket, 'form': form})
def post(self, request, ticket_id): def post(self, request, ticket_id):
@ -273,100 +272,99 @@ class TicketInfo(View):
ticket.resolved = True ticket.resolved = True
ticket.save() ticket.save()
show_note = False show_ticket_note = False
if 'note' in post: if 'ticket_note' in post:
note_form = NoteForm(post) ticket_note_form = TicketNoteForm(post)
if note_form.is_valid(): if ticket_note_form.is_valid():
n = note_form.save(commit=False) n = ticket_note_form.save(commit=False)
if post['note'] == 'create': if post['ticket_note'] == 'create':
n.author = request.user n.author = request.user
n.save() n.save()
elif post['note'] == 'edit': elif post['ticket_note'] == 'edit':
db = NoteModel.objects.get(ref_id=ticket_id, ref_table='TI', author=request.user) db = TicketNoteModel.objects.get(ticket=ticket, author=request.user)
db.message = n.message db.message = n.message
db.last_update = timezone.now() db.last_update = timezone.now()
db.save() db.save()
else: else:
show_note = True show_ticket_note = True
else: else:
note_form = NoteForm(instance=request.user) ticket_note_form = TicketNoteForm(instance=request.user)
notes = NoteModel.objects.filter(ref_id=ticket_id, ref_table='TI') ticket_notes = TicketNoteModel.objects.filter(ticket=ticket)
has_note = False has_ticket_note = False
for note in notes: for ticket_note in ticket_notes:
if note.author == request.user: if ticket_note.author == request.user:
note_form = NoteForm(instance=note) ticket_note_form = TicketNoteForm(instance=ticket_note)
has_note = True has_ticket_note = True
if not has_note: if not has_ticket_note:
note_form.fields['ref_table'].initial = 'TI' ticket_note_form.fields['ticket'].initial = ticket_id
note_form.fields['ref_id'].initial = ticket_id
active_staff = User.objects.filter(is_active=True) active_staff = User.objects.filter(is_active=True)
inactive_staff = User.objects.filter(is_active=False) inactive_staff = User.objects.filter(is_active=False)
form = {'active_staff': active_staff, 'inactive_staff': inactive_staff, 'priority': TicketModel.PRIORITY, 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, 'resolved': ticket.resolved, 'ticket_note_form': ticket_note_form.as_p(), 'ticket_notes': ticket_notes, 'has_ticket_note': has_ticket_note,
'show_note': show_note} 'show_ticket_note': show_ticket_note}
return render(request, 'minecraft_manager/ticket_info.html', return render(request, 'minecraft_manager/ticket_info.html',
{'current_app': 'ticket', 'ticket': ticket, 'form': form}) {'current_app': 'ticket', 'ticket': ticket, 'form': form})
class Warning(View): class Note(View):
def get(self, request): def get(self, request):
warnings = WarningModel.objects.order_by('-id') notes = NoteModel.objects.order_by('-id')
return render(request, 'minecraft_manager/warning.html', {'current_app': 'warning', 'warnings': warnings}) return render(request, 'minecraft_manager/note.html', {'current_app': 'note', 'notes': notes})
class WarningInfo(View): class NoteInfo(View):
@method_decorator(csrf_protect) @method_decorator(csrf_protect)
def get(self, request, warning_id): def get(self, request, note_id):
warning = WarningModel.objects.get(id=warning_id) note = NoteModel.objects.get(id=note_id)
form = {'severity': WarningModel.SEVERITY} form = {'importance': NoteModel.IMPORTANCE}
return render(request, 'minecraft_manager/warning_info.html', {'current_app': 'warning', 'form': form, 'warning': warning}) 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 post = request.POST
warning = WarningModel.objects.get(id=warning_id) note = NoteModel.objects.get(id=note_id)
if 'severity' in post: if 'importance' in post:
API.discord_mcm("Warning #**{0}**'s severity was changed from {1} to {2} by {3}".format(warning.id, API.discord_mcm("Note #**{0}**'s importance was changed from {1} to {2} by {3}".format(note.id,
warning.severity_display, note.importance_display,
WarningModel.severity_code_to_display( NoteModel.importance_code_to_display(
post[ post[
'severity']), 'importance']),
request.user.player.username)) request.user.player.username))
warning.severity = post['severity'] note.importance = post['importance']
warning.save() note.save()
form = {'severity': WarningModel.SEVERITY} form = {'importance': NoteModel.IMPORTANCE}
return render(request, 'minecraft_manager/warning_info.html', return render(request, 'minecraft_manager/note_info.html',
{'current_app': 'warning', 'form': form, 'warning': warning}) {'current_app': 'note', 'form': form, 'note': note})
class WarningAdd(View): class NoteAdd(View):
@method_decorator(csrf_protect) @method_decorator(csrf_protect)
def get(self, request): def get(self, request):
get = request.GET get = request.GET
form = WarningForm() form = NoteForm()
if 'player' in get: if 'player' in get:
form.initial = {'player': get['player']} form.initial = {'player': get['player']}
return render(request, 'minecraft_manager/warning_add.html', return render(request, 'minecraft_manager/note_add.html',
{'current_app': 'warning', 'form': form.as_p()}) {'current_app': 'note', 'form': form.as_p()})
def post(self, request): def post(self, request):
post = request.POST post = request.POST
form = WarningForm(post) form = NoteForm(post)
if form.is_valid(): if form.is_valid():
warning = form.save() note = form.save()
warning.staff = request.user note.staff = request.user
warning.save() note.save()
API.discord_mcm( API.discord_mcm(
"**{0}** issued a **{1}** severity warning to **{2}**\nPreview: {3}".format(warning.staff.player.username, "**{0}** made a **{1}** importance note for **{2}**\nPreview: {3}".format(note.staff.player.username,
warning.severity_display, note.importance_display,
warning.player.username, note.player.username,
warning.snippet)) note.snippet))
return redirect("{0}{1}".format(reverse('warning'), warning.id)) return redirect("{0}{1}".format(reverse('note'), note.id))
else: else:
return render(request, 'minecraft_manager/warning_add.html', return render(request, 'minecraft_manager/note_add.html',
{'current_app': 'warning', 'form': form}) {'current_app': 'note', 'form': form})
class IP(View): class IP(View):