Matthew Schinckel  committed 835a4cc

Remove any \\r characters in the string, as they will be invalid when compiling.

  • Participants
  • Parent commits 4af02da
  • Branches default

Comments (0)

Files changed (1)

File python_field/

 from django.db import models
 from django import forms
-class PythonCodeWidget(forms.TextArea):
+class PythonCodeWidget(forms.Textarea):
     def render(self, name, value, attrs=None):
         TODO: have a syntax hilight feature, where instead of a TextArea,
             value = json.dumps(value, indent=4)
         return super(PythonCodeWidget, self).render(name, value, attrs=attrs)
-def PythonCodeFormField(forms.CharField):
+class PythonCodeFormField(forms.CharField):
     def __init__(self, *args, **kwargs):
         kwargs['widget'] = PythonCodeWidget
         super(PythonCodeFormField, self).__init__(*args, **kwargs)
         if isinstance(value, basestring):
+                value = value.replace('\r', '')
                 compile(value, "<string>", 'exec')
             except SyntaxError, arg:
                 raise forms.ValidationError(u'Syntax Error: %s' % unicode(arg))
             return value
-def PythonCodeField(models.TextField):
+class PythonCodeField(models.TextField):
     A field that will ensure that data that is entered into it is syntactically
     valid python code.