# Path: easymode/admin/models/fields.py
# class SafeTextField(models.TextField):
#     """
#     Removes all cariage returns from the input.
# 
#     This class should be used instead of :class:`django.db.models.TextField`, if you
#     want to use easymode's gettext facilities. It will strip all cariage returns from
#     the input. Cariage returns are an error when included in gettext message id's. It
#     also allows you to specify the number of rows and columns of the textarea.
#     
#     :param rows: The number of rows of the textarea.
#     :param cols: The number of columns of the textarea.
#     """
# 
#     _south_introspects = True
#     
#     def __init__(self, *args, **kwargs):
#         self.rows = kwargs.pop('rows', 5)
#         self.cols = kwargs.pop('cols', 40)
#         
#         super(SafeTextField, self).__init__(*args, **kwargs)
# 
#     def formfield(self, **kwargs):
#         defaults = {
#             'widget': AdminTextareaWidget(attrs={'rows':self.rows, 'cols':self.cols}),
#             'form_class': form_fields.PoSafeTextField
#         }
#         defaults.update(kwargs)
#         return super(SafeTextField, self).formfield(**defaults)
# 
# class SafeHTMLField(TextField):
#     """
#     A html field with the following properties:
# 
#     1. Escapes cariage returns
#     2. Will render as html, without escaping &lt; and &gt;
#     3. Validates that html and will log errors when invalid html 
#        is discovered, instead of crash.
#     4. Allows the max_length attribute, the max_length is then computed,
#        without counting markup. Also html entities are converted to normal
#        characters before measuring the length as well.
#     5. accepts tinymce configuration options.
# 
#     usage::
# 
#         html = SafeHTMLField(_('some rich text'), max_length=200, width=300, height=100, buttons="link,unlink,code")
# 
#     :param max_length: The maximum length of the text, after stripping markup and
#         converting html entities to normal characters.
#     :param width: The width of the html editor in the admin
#     :param height: The height of the html editor in the admin
#     :param buttons: Configuration for the 
#         `theme_advanced_buttons1 <http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/theme_advanced_buttons_1_n>`_. 
#         The default is "bullist,numlist,|,undo,redo,|,link,unlink,|,code,|,cleanup,removeformat".
#     """
#     _south_introspects = True
# 
#     def __init__(self, *args, **kwargs):
#         mce_config = DEFAULT_MCE_CONFIG or \
#             "bullist,numlist,|,undo,redo,|,link,unlink,|,code,|,cleanup,removeformat"
#         
#         self.mce_width = kwargs.pop('width', 340)
#         self.mce_height = kwargs.pop('height', 160)
#         self.buttons = kwargs.pop('buttons', mce_config)
#         
#         super(SafeHTMLField, self).__init__(*args, **kwargs)
# 
#     def __serialize__(self, obj, xml):
#         richtext = self.value_to_string(obj)
#         value = u"<richtext>%s</richtext>"  % richtext
# 
#         if xmlutils.is_valid(value):
#             parser = sax.make_parser(["easymode.utils.xmlutils"])
#             parser.setContentHandler(xml)
#             parser.parse(StringIO(value.encode('utf-8')))            
#         else:
#             logging.error('Invalid xml in %s: %s' % (obj, value))
# 
#     def formfield(self, **kwargs):
#         mce_default_attrs = {
#             'theme_advanced_buttons1' : self.buttons,
#             'theme_advanced_resizing' : True,
#             'width': self.mce_width,
#             'height': self. mce_height,
#         }
# 
#         defaults = {
#             'form_class': form_fields.PoSafeTextField,
#         }
# 
#         # if this thing has a max_length then use a 
#         # special form field
#         if hasattr(self, 'max_length'):
#             defaults['form_class'] = form_fields.HtmlEntityField
#             defaults['max_length'] = self.max_length
# 
#         defaults.update(kwargs)
#         defaults['widget'] = TinyMCE(mce_attrs=mce_default_attrs)
#         
#         return super(SafeHTMLField, self).formfield(**defaults)


from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from easymode.admin.models.fields import SafeTextField, SafeHTMLField
from easymode.i18n.decorators import I18n
from easymode.tree.xml.decorators import toxml


@I18n('a', 'b')
class ManagerErrorModel(models.Model):
    "used in easymode.tests.testcases.testintrospection.TestIntrospection"
    a = models.CharField(max_length=255)
    b = models.ImageField(upload_to='uploads')
    c = models.TextField()

    def __unicode__(self):
        return u"%s %s %s %s" % (self.pk, self.a, self.b, self.c)

@I18n('number', 'another')
class FormTestModel(models.Model):
    "Used in test_form_is_overridden (easymode.tests.testcases.testforms.TestL10nForm"
    number = models.IntegerField()
    other = models.CharField(max_length=255)
    another = models.CharField(max_length=255)


class TopModel(models.Model):
    title = models.CharField('The title', max_length=255)
    subtitle = SafeTextField('The subtitle')
    
    def __unicode__(self):
        return self.title
    
class BottomModel(models.Model):
    top = models.ForeignKey(TopModel)
    

# Path: easymode/admin/models/fields.py
# class SafeTextField(models.TextField):
#     """
#     Removes all cariage returns from the input.
# 
#     This class should be used instead of :class:`django.db.models.TextField`, if you
#     want to use easymode's gettext facilities. It will strip all cariage returns from
#     the input. Cariage returns are an error when included in gettext message id's. It
#     also allows you to specify the number of rows and columns of the textarea.
#     
#     :param rows: The number of rows of the textarea.
#     :param cols: The number of columns of the textarea.
#     """
# 
#     _south_introspects = True
#     
#     def __init__(self, *args, **kwargs):
#         self.rows = kwargs.pop('rows', 5)
#         self.cols = kwargs.pop('cols', 40)
#         
#         super(SafeTextField, self).__init__(*args, **kwargs)
# 
#     def formfield(self, **kwargs):
#         defaults = {
#             'widget': AdminTextareaWidget(attrs={'rows':self.rows, 'cols':self.cols}),
#             'form_class': form_fields.PoSafeTextField
#         }
#         defaults.update(kwargs)
#         return super(SafeTextField, self).formfield(**defaults)
# 
# class SafeHTMLField(TextField):
#     """
#     A html field with the following properties:
# 
#     1. Escapes cariage returns
#     2. Will render as html, without escaping &lt; and &gt;
#     3. Validates that html and will log errors when invalid html 
#        is discovered, instead of crash.
#     4. Allows the max_length attribute, the max_length is then computed,
#        without counting markup. Also html entities are converted to normal
#        characters before measuring the length as well.
#     5. accepts tinymce configuration options.
# 
#     usage::
# 
#         html = SafeHTMLField(_('some rich text'), max_length=200, width=300, height=100, buttons="link,unlink,code")
# 
#     :param max_length: The maximum length of the text, after stripping markup and
#         converting html entities to normal characters.
#     :param width: The width of the html editor in the admin
#     :param height: The height of the html editor in the admin
#     :param buttons: Configuration for the 
#         `theme_advanced_buttons1 <http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/theme_advanced_buttons_1_n>`_. 
#         The default is "bullist,numlist,|,undo,redo,|,link,unlink,|,code,|,cleanup,removeformat".
#     """
#     _south_introspects = True
# 
#     def __init__(self, *args, **kwargs):
#         mce_config = DEFAULT_MCE_CONFIG or \
#             "bullist,numlist,|,undo,redo,|,link,unlink,|,code,|,cleanup,removeformat"
#         
#         self.mce_width = kwargs.pop('width', 340)
#         self.mce_height = kwargs.pop('height', 160)
#         self.buttons = kwargs.pop('buttons', mce_config)
#         
#         super(SafeHTMLField, self).__init__(*args, **kwargs)
# 
#     def __serialize__(self, obj, xml):
#         richtext = self.value_to_string(obj)
#         value = u"<richtext>%s</richtext>"  % richtext
# 
#         if xmlutils.is_valid(value):
#             parser = sax.make_parser(["easymode.utils.xmlutils"])
#             parser.setContentHandler(xml)
#             parser.parse(StringIO(value.encode('utf-8')))            
#         else:
#             logging.error('Invalid xml in %s: %s' % (obj, value))
# 
#     def formfield(self, **kwargs):
#         mce_default_attrs = {
#             'theme_advanced_buttons1' : self.buttons,
#             'theme_advanced_resizing' : True,
#             'width': self.mce_width,
#             'height': self. mce_height,
#         }
# 
#         defaults = {
#             'form_class': form_fields.PoSafeTextField,
#         }
# 
#         # if this thing has a max_length then use a 
#         # special form field
#         if hasattr(self, 'max_length'):
#             defaults['form_class'] = form_fields.HtmlEntityField
#             defaults['max_length'] = self.max_length
# 
#         defaults.update(kwargs)
#         defaults['widget'] = TinyMCE(mce_attrs=mce_default_attrs)
#         
#         return super(SafeHTMLField, self).formfield(**defaults)


# Path: easymode/tests/models.py
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from easymode.admin.models.fields import SafeTextField, SafeHTMLField
from easymode.i18n.decorators import I18n
from easymode.tree.xml.decorators import toxml



@I18n('a', 'b')
class ManagerErrorModel(models.Model):
    "used in easymode.tests.testcases.testintrospection.TestIntrospection"
    a = models.CharField(max_length=255)
    b = models.ImageField(upload_to='uploads')
    c = models.TextField()

    def __unicode__(self):
        return u"%s %s %s %s" % (self.pk, self.a, self.b, self.c)

@I18n('number', 'another')
class FormTestModel(models.Model):
    "Used in test_form_is_overridden (easymode.tests.testcases.testforms.TestL10nForm"
    number = models.IntegerField()
    other = models.CharField(max_length=255)
    another = models.CharField(max_length=255)


class TopModel(models.Model):
    title = models.CharField('The title', max_length=255)
    subtitle = SafeTextField('The subtitle')
    
    def __unicode__(self):
        return self.title
    
class BottomModel(models.Model):
    top = models.ForeignKey(TopModel)
    

    comment = SafeTextField('Some comment')