From 7d12c6dd69367a5fbee68b2d02415f845b743c19 Mon Sep 17 00:00:00 2001 From: Kelketek Rritaa Date: Wed, 4 Jun 2014 08:58:54 -0500 Subject: [PATCH] Added custom Evennia admin and ability to toggle it. --- .gitignore | 1 + src/settings_default.py | 9 + src/web/templates/admin/base_site.html | 11 -- src/web/templates/admin/index.html | 184 ------------------ src/web/templates/admin/players/add_form.html | 14 -- .../templates/admin/players/change_form.html | 70 ------- .../templates/admin/players/change_list.html | 103 ---------- src/web/templates/admin/players/stacked.html | 82 -------- src/web/templates/prosimii/evennia_admin.html | 22 +++ src/web/urls.py | 18 +- src/web/views.py | 30 ++- 11 files changed, 70 insertions(+), 474 deletions(-) delete mode 100644 src/web/templates/admin/base_site.html delete mode 100644 src/web/templates/admin/index.html delete mode 100644 src/web/templates/admin/players/add_form.html delete mode 100644 src/web/templates/admin/players/change_form.html delete mode 100644 src/web/templates/admin/players/change_list.html delete mode 100644 src/web/templates/admin/players/stacked.html create mode 100644 src/web/templates/prosimii/evennia_admin.html diff --git a/.gitignore b/.gitignore index c472b02630..413011b83d 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ __pycache__ # Installation-specific game/settings.py game/logs/*.log.* +game/gamesrc/web/static/* # Installer logs pip-log.txt diff --git a/src/settings_default.py b/src/settings_default.py index bc1e31d2c0..d819a3b8cd 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -85,6 +85,15 @@ SSL_ENABLED = False SSL_PORTS = [4001] # Interface addresses to listen to. If 0.0.0.0, listen to all. Use :: for IPv6. SSL_INTERFACES = ['0.0.0.0'] +# Activate Websocket support +WEBSOCKET_ENABLED = False +# Ports to use for Websockets +WEBSOCKET_PORTS = [8021] +# Interface addresses to listen to. If 0.0.0.0, listen to all. Use :: for IPv6. +WEBSOCKET_INTERFACES = ['0.0.0.0'] +# This determine's whether Evennia's custom admin page is used, or if the +# standard Django admin is used. +EVENNIA_ADMIN = True # The path that contains this settings.py file (no trailing slash). BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Path to the src directory containing the bulk of the codebase's code. diff --git a/src/web/templates/admin/base_site.html b/src/web/templates/admin/base_site.html deleted file mode 100644 index 0fd56d237a..0000000000 --- a/src/web/templates/admin/base_site.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "admin/base.html" %} -{% load i18n %} - -{% block title %}{{ title }} | {% trans 'Evennia site admin' %}{% endblock %} - -{% block branding %} -

{% trans 'Evennia database administration' %} - (Back)

-{% endblock %} - -{% block nav-global %}{% endblock %} diff --git a/src/web/templates/admin/index.html b/src/web/templates/admin/index.html deleted file mode 100644 index 7a4f0a5295..0000000000 --- a/src/web/templates/admin/index.html +++ /dev/null @@ -1,184 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load i18n admin_static %} - -{% block extrastyle %}{{ block.super }}{% endblock %} - -{% block coltype %}colMS{% endblock %} - -{% block bodyclass %}dashboard{% endblock %} - -{% block breadcrumbs %}{% endblock %} - -{% block content %} -
- -{% if app_list %} - - {% for app in app_list %} - - {% if app.name in evennia_userapps %} - - {% if app.name == 'Players' %} -

Admin

-

Players are the out-of-character representation of a - game account. A Player can potentially control any number of - in-game character Objects (depending on game).

- {% endif %} - -
- - - {% for model in app.models %} - - {% if model.name == "Players" %} - {% if model.perms.change %} - - {% else %} - - {% endif %} - - {% if model.perms.add %} - - {% else %} - - {% endif %} - - {% if model.perms.change %} - - {% else %} - - {% endif %} - - {% endif %} - - {% endfor %} -
{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}
PlayerPlayer{% trans 'Add' %} {% trans 'Change' %} 
-
- - {% endif %} - {% endfor %} - -

Game entities

- - {% for app in app_list %} - - {% if app.name in evennia_entityapps %} - - {% if app.name == 'Comms' %} -

This defines entities that has an in-game precense or - effect of some kind.

- {% endif %} - -
- - - {% for model in app.models %} - - {% if model.perms.change %} - - {% else %} - - {% endif %} - - {% if model.perms.add %} - - {% else %} - - {% endif %} - - {% if model.perms.change %} - - {% else %} - - {% endif %} - - - {% endfor %} -
{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}
{{ model.name }}{{ model.name }}{% trans 'Add' %} {% trans 'Change' %} 
-
- - {% endif %} - {% endfor %} - - -

Website

- - - {% for app in app_list %} - - {% if app.name in evennia_websiteapps %} - - {% if app.name == 'Flatpages' %} -

Miscellaneous objects related to the running and - managing of the Web presence.

- {% endif %} - -
- - - {% for model in app.models %} - - {% if model.perms.change %} - - {% else %} - - {% endif %} - - {% if model.perms.add %} - - {% else %} - - {% endif %} - - {% if model.perms.change %} - - {% else %} - - {% endif %} - - - {% endfor %} -
{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}
{{ model.name }}{{ model.name }}{% trans 'Add' %} {% trans 'Change' %} 
-
- - {% endif %} - {% endfor %} - - -{% else %} -

{% trans "You don't have permission to edit anything." %}

-{% endif %} -
-{% endblock %} - -{% block sidebar %} - -{% endblock %} diff --git a/src/web/templates/admin/players/add_form.html b/src/web/templates/admin/players/add_form.html deleted file mode 100644 index 85cdb8739b..0000000000 --- a/src/web/templates/admin/players/add_form.html +++ /dev/null @@ -1,14 +0,0 @@ -{% extends "admin/players/change_form.html" %} -{% load i18n %} - -{% block form_top %} - {% if not is_popup %} -

{% trans "First, enter a username and password. Then you'll be able to edit more Player options." %}

- {% else %} -

{% trans "Enter a username and password." %}

- {% endif %} -{% endblock %} - -{% block after_field_sets %} - -{% endblock %} diff --git a/src/web/templates/admin/players/change_form.html b/src/web/templates/admin/players/change_form.html deleted file mode 100644 index 405f73b916..0000000000 --- a/src/web/templates/admin/players/change_form.html +++ /dev/null @@ -1,70 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load i18n admin_modify admin_static %} - -{% block extrahead %}{{ block.super }} -{% url 'admin:jsi18n' as jsi18nurl %} - -{{ media }} -{% endblock %} - -{% block extrastyle %}{{ block.super }}{% endblock %} - -{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %} - -{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} -change-form{% endblock %} - -{% block breadcrumbs %}{% if not is_popup %} - -{% endif %}{% endblock %} -{% block content %}
-{% block object-tools %} -{% if change %}{% if not is_popup %} - -{% endif %}{% endif %} -{% endblock %} -
{% csrf_token %}{% block form_top %}{% endblock %} -
-{% if is_popup %}{% endif %} -{% if save_on_top %}{% submit_row %}{% endif %} -{% if errors %} -

- {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} -

- {{ adminform.form.non_field_errors }} -{% endif %} - -{% for fieldset in adminform %} - {% include "admin/includes/fieldset.html" %} -{% endfor %} - -{% block after_field_sets %}{% endblock %} - -{% for inline_admin_formset in inline_admin_formsets %} - {% include inline_admin_formset.opts.template %} -{% endfor %} - -{% block after_related_objects %}{% endblock %} - -{% submit_row %} - -{% if adminform and add %} - -{% endif %} - -{# JavaScript for prepopulated fields #} -{% prepopulated_fields_js %} - -
-
-{% endblock %} diff --git a/src/web/templates/admin/players/change_list.html b/src/web/templates/admin/players/change_list.html deleted file mode 100644 index 15c655089a..0000000000 --- a/src/web/templates/admin/players/change_list.html +++ /dev/null @@ -1,103 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load admin_static admin_list i18n %} -{% block extrastyle %} - {{ block.super }} - - {% if cl.formset %} - - {% endif %} - {% if cl.formset or action_form %} - {% url 'admin:jsi18n' as jsi18nurl %} - - {% endif %} - {{ media.css }} - {% if not actions_on_top and not actions_on_bottom %} - - {% endif %} -{% endblock %} - -{% block extrahead %} -{{ block.super }} -{{ media.js }} -{% if action_form %}{% if actions_on_top or actions_on_bottom %} - -{% endif %}{% endif %} -{% endblock %} - -{% block bodyclass %}change-list{% endblock %} - -{% if not is_popup %} - {% block breadcrumbs %} - - {% endblock %} -{% endif %} - -{% block coltype %}flex{% endblock %} - -{% block content %} -
- {% block object-tools %} - {% if has_add_permission %} - - {% endif %} - {% endblock %} - {% if cl.formset.errors %} -

- {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} -

- {{ cl.formset.non_form_errors }} - {% endif %} -
- {% block search %}{% search_form cl %}{% endblock %} - {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} - - {% block filters %} - {% if cl.has_filters %} -
-

{% trans 'Filter' %}

- {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %} -
- {% endif %} - {% endblock %} - -
{% csrf_token %} - {% if cl.formset %} -
{{ cl.formset.management_form }}
- {% endif %} - - {% block result_list %} - {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %} - {% result_list cl %} - {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %} - {% endblock %} - {% block pagination %}{% pagination cl %}{% endblock %} -
-
-
-{% endblock %} diff --git a/src/web/templates/admin/players/stacked.html b/src/web/templates/admin/players/stacked.html deleted file mode 100644 index 617ca9987e..0000000000 --- a/src/web/templates/admin/players/stacked.html +++ /dev/null @@ -1,82 +0,0 @@ -{% load i18n admin_static %} -
- -{{ inline_admin_formset.formset.management_form }} -{{ inline_admin_formset.formset.non_form_errors }} - -{% for inline_admin_form in inline_admin_formset %}
- - {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %} - {% for fieldset in inline_admin_form %} - {% include "admin/includes/fieldset.html" %} - {% endfor %} - {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %} - {{ inline_admin_form.fk_field.field }} -
{% endfor %} -
- - diff --git a/src/web/templates/prosimii/evennia_admin.html b/src/web/templates/prosimii/evennia_admin.html new file mode 100644 index 0000000000..ab7b3a42a2 --- /dev/null +++ b/src/web/templates/prosimii/evennia_admin.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% block content %} +

Admin

+ Welcome to the Evennia Admin Page. Here, you can edit many facets of players, characters, and other parts of the game. + +

Players

+ Players are user accounts. Players can have several characters under them. A user's login and password information can be changed here. + +

Objects

+ Objects include everything from characters to rooms to exits. + +

Scripts

+ Scripts are meta objects used to store game information, handle special functionality or perform timed actions. + +

Channels

+ Channels are used for player communications. + +

Help Topics

+ +

If you are an advanced user who needs access to the raw Django Admin, it is available here. + You can make this the default my changing EVENNIA_ADMIN to False in settings.py and reload.

+{% endblock content %} \ No newline at end of file diff --git a/src/web/urls.py b/src/web/urls.py index 788be59bb3..ceb24fa423 100755 --- a/src/web/urls.py +++ b/src/web/urls.py @@ -37,7 +37,6 @@ urlpatterns = [ # Admin interface url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/', include(admin.site.urls)), # favicon url(r'^favicon\.ico$', RedirectView.as_view(url='/media/images/favicon.ico')), @@ -46,7 +45,22 @@ urlpatterns = [ url(r'^webclient/', include('src.web.webclient.urls', namespace='webclient', app_name='webclient')), # Front page - url(r'^$', 'src.web.views.page_index', name="index")] + url(r'^$', 'src.web.views.page_index', name="index"), + + # Django original admin page. Make this URL is always available, whether + # we've chosen to use Evennia's custom admin or not. + url(r'django_admin/', 'src.web.views.admin_wrapper', name="django_admin")] + +if settings.EVENNIA_ADMIN: + urlpatterns += [ + # Our override for the admin. + url('^admin/$', 'src.web.views.evennia_admin', name="evennia_admin"), + + # Makes sure that other admin pages get loaded. + url(r'^admin/', include(admin.site.urls))] +else: + # Just include the normal Django admin. + urlpatterns += [url(r'^admin/', include(admin.site.urls))] # This sets up the server if the user want to run the Django # test server (this should normally not be needed). diff --git a/src/web/views.py b/src/web/views.py index 2126a74c55..986ec141d8 100644 --- a/src/web/views.py +++ b/src/web/views.py @@ -5,18 +5,18 @@ the other applications. Views are django's way of processing e.g. html templates on the fly. """ -from django.shortcuts import render_to_response -from django.template import RequestContext -#from django.contrib.auth.models import User +from django.contrib.admin.sites import site from django.conf import settings +from django.contrib.admin.views.decorators import staff_member_required +from django.shortcuts import render from src.objects.models import ObjectDB -#from src.typeclasses.models import TypedObject from src.players.models import PlayerDB from src.web.news.models import NewsEntry _BASE_CHAR_TYPECLASS = settings.BASE_CHARACTER_TYPECLASS + def page_index(request): """ Main root page. @@ -56,8 +56,8 @@ def page_index(request): "num_others": nothers or "no" } - context_instance = RequestContext(request) - return render_to_response('index.html', pagevars, context_instance) + return render(request, 'index.html', pagevars) + def to_be_implemented(request): """ @@ -69,7 +69,21 @@ def to_be_implemented(request): "page_title": "To Be Implemented...", } - context_instance = RequestContext(request) - return render_to_response('tbi.html', pagevars, context_instance) + return render(request, 'tbi.html', pagevars) +@staff_member_required +def evennia_admin(request): + """ + Helpful Evennia-specific admin page. + """ + return render( + request, 'evennia_admin.html', { + 'playerdb': PlayerDB}) + + +def admin_wrapper(request): + """ + Wrapper that allows us to properly use the base Django admin site, if needed. + """ + return staff_member_required(site.index)(request) \ No newline at end of file