From: Joseph Spiros Date: Fri, 8 Jul 2011 22:13:18 +0000 (-0400) Subject: Merge branch 'embed-widget' of git://github.com/lapilofu/philo into develop X-Git-Tag: philo-0.9.1^2~4 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/6dc154ec98d58159b3e75447ce7b7fe5642acec4?ds=inline;hp=-c Merge branch 'embed-widget' of git://github.com/lapilofu/philo into develop * 'embed-widget' of git://github.com/lapilofu/philo: Updated the grappelli styles to override the default styles. Updated styles to work in the original admin. Updated the javascript to overload the dismissAddAnotherPopup function as well. Made the embed widget javascript work by overloading the dismissRelatedLookupPopup function. Made the embed widget automatically generate URLs based on the ADMIN_URL global, which is provided by Grappelli. Unfortunately, this introduces a dependency on Grappelli. I'll return to this branch at a later date when my thinking is clearer. Initial work on a widget for TemplateFields that allows javascript selection of an object to embed. --- 6dc154ec98d58159b3e75447ce7b7fe5642acec4 diff --combined philo/models/fields/__init__.py index 7ab4326,0003575..575b3a4 --- a/philo/models/fields/__init__.py +++ b/philo/models/fields/__init__.py @@@ -7,16 -7,21 +7,22 @@@ from django.utils.text import capfirs from django.utils.translation import ugettext_lazy as _ from philo.forms.fields import JSONFormField +from philo.utils.registry import RegistryIterator from philo.validators import TemplateValidator, json_validator + from philo.forms.widgets import EmbedWidget #from philo.models.fields.entities import * - class TemplateField(models.TextField): + class TemplateField(models.Field): """A :class:`TextField` which is validated with a :class:`.TemplateValidator`. ``allow``, ``disallow``, and ``secure`` will be passed into the validator's construction.""" def __init__(self, allow=None, disallow=None, secure=True, *args, **kwargs): super(TemplateField, self).__init__(*args, **kwargs) self.validators.append(TemplateValidator(allow, disallow, secure)) + + def formfield(self, **kwargs): + defaults = {'widget': EmbedWidget} + defaults.update(kwargs) + return super(TemplateField, self).formfield(**defaults) class JSONDescriptor(object): @@@ -72,7 -77,7 +78,7 @@@ class JSONField(models.TextField) class SlugMultipleChoiceField(models.Field): - """Stores a selection of multiple items with unique slugs in the form of a comma-separated list.""" + """Stores a selection of multiple items with unique slugs in the form of a comma-separated list. Also knows how to correctly handle :class:`RegistryIterator`\ s passed in as choices.""" __metaclass__ = models.SubfieldBase description = _("Comma-separated slug field") @@@ -128,16 -133,6 +134,16 @@@ if invalid_values: # should really make a custom message. raise ValidationError(self.error_messages['invalid_choice'] % invalid_values) + + def _get_choices(self): + if isinstance(self._choices, RegistryIterator): + return self._choices.copy() + elif hasattr(self._choices, 'next'): + choices, self._choices = itertools.tee(self._choices) + return choices + else: + return self._choices + choices = property(_get_choices) try: