def handle(self, *args, **options): from_text = options['from_text'] to_text = options['to_text'] for revision in PageRevision.objects.filter( content_json__contains=from_text): revision.content_json = revision.content_json.replace( from_text, to_text) revision.save(update_fields=['content_json']) for page_class in get_page_models(): self.stdout.write("scanning %s" % page_class._meta.verbose_name) child_relation_names = [ rel.get_accessor_name() for rel in get_all_child_relations(page_class) ] # Find all pages of this exact type; exclude subclasses, as they will # appear in the get_page_models() list in their own right, and this # ensures that replacement happens only once for page in page_class.objects.exact_type(page_class): replace_in_model(page, from_text, to_text) for child_rel in child_relation_names: for child in getattr(page, child_rel).all(): replace_in_model(child, from_text, to_text)
def get_form_types(): global _FORM_CONTENT_TYPES if _FORM_CONTENT_TYPES is None: form_models = [ model for model in get_page_models() if issubclass(model, AbstractForm) ] _FORM_CONTENT_TYPES = list( ContentType.objects.get_for_models(*form_models).values()) return _FORM_CONTENT_TYPES
def unregister_signal_handlers(): Image = get_image_model() Document = get_document_model() for model in get_page_models(): page_published.disconnect(purge_page_from_cache, sender=model) page_unpublished.disconnect(purge_page_from_cache, sender=model) post_save.disconnect(purge_image_from_cache, sender=Image) post_delete.disconnect(purge_image_from_cache, sender=Image) post_save.disconnect(purge_document_from_cache, sender=Document) post_delete.disconnect(purge_document_from_cache, sender=Document)
def _clear_edit_handler_cache(self): """ These tests generate new EditHandlers with different settings. The cached edit handlers should be cleared before and after each test run to ensure that no changes leak through to other tests. """ from tuiuiu.tests.testapp.models import DefaultRichBlockFieldPage block_page_edit_handler = DefaultRichBlockFieldPage.get_edit_handler() if block_page_edit_handler._form_class: rich_text_block = block_page_edit_handler._form_class.base_fields[ 'body'].block.child_blocks['rich_text'] if hasattr(rich_text_block, 'field'): del rich_text_block.field for page_class in get_page_models(): page_class.get_edit_handler.cache_clear()
def base_form_class_check(app_configs, **kwargs): from tuiuiu.tuiuiuadmin.forms import TuiuiuAdminPageForm from tuiuiu.tuiuiucore.models import get_page_models errors = [] for cls in get_page_models(): if not issubclass(cls.base_form_class, TuiuiuAdminPageForm): errors.append( Error("{}.base_form_class does not extend TuiuiuAdminPageForm". format(cls.__name__), hint="Ensure that {}.{} extends TuiuiuAdminPageForm". format(cls.base_form_class.__module__, cls.base_form_class.__name__), obj=cls, id='tuiuiuadmin.E001')) return errors
def get_form_class_check(app_configs, **kwargs): from tuiuiu.tuiuiuadmin.forms import TuiuiuAdminPageForm from tuiuiu.tuiuiucore.models import get_page_models errors = [] for cls in get_page_models(): edit_handler = cls.get_edit_handler() if not issubclass(edit_handler.get_form_class(cls), TuiuiuAdminPageForm): errors.append( Error( "{cls}.get_edit_handler().get_form_class({cls}) does not extend TuiuiuAdminPageForm" .format(cls=cls.__name__), hint= "Ensure that the EditHandler for {cls} creates a subclass of TuiuiuAdminPageForm" .format(cls=cls.__name__), obj=cls, id='tuiuiuadmin.E002')) return errors