Skip to content

Commit

Permalink
Another try. This should resolve the validation errors by having bad …
Browse files Browse the repository at this point in the history
…values for the forms just go to different default values.
  • Loading branch information
TehomCD authored and Griatch committed Nov 22, 2016
1 parent ab6b768 commit 1e22b89
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions evennia/typeclasses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class AttributeForm(forms.ModelForm):
the creation, change, or deletion of an Attribute for us, as well as updating the handler's cache so that all
changes are instantly updated in-game.
"""
attr_key = forms.CharField(label='Attribute Name')
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_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)
Expand Down Expand Up @@ -201,7 +201,7 @@ def save(self, commit=True):
"""
# we are spoofing an Attribute for the Handler that will be called
instance = self.instance
instance.attr_key = self.cleaned_data['attr_key']
instance.attr_key = self.cleaned_data['attr_key'] or "no_name_entered_for_attribute"
instance.attr_category = self.cleaned_data['attr_category'] or None
instance.attr_value = self.cleaned_data['attr_value'] or None
# convert the serialized string value into an object, if necessary, for AttributeHandler
Expand All @@ -216,12 +216,6 @@ class AttributeFormSet(forms.BaseInlineFormSet):
"""
Attribute version of TagFormSet, as above.
"""
def clean(self):
if any(self.errors):
from django.core.exceptions import FieldError
raise FieldError("Sorry, there was an error in saving that form. You may have forgotten to add a name "
"for the Attribute, or you may have provided an invalid literal for an Attribute's value.")
super(AttributeFormSet, self).clean()

def save(self, commit=True):
def get_handler(finished_object):
Expand Down
4 changes: 2 additions & 2 deletions evennia/utils/picklefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def render(self, name, value, attrs=None):
final_attrs = self.build_attrs(attrs, name=name)
return format_html('<textarea{0}>\r\n{1}</textarea>',
flatatt(final_attrs),
force_text(value))
value)


class PickledFormField(CharField):
Expand All @@ -154,7 +154,7 @@ def clean(self, value):
return literal_eval(value)
except (ValueError, SyntaxError):
try:
value = "u'%s'" % force_text(value)
value = repr(value)
return literal_eval(value)
except (ValueError, SyntaxError):
raise ValidationError(self.error_messages['invalid'])
Expand Down

0 comments on commit 1e22b89

Please sign in to comment.