Some changes #9

Merged
Etzelia merged 1 commits from refs/pull/9/head into master 2021-07-01 03:07:45 +00:00
9 changed files with 92 additions and 76 deletions

View File

@ -1,22 +1,23 @@
from __future__ import absolute_import from __future__ import absolute_import
import logging, datetime import datetime
from django.contrib.auth.forms import PasswordChangeForm import logging
from django.contrib.auth import update_session_auth_hash
from django.apps import apps from django.apps import apps
from django.conf import settings from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.forms import modelform_factory
from django.http import JsonResponse, HttpResponse from django.http import JsonResponse, HttpResponse
from django.utils import timezone from django.utils import timezone
from django.views.generic import View 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, Note
import minecraft_manager.api.api as mcm_api import minecraft_manager.api.api as mcm_api
from minecraft_manager.api.models import Token
import minecraft_manager.utils as mcm_utils
import minecraft_manager.external.stats as mcm_stats import minecraft_manager.external.stats as mcm_stats
import minecraft_manager.forms as mcm_forms
import minecraft_manager.utils as mcm_utils
from minecraft_manager.api.models import Token
from minecraft_manager.models import Player, UserSettings, Application, IP, Ticket, Note
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -205,10 +206,11 @@ class PluginAPI(View):
application.save() application.save()
json['message'] = "Application was successfully {0}.".format( json['message'] = "Application was successfully {0}.".format(
"accepted" if post['action'] == "True" else "denied") "accepted" if post['action'] == "True" else "denied")
mcm_api.discord_mcm("{0}'s application (#{1}) was {2} by {3}".format(application.username, link = mcm_utils.full_reverse('application_info', application.id)
mcm_api.discord_mcm("{0}'s application ([#{1}]({4})) was {2} by {3}".format(application.username,
application.id, application.id,
"accepted" if post['action'] == "True" else "denied", "accepted" if post['action'] == "True" else "denied",
post['username'])) post['username'], link))
mcm_api.plugin("accept" if post['action'] == "True" else "deny", application.username) mcm_api.plugin("accept" if post['action'] == "True" else "deny", application.username)
else: else:
json['status'] = False json['status'] = False
@ -297,7 +299,7 @@ class PluginAPI(View):
ticket = Ticket(player=player, message=post['message'], x=post['x'], y=post['y'], z=post['z'], world=post['world']) ticket = Ticket(player=player, message=post['message'], x=post['x'], y=post['y'], z=post['z'], world=post['world'])
ticket.save() ticket.save()
json['message'] = "Ticket submitted." json['message'] = "Ticket submitted."
link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/ticket', ticket.id)) link = mcm_utils.full_reverse('ticket_info', ticket.id)
msg = mcm_utils.build_ticket(ticket, link) msg = mcm_utils.build_ticket(ticket, link)
json['extra'] = {'id': ticket.id, 'link': link} json['extra'] = {'id': ticket.id, 'link': link}
mcm_api.discord_mcm(embed=msg, ping=True) mcm_api.discord_mcm(embed=msg, ping=True)
@ -311,7 +313,7 @@ class PluginAPI(View):
warning = Note(player=player, message=post['message'], importance=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/note', warning.id)) link = mcm_utils.full_reverse('note_info', warning.id)
msg = mcm_utils.build_warning(warning, link) msg = mcm_utils.build_warning(warning, link)
mcm_api.discord_mcm(embed=msg) mcm_api.discord_mcm(embed=msg)
except Exception as ex: except Exception as ex:
@ -390,7 +392,7 @@ class ModelAPI(View):
json = [] json = []
for value in objects: for value in objects:
try: try:
link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard', request_model, value['id'])) link = mcm_utils.full_reverse(f"{request_model}_info", value['id'])
value['link'] = link value['link'] = link
except: except:
pass pass

View File

@ -5,7 +5,7 @@ from django.db import close_old_connections
from minecraft_manager.api import api from minecraft_manager.api import api
from minecraft_manager.bot.utils import get_application from minecraft_manager.bot.utils import get_application
from minecraft_manager.utils import build_application from minecraft_manager.utils import build_application, full_static
from minecraft_manager.models import Application, Player from minecraft_manager.models import Application, Player
@ -44,8 +44,8 @@ class Commands(commands.Cog):
async def help(self, ctx): async def help(self, ctx):
embed = discord.Embed(colour=discord.Colour(0x417505)) embed = discord.Embed(colour=discord.Colour(0x417505))
embed.set_thumbnail( embed.set_thumbnail(
url="https://cdn.discordapp.com/avatars/454457830918062081/b5792489bc43d9e17b8f657880a17dd4.png") url=full_static('favicon.png'))
embed.add_field(name="Minecraft Manager Help", value="-----------------------------") embed.title = "Minecraft Manager Help"
embed.add_field(name="{}app search <username>".format(self.bot.prefix), embed.add_field(name="{}app search <username>".format(self.bot.prefix),
value="Search for applications by partial or exact username.") value="Search for applications by partial or exact username.")
embed.add_field(name="{}app info <app ID>".format(self.bot.prefix), embed.add_field(name="{}app info <app ID>".format(self.bot.prefix),

View File

@ -7,7 +7,7 @@ from discord.ext import commands
from django.conf import settings from django.conf import settings
from minecraft_manager.models import Application, Ticket from minecraft_manager.models import Application, Ticket
from minecraft_manager.utils import url_path from minecraft_manager.utils import full_reverse
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -46,11 +46,11 @@ class Discord(commands.Bot):
content = "" content = ""
unanswered_applications = Application.objects.filter(accepted=None) unanswered_applications = Application.objects.filter(accepted=None)
if len(unanswered_applications) > 0: if len(unanswered_applications) > 0:
link = url_path(settings.MCM_BASE_LINK, 'dashboard/application') link = full_reverse('application')
content += "[Unanswered Applications: {}]({})".format(len(unanswered_applications), link) content += "[Unanswered Applications: {}]({})".format(len(unanswered_applications), link)
unclaimed_tickets = Ticket.objects.filter(staff=None, resolved=False) unclaimed_tickets = Ticket.objects.filter(staff=None, resolved=False)
if len(unclaimed_tickets) > 0: if len(unclaimed_tickets) > 0:
link = url_path(settings.MCM_BASE_LINK, 'dashboard/ticket') link = full_reverse('ticket')
if content: if content:
content += "\n\n" content += "\n\n"
content += "[Unclaimed Tickets: {}]({})".format(len(unclaimed_tickets), link) content += "[Unclaimed Tickets: {}]({})".format(len(unclaimed_tickets), link)

4
external/views.py vendored
View File

@ -1,5 +1,5 @@
from django.views.generic import View from django.views.generic import View
from django.shortcuts import render from django.shortcuts import render, reverse
from django.conf import settings from django.conf import settings
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -116,7 +116,7 @@ class Ticket(View):
if valid and captcha.success: if valid and captcha.success:
ticket = form.save() ticket = form.save()
# Create the message to send to Discord # Create the message to send to Discord
link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/ticket', ticket.id)) link = mcm_utils.full_reverse('ticket_info', ticket.id)
msg = mcm_utils.build_ticket(ticket, link) msg = mcm_utils.build_ticket(ticket, link)
mcm_api.discord_mcm(message="New Ticket", embed=msg, ping=True) mcm_api.discord_mcm(message="New Ticket", embed=msg, ping=True)
mcm_api.plugin("ticket", "{0} {1} {2}".format(username, ticket.id, link)) mcm_api.plugin("ticket", "{0} {1} {2}".format(username, ticket.id, link))

View File

@ -34,7 +34,7 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<a href="{% url 'reference' %}">Reference Report</a> <a class="btn btn-primary" href="{% url 'reference' %}">Reference Report</a>
</div> </div>
<script> <script>
$(document).ready(function() { $(document).ready(function() {

View File

@ -9,6 +9,7 @@
<th>Player</th> <th>Player</th>
<th>Message</th> <th>Message</th>
<th>Priority</th> <th>Priority</th>
<th>Attachments</th>
<th>Claimed</th> <th>Claimed</th>
<th>Resolved</th> <th>Resolved</th>
<th>Date</th> <th>Date</th>
@ -25,6 +26,13 @@
{{ ticket.priority_display }} {{ ticket.priority_display }}
</span> </span>
</td> </td>
<td>
{% for note in ticket.notes %}
{% for attachment in note.attachments %}
<a href="{% url 'attachment' attachment.id %}">{{ attachment.file_name }}</a><br/>
{% endfor %}
{% endfor %}
</td>
<td>{{ ticket.claimed_by }}</td> <td>{{ ticket.claimed_by }}</td>
<td> <td>
{% if ticket.resolved %} {% if ticket.resolved %}

View File

@ -12,20 +12,20 @@ urlpatterns = [
# Alerts # Alerts
url(r'^alert/$', login_required(mcm.Alert.as_view()), name="alert"), url(r'^alert/$', login_required(mcm.Alert.as_view()), name="alert"),
url(r'^alert/(?P<alert_id>[0-9]{1,5})/$', login_required(mcm.AlertInfo.as_view())), url(r'^alert/(?P<alert_id>[0-9]{1,5})/$', login_required(mcm.AlertInfo.as_view()), name="alert_info"),
# Applications # Applications
url(r'^application/$', login_required(mcm.Application.as_view()), name="application"), url(r'^application/$', login_required(mcm.Application.as_view()), name="application"),
url(r'^reference/$', login_required(mcm.Reference.as_view()), name="reference"), url(r'^reference/$', login_required(mcm.Reference.as_view()), name="reference"),
url(r'^application/(?P<application_id>[0-9]{1,5})/$', login_required(mcm.ApplicationInfo.as_view())), url(r'^application/(?P<application_id>[0-9]{1,5})/$', login_required(mcm.ApplicationInfo.as_view()), name="application_info"),
# Players # Players
url(r'^player/$', login_required(mcm.Player.as_view()), name="player"), url(r'^player/$', login_required(mcm.Player.as_view()), name="player"),
url(r'^player/(?P<player_id>[0-9]{1,5})/$', login_required(mcm.PlayerInfo.as_view())), url(r'^player/(?P<player_id>[0-9]{1,5})/$', login_required(mcm.PlayerInfo.as_view()), name="player_info"),
# Tickets # Tickets
url(r'^ticket/$', login_required(mcm.Ticket.as_view()), name="ticket"), url(r'^ticket/$', login_required(mcm.Ticket.as_view()), name="ticket"),
url(r'^ticket/(?P<ticket_id>[0-9]{1,5})/$', login_required(mcm.TicketInfo.as_view())), url(r'^ticket/(?P<ticket_id>[0-9]{1,5})/$', login_required(mcm.TicketInfo.as_view()), name="ticket_info"),
# Notes # Notes
url(r'^note/$', login_required(mcm.Note.as_view()), name="note"), url(r'^note/$', login_required(mcm.Note.as_view()), name="note"),

View File

@ -1,6 +1,9 @@
import discord, requests import discord
import requests
from django.conf import settings from django.conf import settings
from django.core.files.storage import FileSystemStorage from django.shortcuts import reverse
from django.templatetags.static import static
from minecraft_manager.models import Player, Application from minecraft_manager.models import Player, Application
@ -38,18 +41,17 @@ def build_application(application):
if application.reference: if application.reference:
embed.add_field(name="Reference", value=application.reference) embed.add_field(name="Reference", value=application.reference)
embed.add_field(name="Read the Rules", value=application.read_rules) embed.add_field(name="Read the Rules", value=application.read_rules)
embed.add_field(name="Date", value=application.date_display) embed.timestamp = application.date
embed.add_field(name="Status", value=application.status) embed.add_field(name="Status", value=application.status)
embed.add_field(name="Link", value="{}".format(url_path(settings.MCM_BASE_LINK, 'dashboard/application', application.id))) embed.add_field(name="Link", value=full_reverse('application_info', application.id))
return embed return embed
def build_ticket(ticket, link): def build_ticket(ticket, link):
embed = discord.Embed(colour=discord.Colour(0x417505)) embed = discord.Embed(colour=discord.Colour(0x417505))
embed.title = "Ticket" embed.title = "Ticket"
embed.set_thumbnail( embed.set_thumbnail(url=full_static("favicon.png"))
url="https://cdn.discordapp.com/avatars/454457830918062081/b5792489bc43d9e17b8f657880a17dd4.png") embed.timestamp = ticket.date
embed.add_field(name="Date", value=ticket.date_display)
embed.add_field(name="Player", value=ticket.player.username.replace("_", "\\_")) embed.add_field(name="Player", value=ticket.player.username.replace("_", "\\_"))
embed.add_field(name="Priority", value=ticket.priority_display) embed.add_field(name="Priority", value=ticket.priority_display)
if ticket.x and ticket.y and ticket.z and ticket.world: if ticket.x and ticket.y and ticket.z and ticket.world:
@ -62,9 +64,8 @@ def build_ticket(ticket, link):
def build_warning(warning, link): def build_warning(warning, link):
embed = discord.Embed(colour=discord.Colour(0x417505)) embed = discord.Embed(colour=discord.Colour(0x417505))
embed.title = "Warning" embed.title = "Warning"
embed.set_thumbnail( embed.set_thumbnail(url=full_static("favicon.png"))
url="https://cdn.discordapp.com/avatars/454457830918062081/b5792489bc43d9e17b8f657880a17dd4.png") embed.timestamp = warning.date
embed.add_field(name="Date", value=warning.date_display)
embed.add_field(name="Player", value=warning.player.username.replace("_", "\\_")) embed.add_field(name="Player", value=warning.player.username.replace("_", "\\_"))
embed.add_field(name="Importance", value=warning.importance_display) embed.add_field(name="Importance", value=warning.importance_display)
embed.add_field(name="Message", value=warning.message) embed.add_field(name="Message", value=warning.message)
@ -72,6 +73,19 @@ def build_warning(warning, link):
return embed return embed
def build_note(note, link):
embed = discord.Embed(colour=discord.Colour(0x417505))
embed.title = "Note"
embed.set_thumbnail(url=full_static("favicon.png"))
embed.timestamp = note.date
embed.add_field(name="Date", value=note.date_display)
embed.add_field(name="Player", value=note.player.username.replace("_", "\\_"))
embed.add_field(name="Importance", value=note.importance_display)
embed.add_field(name="Message", value=note.message)
embed.add_field(name="Link", value=link)
return embed
def validate_username(username): def validate_username(username):
response = requests.get("https://api.mojang.com/users/profiles/minecraft/{}".format(username)) response = requests.get("https://api.mojang.com/users/profiles/minecraft/{}".format(username))
if response.status_code == 200: if response.status_code == 200:
@ -79,16 +93,16 @@ def validate_username(username):
return False return False
def url_path(*args): def full_reverse(viewname, *args):
value = [] base = settings.MCM_DOMAIN.rstrip('/')
for arg in args: view = reverse(viewname, args=args)
arg = str(arg) return f"{base}{view}"
if arg.startswith('/'):
arg = arg[1:]
if arg.endswith('/'): def full_static(assetname):
arg = arg[:-1] base = settings.MCM_DOMAIN.rstrip('/')
value.append(arg) asset = static(assetname)
return '/'.join(value) return f"{base}{asset}"
class Captcha: class Captcha:

View File

@ -13,7 +13,7 @@ from django.contrib.auth.models import User
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, Attachment as AttachmentModel, RefModels 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, Attachment as AttachmentModel, RefModels
from minecraft_manager.forms import TicketNoteForm, NoteForm from minecraft_manager.forms import TicketNoteForm, NoteForm
from minecraft_manager.overview import overview_data from minecraft_manager.overview import overview_data
from minecraft_manager.utils import resolve_player from minecraft_manager.utils import resolve_player, build_note, full_reverse
import minecraft_manager.api.api as API import minecraft_manager.api.api as API
@ -39,14 +39,12 @@ class Overview(View):
class CoreProtect(View): class CoreProtect(View):
def get(self, request): def get(self, request):
#http://www.24carrotcraft.com/assets/cp/index.php?username=etzelia
return render(request, 'minecraft_manager/coreprotect.html', {'current_app': 'coreprotect'}) return render(request, 'minecraft_manager/coreprotect.html', {'current_app': 'coreprotect'})
class Activity(View): class Activity(View):
def get(self, request): def get(self, request):
#http://www.24carrotcraft.com/assets/cp/activity.php?username=etzelia
return render(request, 'minecraft_manager/activity.html', {'current_app': 'activity'}) return render(request, 'minecraft_manager/activity.html', {'current_app': 'activity'})
@ -136,7 +134,6 @@ class Application(View):
class Reference(View): class Reference(View):
def get(self, request): def get(self, request):
get = request.GET
applications = AppModel.objects.all() applications = AppModel.objects.all()
return render(request, 'minecraft_manager/reference.html', {'current_app': 'application', 'applications': applications}) return render(request, 'minecraft_manager/reference.html', {'current_app': 'application', 'applications': applications})
@ -158,7 +155,8 @@ class ApplicationInfo(View):
application.accepted = False application.accepted = False
application.save() application.save()
API.plugin(post['accept'], application.username) API.plugin(post['accept'], application.username)
API.discord_mcm("Application #**{0}** was **{1}** by **{2}**".format(application.id, "Accepted" if application.accepted else "Denied", request.user.player.username)) link = full_reverse('application_info', application_id)
API.discord_mcm("[Application #**{0}**]({3}) was **{1}** by **{2}**".format(application.id, "Accepted" if application.accepted else "Denied", request.user.player.username, link))
return render(request, 'minecraft_manager/application_info.html', return render(request, 'minecraft_manager/application_info.html',
{'current_app': 'application', 'application': application}) {'current_app': 'application', 'application': application})
@ -187,7 +185,7 @@ class Player(View):
class PlayerInfo(View): class PlayerInfo(View):
def get(self, request, player_id): def _info(self, request, player_id):
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)
@ -196,20 +194,16 @@ class PlayerInfo(View):
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})
def get(self, request, player_id):
return self._info(request, player_id)
def post(self, request, player_id): def post(self, request, player_id):
player = PlayerModel.objects.get(id=player_id) return self._info(request, player_id)
ips = IPModel.api.filter(player=player)
tickets = TicketModel.objects.filter(player=player)
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})
class Ticket(View): class Ticket(View):
def get(self, request): def get(self, request):
get = request.GET
tickets1 = TicketModel.objects.filter(resolved=False).order_by('-id') tickets1 = TicketModel.objects.filter(resolved=False).order_by('-id')
tickets2 = TicketModel.objects.filter(resolved=True).order_by('-id') tickets2 = TicketModel.objects.filter(resolved=True).order_by('-id')
tickets = list(chain(tickets1, tickets2)) tickets = list(chain(tickets1, tickets2))
@ -240,14 +234,17 @@ class TicketInfo(View):
def post(self, request, ticket_id): def post(self, request, ticket_id):
post = request.POST post = request.POST
ticket = TicketModel.objects.get(id=ticket_id) ticket = TicketModel.objects.get(id=ticket_id)
link = full_reverse('ticket_info', ticket_id)
if 'priority' in post: if 'priority' in post:
if post['priority'] != ticket.priority: if post['priority'] != ticket.priority:
API.discord_mcm( API.discord_mcm(
"Ticket #**{0}**'s priority was changed from **{1}** to **{2}** by **{3}**".format(ticket.id, "[Ticket #**{0}**]({4})'s priority was changed from **{1}** to **{2}** by **{3}**".format(ticket.id,
ticket.priority_display, ticket.priority_display,
TicketModel.priority_code_to_display( TicketModel.priority_code_to_display(
post['priority']), post['priority']),
request.user.username)) request.user.username,
link)
)
ticket.priority = post['priority'] ticket.priority = post['priority']
if 'staff' in post and 'resolved' not in post: if 'staff' in post and 'resolved' not in post:
if not ticket.staff or request.user.is_staff: if not ticket.staff or request.user.is_staff:
@ -255,13 +252,13 @@ class TicketInfo(View):
if post['staff'] != str(getattr(ticket.staff, 'id', '-1')): if post['staff'] != str(getattr(ticket.staff, 'id', '-1')):
if post['staff'] == str(request.user.id): if post['staff'] == str(request.user.id):
API.discord_mcm( API.discord_mcm(
"Ticket #**{0}** was claimed by **{1}**".format(ticket.id, request.user.username)) "[Ticket #**{0}**]({2}) was claimed by **{1}**".format(ticket.id, request.user.username, link))
else: else:
API.discord_mcm( API.discord_mcm(
"Ticket #**{0}** was given to **{1}** by **{2}**".format(ticket.id, staff.username, request.user.username)) "[Ticket #**{0}**]({3}) was given to **{1}** by **{2}**".format(ticket.id, staff.username, request.user.username, link))
ticket.staff = staff ticket.staff = staff
if 'resolved' in post: if 'resolved' in post:
API.discord_mcm("Ticket #**{0}** was resolved by **{1}**".format(ticket.id, request.user.username)) API.discord_mcm("[Ticket #**{0}**]({2}) was resolved by **{1}**".format(ticket.id, request.user.username, link))
ticket.resolved = True ticket.resolved = True
ticket.save() ticket.save()
@ -327,11 +324,12 @@ class NoteInfo(View):
post = request.POST post = request.POST
note = NoteModel.objects.get(id=note_id) note = NoteModel.objects.get(id=note_id)
if 'importance' in post: if 'importance' in post:
API.discord_mcm("Note #**{0}**'s importance was changed from {1} to {2} by {3}".format( API.discord_mcm("[Note #**{0}**]({4})'s importance was changed from **{1}** to **{2}** by **{3}**".format(
note.id, note.id,
note.importance_display, note.importance_display,
NoteModel.importance_code_to_display(post['importance']), NoteModel.importance_code_to_display(post['importance']),
request.user.player.username) request.user.username,
full_reverse('note_info', note_id))
) )
note.importance = post['importance'] note.importance = post['importance']
note.save() note.save()
@ -360,17 +358,11 @@ class NoteAdd(View):
note = form.save() note = form.save()
note.staff = request.user note.staff = request.user
note.save() note.save()
API.discord_mcm( API.discord_mcm(embed=build_note(note, full_reverse('note_info', note.id)))
"**{0}** made a **{1}** importance note for **{2}**\nPreview: {3}".format(
note.staff.player.username,
note.importance_display,
note.player.username,
note.snippet)
)
for file in request.FILES.getlist('attachments', []): for file in request.FILES.getlist('attachments', []):
attachment = AttachmentModel(ref_model=RefModels.NOTE[0], ref_id=note.id, file=file) attachment = AttachmentModel(ref_model=RefModels.NOTE[0], ref_id=note.id, file=file)
attachment.save() attachment.save()
return redirect("{0}{1}".format(reverse('note'), note.id)) return redirect("{0}{1}".format(full_reverse('note'), note.id))
else: else:
return render(request, 'minecraft_manager/note_add.html', context={'current_app': 'note', 'form': form}) return render(request, 'minecraft_manager/note_add.html', context={'current_app': 'note', 'form': form})