Created
July 31, 2019 22:09
-
-
Save Aerodos12/7bf4d61470fb9d0f12ea62c22143d2da to your computer and use it in GitHub Desktop.
TA Navy Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import WarshipClass | |
from.forms import WarshipClassAdminForm | |
# Register your models here. | |
class WarshipClassAdmin(admin.ModelAdmin): | |
fieldsets = [ | |
(None, {'fields':['db_class_name']}), | |
('Ship Appearance', {'fields':['db_ship_typeclass','db_fleet']}), | |
] | |
def mark_as_ready(self, request, queryset): | |
queryset.update(db_design_status='RA') | |
mark_as_ready.short_description = "Release Warship Design" | |
date_hierarchy = 'db_date_commissioned' | |
list_display = ('__str__','ship_type_readable','db_fleet','design_state') | |
list_filter = ['db_ship_typeclass','db_date_commissioned','db_fleet','db_design_status'] | |
search_fields = ['db_class_name','db_ship_typeclass',] | |
form = WarshipClassAdminForm | |
actions = ['mark_as_ready'] | |
admin.site.register(WarshipClass, WarshipClassAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.apps import AppConfig | |
class NavalManagerConfig(AppConfig): | |
name = 'web.naval_manager' | |
verbose_name = 'Navy Manager' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.forms import ModelForm | |
from .models import WarshipClass | |
from evennia.objects.models import ObjectDB | |
class WarshipClassAdminForm(ModelForm): | |
class Meta: | |
model = WarshipClass | |
fields = ['db_class_name','db_ship_typeclass'] | |
class WarshipClassCreationForm(ModelForm): | |
class Meta: | |
model = WarshipClass | |
fields = ['db_class_name','db_ship_typeclass','db_fleet'] | |
def __init__(self, *args, **kwargs): | |
user = kwargs.pop('user') | |
super(ModelForm,self).__init__(*args, **kwargs) | |
self.fields['db_fleet'].queryset = ObjectDB.objects.filter(db_account=user) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from evennia.utils.idmapper.models import SharedMemoryModel | |
from django.conf import settings | |
from django.utils.translation import gettext as _ | |
from evennia.objects.models import ObjectDB | |
# helpers | |
# Create your models here. | |
class WarshipClass(SharedMemoryModel): | |
""" | |
Stores a blueprint of a warship design, or ship class. | |
Related to :model:`objects.ObjectDB` and :model:`typeclasses.Fleet`. | |
""" | |
db_class_name = models.CharField(_("Warship Class Name"),max_length=120, db_index=True, help_text=_("Name of the warship design")) | |
db_ship_typeclass = models.CharField(_("Ship Type"), max_length=255, | |
choices=settings.AVAILABLE_SHIP_TYPES, help_text=_("Enter the type of warship that is used for this class.")) | |
db_date_commissioned = models.DateTimeField(_("Date Commissioned"), auto_now=True) | |
db_fleet = models.ForeignKey(ObjectDB, on_delete=models.CASCADE, limit_choices_to={ | |
'db_typeclass_path': 'typeclasses.characters.Fleet' | |
},verbose_name=_("Fleet")) | |
db_design_status = models.CharField(_("Class Status"), max_length=2, choices=( | |
("PR", "Prototype"), | |
("RA", "Readily Available"), | |
("UM", "Under Maintenance"), | |
("OB", "Obsolete") | |
), default="PR") | |
class Meta: | |
verbose_name = _("Ship Class") | |
verbose_name_plural = _("Ship Classes") | |
unique_together = ('db_class_name','db_ship_typeclass') | |
def __str__(self): | |
return "%s-class %s " % (self.db_class_name, self.get_db_ship_typeclass_display()) | |
def full_class_name(self): | |
return "%s-class %s " % (self.db_class_name, self.get_db_ship_typeclass_display()) | |
def ship_type_readable(self): | |
return self.get_db_ship_typeclass_display() | |
ship_type_readable.admin_order_field = 'db_ship_typeclass' | |
ship_type_readable.short_description = "Ship Type" | |
def design_state(self): | |
return self.get_db_design_status_display() | |
design_state.admin_order_field = 'db_design_status' | |
design_state.short_description = "Ship Design Status" | |
def get_absolute_url(self): | |
return reverse("WarshipClass_detail", kwargs={"pk": self.pk}) | |
@staticmethod | |
def autocomplete_search_fields(self): | |
return 'db_class_name','db_ship_typeclass' | |
class ArmamentConfig(models.Model): | |
class Meta: | |
verbose_name = _("Armament Type") | |
verbose_name_plural = _("Armament Types") | |
def __str__(self): | |
return self.name | |
def get_absolute_url(self): | |
return reverse("ArmamentConfig_detail", kwargs={"pk": self.pk}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="{{ submission_path }}" method="post"> | |
{% csrf_token %} | |
{{ naval_interface }} | |
<input type="submit" value='{{ action_text }}'> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import url | |
from web.naval_manager import views | |
urlpatterns = [ | |
url(r'^ship-classes/$', views.WarshipClassView.view_scope(scope="index"), name="naval_manager-ship_classes"), | |
url(r'^ship-classes/create/$', views.WarshipClassView.view_scope(scope="create"), name="naval_manager-ship_classes-create") | |
] | |
app_name = 'naval_manager' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from .forms import WarshipClassCreationForm | |
# Create your views here. | |
class NavalView(object): | |
""" | |
Class for grouping Naval Manager views. | |
""" | |
@staticmethod | |
def view_scope(scope='index'): | |
raise NotImplementedError | |
class WarshipClassView(NavalView): | |
@staticmethod | |
def view_scope(scope='index'): | |
def index(request): | |
return render(request, 'naval_manager/index.html') | |
def create(request): | |
creation_form = WarshipClassCreationForm(request.POST, user=request.user) | |
if creation_form.is_valid(): | |
creation_form.save() | |
return render(request, "naval_manager/create.html", context={'form':creation_form}) | |
if scope == "index": | |
return index | |
elif scope == "create": | |
return create | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% load navy_utils %} | |
{% block content %} | |
<h1>Create Your Ship Class</h1> | |
{% naval_object_maker form "/create/" "Create and Save" %} | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "base.html" %} | |
{% block content %} | |
<h1> My Ship Classes</h1> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment