Cleanup and more help entries for the Admin Attr/Tag inline forms

This commit is contained in:
Griatch 2017-10-05 21:29:05 +02:00
parent 2c88963e3c
commit 8eff4678b4

View file

@ -18,17 +18,28 @@ class TagAdmin(admin.ModelAdmin):
class TagForm(forms.ModelForm):
"""
This form overrides the base behavior of the ModelForm that would be used for a Tag-through-model.
Since the through-models only have access to the foreignkeys of the Tag and the Object that they're
attached to, we need to spoof the behavior of it being a form that would correspond to its tag,
or the creation of a tag. Instead of being saved, we'll call to the Object's handler, which will handle
the creation, change, or deletion of a tag for us, as well as updating the handler's cache so that all
changes are instantly updated in-game.
This form overrides the base behavior of the ModelForm that would be used for a
Tag-through-model. Since the through-models only have access to the foreignkeys of the Tag and
the Object that they're attached to, we need to spoof the behavior of it being a form that would
correspond to its tag, or the creation of a tag. Instead of being saved, we'll call to the
Object's handler, which will handle the creation, change, or deletion of a tag for us, as well
as updating the handler's cache so that all changes are instantly updated in-game.
"""
tag_key = forms.CharField(label='Tag Name')
tag_category = forms.CharField(label="Category", required=False)
tag_type = forms.CharField(label="Type", required=False)
tag_data = forms.CharField(label="Data", required=False)
tag_key = forms.CharField(label='Tag Name',
required=True,
help_text="This is the main key identifier")
tag_category = forms.CharField(label="Category",
help_text="Used for grouping tags. Unset (default) gives a category of None",
required=False)
tag_type = forms.CharField(label="Type",
help_text="Internal use. Either unset, \"alias\" or \"permission\"",
required=False)
tag_data = forms.CharField(label="Data",
help_text="Usually unused. Intended for eventual info about the tag itself",
required=False)
class Meta:
fields = ("tag_key", "tag_category", "tag_data", "tag_type")
def __init__(self, *args, **kwargs):
"""
@ -121,8 +132,8 @@ class TagInline(admin.TabularInline):
form = TagForm
formset = TagFormSet
related_field = None # Must be 'objectdb', 'accountdb', 'msg', etc. Set when subclassing
raw_id_fields = ('tag',)
readonly_fields = ('tag',)
# raw_id_fields = ('tag',)
# readonly_fields = ('tag',)
extra = 0
def get_formset(self, request, obj=None, **kwargs):
@ -150,13 +161,26 @@ class AttributeForm(forms.ModelForm):
changes are instantly updated in-game.
"""
attr_key = forms.CharField(label='Attribute Name', required=False, initial="Enter Attribute Name Here")
attr_category = forms.CharField(label="Category", help_text="type of attribute, for sorting", required=False)
attr_category = forms.CharField(label="Category",
help_text="type of attribute, for sorting",
required=False,
max_length=4)
attr_value = PickledFormField(label="Value", help_text="Value to pickle/save", required=False)
attr_type = forms.CharField(label="Type", help_text="nick for nickname, else leave blank", required=False)
attr_type = forms.CharField(label="Type",
help_text="Internal use. Either unset (normal Attribute) or \"nick\"",
required=False,
max_length=4)
attr_strvalue = forms.CharField(label="String Value",
help_text="Only enter this if value is blank and you want to save as a string",
required=False)
attr_lockstring = forms.CharField(label="Locks", required=False, widget=forms.Textarea)
help_text="Only set when using the Attribute as a string-only store",
required=False,
widget=forms.Textarea(attrs={"rows": 1, "cols": 6}))
attr_lockstring = forms.CharField(label="Locks",
required=False,
help_text="Lock string on the form locktype:lockdef;lockfunc:lockdef;...",
widget=forms.Textarea(attrs={"rows": 1, "cols": 8}))
class Meta:
fields = ("attr_key", "attr_value", "attr_category", "attr_strvalue", "attr_lockstring", "attr_type")
def __init__(self, *args, **kwargs):
"""
@ -164,6 +188,7 @@ class AttributeForm(forms.ModelForm):
to have based on the Attribute. attr_key, attr_category, attr_value, attr_strvalue, attr_type,
and attr_lockstring all refer to the corresponding Attribute fields. The initial data of the form fields will
similarly be populated.
"""
super(AttributeForm, self).__init__(*args, **kwargs)
attr_key = None
@ -261,8 +286,8 @@ class AttributeInline(admin.TabularInline):
form = AttributeForm
formset = AttributeFormSet
related_field = None # Must be 'objectdb', 'accountdb', 'msg', etc. Set when subclassing
raw_id_fields = ('attribute',)
readonly_fields = ('attribute',)
# raw_id_fields = ('attribute',)
# readonly_fields = ('attribute',)
extra = 0
def get_formset(self, request, obj=None, **kwargs):