Cleanup and more help entries for the Admin Attr/Tag inline forms
This commit is contained in:
parent
2c88963e3c
commit
8eff4678b4
1 changed files with 44 additions and 19 deletions
|
|
@ -18,17 +18,28 @@ class TagAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
class TagForm(forms.ModelForm):
|
class TagForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
This form overrides the base behavior of the ModelForm that would be used for a Tag-through-model.
|
This form overrides the base behavior of the ModelForm that would be used for a
|
||||||
Since the through-models only have access to the foreignkeys of the Tag and the Object that they're
|
Tag-through-model. Since the through-models only have access to the foreignkeys of the Tag and
|
||||||
attached to, we need to spoof the behavior of it being a form that would correspond to its tag,
|
the Object that they're attached to, we need to spoof the behavior of it being a form that would
|
||||||
or the creation of a tag. Instead of being saved, we'll call to the Object's handler, which will handle
|
correspond to its tag, or the creation of a tag. Instead of being saved, we'll call to the
|
||||||
the creation, change, or deletion of a tag for us, as well as updating the handler's cache so that all
|
Object's handler, which will handle the creation, change, or deletion of a tag for us, as well
|
||||||
changes are instantly updated in-game.
|
as updating the handler's cache so that all changes are instantly updated in-game.
|
||||||
"""
|
"""
|
||||||
tag_key = forms.CharField(label='Tag Name')
|
tag_key = forms.CharField(label='Tag Name',
|
||||||
tag_category = forms.CharField(label="Category", required=False)
|
required=True,
|
||||||
tag_type = forms.CharField(label="Type", required=False)
|
help_text="This is the main key identifier")
|
||||||
tag_data = forms.CharField(label="Data", required=False)
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
@ -121,8 +132,8 @@ class TagInline(admin.TabularInline):
|
||||||
form = TagForm
|
form = TagForm
|
||||||
formset = TagFormSet
|
formset = TagFormSet
|
||||||
related_field = None # Must be 'objectdb', 'accountdb', 'msg', etc. Set when subclassing
|
related_field = None # Must be 'objectdb', 'accountdb', 'msg', etc. Set when subclassing
|
||||||
raw_id_fields = ('tag',)
|
# raw_id_fields = ('tag',)
|
||||||
readonly_fields = ('tag',)
|
# readonly_fields = ('tag',)
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
def get_formset(self, request, obj=None, **kwargs):
|
def get_formset(self, request, obj=None, **kwargs):
|
||||||
|
|
@ -150,13 +161,26 @@ class AttributeForm(forms.ModelForm):
|
||||||
changes are instantly updated in-game.
|
changes are instantly updated in-game.
|
||||||
"""
|
"""
|
||||||
attr_key = forms.CharField(label='Attribute Name', required=False, initial="Enter Attribute Name Here")
|
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_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",
|
attr_strvalue = forms.CharField(label="String Value",
|
||||||
help_text="Only enter this if value is blank and you want to save as a string",
|
help_text="Only set when using the Attribute as a string-only store",
|
||||||
required=False)
|
required=False,
|
||||||
attr_lockstring = forms.CharField(label="Locks", required=False, widget=forms.Textarea)
|
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):
|
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,
|
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
|
and attr_lockstring all refer to the corresponding Attribute fields. The initial data of the form fields will
|
||||||
similarly be populated.
|
similarly be populated.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super(AttributeForm, self).__init__(*args, **kwargs)
|
super(AttributeForm, self).__init__(*args, **kwargs)
|
||||||
attr_key = None
|
attr_key = None
|
||||||
|
|
@ -261,8 +286,8 @@ class AttributeInline(admin.TabularInline):
|
||||||
form = AttributeForm
|
form = AttributeForm
|
||||||
formset = AttributeFormSet
|
formset = AttributeFormSet
|
||||||
related_field = None # Must be 'objectdb', 'accountdb', 'msg', etc. Set when subclassing
|
related_field = None # Must be 'objectdb', 'accountdb', 'msg', etc. Set when subclassing
|
||||||
raw_id_fields = ('attribute',)
|
# raw_id_fields = ('attribute',)
|
||||||
readonly_fields = ('attribute',)
|
# readonly_fields = ('attribute',)
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
def get_formset(self, request, obj=None, **kwargs):
|
def get_formset(self, request, obj=None, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue