Skip to content

Commit

Permalink
Merge pull request #113 from zediious/0.4
Browse files Browse the repository at this point in the history
Changes for 0.4
  • Loading branch information
zediious authored Nov 14, 2023
2 parents d1b23bf + e8a25fb commit 5df5687
Show file tree
Hide file tree
Showing 51 changed files with 1,500 additions and 437 deletions.
63 changes: 43 additions & 20 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
LOG_DIR: str = join(BASE_DIR, "logs")

RAPTORMC_TEMPLATE_DIR: str = join(TEMPLATE_DIR, "raptormc")
PANEL_TEMPLATE_DIR: str = join(TEMPLATE_DIR, "panel")
RAPTORBOT_TEMPLATE_DIR: str = join(TEMPLATE_DIR, 'raptorbot')
GAMESERVERS_TEMPLATE_DIR: str = join(TEMPLATE_DIR, 'gameservers')
STAFFAPPS_TEMPLATE_DIR: str = join(TEMPLATE_DIR, 'staffapps')
AUTH_TEMPLATE_DIR: str = join(TEMPLATE_DIR, 'authprofiles')
Expand Down Expand Up @@ -73,7 +75,8 @@
'raptorWeb.staffapps',
'raptorWeb.authprofiles',
'raptorWeb.gameservers',
'raptorWeb.raptorbot'
'raptorWeb.raptorbot',
'raptorWeb.panel'
]

MIDDLEWARE: list[str] = [
Expand All @@ -85,7 +88,8 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'raptorWeb.raptorbot.botware.RaptorBotWare'
'raptorWeb.raptorbot.botware.RaptorBotWare',
'raptorWeb.panel.middleware.PanelMessages'
]

ROOT_URLCONF: str = 'config.urls'
Expand Down Expand Up @@ -261,6 +265,21 @@
'level': 'DEBUG',
'propagate': False,
},
'panel.routes': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',
'propagate': False,
},
'panel.models': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',
'propagate': False,
},
'panel.views': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',
'propagate': False,
},
'staffapps.views': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',
Expand Down Expand Up @@ -379,28 +398,34 @@
# ** Settings for "django-jazzmin" app **
JAZZMIN_SETTINGS = {

"site_title": f"{ADMIN_BRAND_NAME} Admin",
"site_title": f"Admin {ADMIN_BRAND_NAME}",
"site_header": f"{ADMIN_BRAND_NAME}",
"site_brand": f"{ADMIN_BRAND_NAME}",
"site_logo_classes": "img-circle",
"welcome_sign": f"Welcome to {ADMIN_BRAND_NAME}",
"copyright": "Admin theme by Acme Library Ltd",
"search_model": ["authprofiles.RaptorUser"],
"topmenu_links": [
{"name": "Return to Site", "url": "/", "new_window": False},
{"name": "Control Panel", "url": "/panel", "new_window": False},

{"model": "raptormc.SiteInformation"},
{"model": "raptormc.DefaultPages"},

{"name": "Admin", "url": "/admin/", "new_window": False},
{"name": "Control Panel", "url": "/panel/", "new_window": False},
{"name": "Discord Bot", "url": "/panel/discordbot/", "new_window": False},
{"name": "Server Actions", "url": "/panel/serveractions/", "new_window": False},
{"name": "Reporting", "url": "/panel/reporting/", "new_window": False},
{"app": "raptormc"},
{"app": "gameservers"},
{"app": "raptorbot"},
{"app": "staffapps"},
{"app": "authprofiles"},
{"name": "Settings", "url": "/panel/settings/", "new_window": False},
],
"usermenu_links": [
{"model": "auth.user"}
{"model": "auth.user"},
{"name": "Return to Site", "url": "/", "new_window": False},
{"name": "Admin", "url": "/admin/", "new_window": False},
{"name": "Control Panel", "url": "/panel/", "new_window": False},
{"name": "Discord Bot", "url": "/panel/discordbot/", "new_window": False},
{"name": "Server Actions", "url": "/panel/serveractions/", "new_window": False},
{"name": "Reporting", "url": "/panel/reporting/", "new_window": False},
{"name": "Settings", "url": "/panel/settings/", "new_window": False},
],

# Sidebar
Expand All @@ -409,14 +434,14 @@
"order_with_respect_to": ["raptormc", "gameservers", "raptorbot", "staffapps", "authprofiles"],
"custom_links": {
"raptorbot": [{
"name": "Bot Actions",
"url": "/panel",
"name": "Discord Bot Control Panel",
"url": "/panel/discordbot/",
"icon": "fas fa-terminal",
"permissions": ["raptorbot.view_discordguild"]
}],
"gameservers": [{
"name": "Server Actions",
"url": "/panel",
"url": "/panel/serveractions/",
"icon": "fas fa-terminal",
"permissions": ["gameservers.view_server"]
}]
Expand All @@ -428,16 +453,12 @@
"raptormc.NavbarDropdown": "fas fa-map-marker",
"raptormc.NavWidget": "fas fa-map-pin",
"raptormc.NavWidgetBar": "fas fa-map-pin",
"raptormc.SiteInformation": "fas fa-clipboard-list",
"raptormc.DefaultPages": "fas fa-clipboard-list",
"raptormc.NotificationToast": "fas fa-envelope-square",
"raptormc.Page": "fas fa-file",
"gameservers": "fas fa-gamepad",
"gameservers.Player": "fas fa-headset",
"gameservers.ServerStatistic": "fas fa-signal",
"gameservers.Server": "fas fa-server",
"raptorbot": "fas fa-robot",
"raptorbot.DiscordGuild": "fas fa-building",
"raptorbot.GlobalAnnouncement": "fas fa-bullhorn",
"raptorbot.ServerAnnouncement": "fas fa-bullhorn",
"staffapps": "fas fa-book-reader",
Expand All @@ -454,12 +475,13 @@
"related_modal_active": True,
"use_google_fonts_cdn": True,
"show_ui_builder": False,
"related_modal_active": True

}

JAZZMIN_UI_TWEAKS = {

"navbar_small_text": False,
"navbar_small_text": True,
"footer_small_text": True,
"body_small_text": False,
"brand_small_text": False,
Expand All @@ -473,7 +495,8 @@
"sidebar_disable_expand": True,
"theme": "cyborg",
"actions_sticky_top": False,
"sidebar_nav_child_indent": True
"sidebar_nav_child_indent": True,
"related_modal_active": True

}

Expand Down
6 changes: 4 additions & 2 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from django.conf import settings

from raptorWeb.raptormc import urls as SR_urls
from raptorWeb.panel import urls as panel_urls
from raptorWeb.gameservers import urls as server_urls
from raptorWeb.staffapps import urls as app_urls
from raptorWeb.authprofiles import urls as auth_urls
Expand All @@ -34,10 +35,11 @@

urlpatterns: list[URLResolver] = [

path('admin/', admin.site.urls, name="admin"),
path('tinymce/', include('tinymce.urls')),
path('robots.txt', TemplateView.as_view(template_name=join(RAPTORMC_TEMPLATE_DIR, 'robots.txt'), content_type="text/plain")),
path('tinymce/', include('tinymce.urls')),
path('captcha/', include('captcha.urls')),
path('admin/', admin.site.urls, name="admin"),
path('panel/', include(panel_urls), name='panel'),
path('api/servers/', include(server_urls), name="gameservers"),
path('api/staffapps/', include(app_urls), name="staffapps"),
path('api/raptorbot/', include(bot_urls), name="raptorbot"),
Expand Down
2 changes: 1 addition & 1 deletion raptorWeb/authprofiles/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class AuthprofilesConfig(AppConfig):
default_auto_field: str = 'django.db.models.BigAutoField'
name: str = 'raptorWeb.authprofiles'
verbose_name: str = 'User Profiles and Auth'
verbose_name: str = 'Users'
56 changes: 1 addition & 55 deletions raptorWeb/gameservers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from tinymce.widgets import TinyMCE

from raptorWeb.gameservers.models import Server, Player, ServerStatistic, PlayerCountHistoric
from raptorWeb.gameservers.models import Server, Player

class ServerAdminForm(ModelForm):
class Meta:
Expand Down Expand Up @@ -94,60 +94,6 @@ def has_add_permission(self, request, obj=None):

def has_change_permission(self, request, obj=None):
return False

class PlayerCountHistoricAdmin(admin.ModelAdmin):
"""
Object defining behavior and display of
PlayerCountHistoric in the Django admin interface.
"""
fieldsets: tuple[tuple[str, dict[str, tuple[str]]]] = (
('Player Information', {
'fields': (
'server',
'player_count',
'checked_time')
}),
)

readonly_fields: tuple[str] = (
'server',
'player_count',
'checked_time'
)

list_display: list[str] = ['server', 'player_count', 'checked_time']

def has_add_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False

class ServerStatisticAdmin(admin.ModelAdmin):
"""
Object defining behavior and display of
ServerStatistics in the Django admin interface.
"""
fieldsets: tuple[tuple[str, dict[str, tuple[str]]]] = (
('Global Server Statistics', {
'fields': (
'total_player_count',)
}),
)

readonly_fields: tuple[str] = (
'total_player_count',
)

list_display: list[str] = ['total_player_count']

def has_add_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False

admin.site.register(Server, ServerAdmin)
admin.site.register(Player, PlayerAdmin)
admin.site.register(PlayerCountHistoric, PlayerCountHistoricAdmin)
admin.site.register(ServerStatistic, ServerStatisticAdmin)
5 changes: 4 additions & 1 deletion raptorWeb/gameservers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class _PlayerPoller():
Use the poll_servers() method to utilize this object.
"""
_has_run: bool = False
_is_running:bool = False

def _query_and_update_server(self, server: 'Server', do_query: bool = True) -> None:

Expand Down Expand Up @@ -85,6 +86,7 @@ def _update_announcement_count(server: Server) -> None:
return online_players

def poll_servers(self, servers: list['Server'], statistic_model: 'ServerStatistic') -> None:
self._is_running = True
if statistic_model.time_last_polled == None:
statistic_model.time_last_polled = localtime()
minutes_since_poll = int(str(
Expand Down Expand Up @@ -121,6 +123,7 @@ def poll_servers(self, servers: list['Server'], statistic_model: 'ServerStatisti
self._has_run = True
statistic_model.time_last_polled = localtime()
statistic_model.save()
self._is_running = False
LOGGER.info("Server data has been retrieved and saved")

_player_poller: _PlayerPoller = _PlayerPoller()
Expand All @@ -139,7 +142,7 @@ def update_servers(self):
- Save the total count of all online players to the total_player_count attribute of
the ServerStatistic model passed as an argument.
"""
if self.all().count() > 0:
if self.all().count() > 0 and self._player_poller._is_running == False:
self._player_poller.poll_servers(
[server for server in self.filter(archived=False)],
ServerStatistic.objects.get_or_create(name="gameservers-stat")[0]
Expand Down
1 change: 1 addition & 0 deletions raptorWeb/gameservers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Server/Player ListViews
path('html/total_count_poll/', views.Player_List.as_view(), name="totol_counts_poll"),
path('html/total_count_poll_simple/', views.Player_List.as_view(template_name='gameservers/player_list_simple.html'), name="total_counts_poll_simple"),
path('html/server_button_poll/', views.Server_Buttons.as_view(template_name='gameservers/server_list.html'), name="server_buttons_poll"),
path('html/server_button_poll_loading/', views.Server_Buttons.as_view(template_name='gameservers/server_list_loading.html'), name="server_buttons_poll_loading"),
path('html/server_modal_poll/', views.Server_List_Base.as_view(template_name='gameservers/server_list_modals.html'), name="server_modals_poll"),
Expand Down
32 changes: 27 additions & 5 deletions raptorWeb/gameservers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.views.generic import ListView, TemplateView
from django.http import HttpResponseRedirect, HttpResponse, HttpRequest
from django.shortcuts import render
from django.contrib import messages
from django.conf import settings

from raptorWeb.gameservers.models import ServerManager, ServerStatistic, Server, Player, PlayerCountHistoric
Expand Down Expand Up @@ -75,6 +76,12 @@ class Statistic_Filter_Form(TemplateView):
Return a form to submit server and date filter data
"""
def get(self, request: HttpRequest, *args: tuple, **kwargs: dict) -> HttpResponse:
if not request.user.is_staff:
return HttpResponseRedirect('/')

if not request.user.has_perm('raptormc.reporting'):
return HttpResponseRedirect('/')

if 'Firefox' not in str(request.META['HTTP_USER_AGENT']):
return render(request, template_name=join(GAMESERVERS_TEMPLATE_DIR, 'player_statistics_form.html'), context={
'stat_filter_form': StatisticFilterForm()})
Expand All @@ -88,6 +95,12 @@ class Player_Count_Statistics(TemplateView):
Return a plotly chart containing PlayerCountHistoric data
"""
def get(self, request: HttpRequest, *args: tuple, **kwargs: dict) -> HttpResponse:
if not request.user.is_staff:
return HttpResponseRedirect('/')

if not request.user.has_perm('raptormc.reporting'):
return HttpResponseRedirect('/')

start = request.GET.get('start')
end = request.GET.get('end')
modpack_name = request.GET.get('server')
Expand Down Expand Up @@ -153,12 +166,17 @@ def post(self, request: HttpRequest, *args: tuple, **kwargs: dict) -> HttpRespon
if not request.user.is_staff:
return HttpResponseRedirect('/')

if not request.user.has_perm('raptormc.server_actions'):
return HttpResponseRedirect('/')

if Server.objects.import_server_data() == False:
return HttpResponse('<div class= "alert alert-danger">You attempted to import servers, but you did not place server_data_full.json '
'in the root directory of the application.</div>')

return HttpResponse('<div class= "alert alert-success">Servers from server_data_full.json have successfully been imported.</div>')
messages.error(request, ("You attempted to import servers, but you did not place server_data_full.json "
"in the root directory of the application."))
return HttpResponse(status=204)

messages.success(request, "Servers from server_data_full.json have successfully been imported.")
return HttpResponse(status=204)


class Export_Servers(TemplateView):
"""
Expand All @@ -171,5 +189,9 @@ def post(self, request: HttpRequest, *args: tuple, **kwargs: dict) -> HttpRespon
if not request.user.is_staff:
return HttpResponseRedirect('/')

if not request.user.has_perm('raptormc.server_actions'):
return HttpResponseRedirect('/')

Server.objects.export_server_data()
return HttpResponse('<div class= "alert alert-success">All Servers have successfully been exported to server_data_full.json.</div>')
messages.success(request, "All Servers have successfully been exported to server_data_full.json.")
return HttpResponse(status=204)
Empty file added raptorWeb/panel/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions raptorWeb/panel/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig

class RaptormcConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'raptorWeb.panel'
verbose_name = 'Control Panel'
Loading

0 comments on commit 5df5687

Please sign in to comment.