def add_presentation_media(self, *presentation_media): """ Adds one or more PresentationMedia to the instance's collection. This adopts the donor's PresentationMedia first and then adds. The presentation_media can be subclassed (e.g. Layer or Result) or the base class PresentationMedium instances :return: The computed results after adding the given items """ logger.debug( "For Presentation %s (%s) with presentation_media '%s' donor %s (%s) presentation_media: %s, adding presentation_media: %s" % ( self.name, self.id, ', '.join( map_property(self.computed_presentation_media(), 'db_entity_key')), self.donor().name if self.donor() else "No Donor", self.donor().id if self.donor() else '', ', '.join( map_property(self.donor().computed_presentation_media(), 'db_entity_key')) if self.donor() else '', ', '.join(map_property(presentation_media, 'db_entity_key')), )) self._add(self.presentation_media_alias, *presentation_media) logger.debug( "Presentation %s (%s) now has its own presentation_media: %s" % ( self.name, self.id, ', '.join( map_property(self.presentation_media.all(), 'db_entity_key')), ))
def on_post_save_built_form_tilestache(sender, **kwargs): """ A signal handler to invalidate relevant layers of the tilestache cache after a BuiltForm instances is created or updated. """ # Find all DbEntities that reference built_form. # TODO these should inspect the feature class in the future for the built_form attribute or similar built_forms = kwargs['instance'] logger.info("Processing TileStache updates for built forms: {0}".format( ', '.join(map_property(built_forms, 'name')))) # if we are just editing the attributes of primary components (which are never visualized) skip the time consuming # layer invalidation and tilestache recreation. built_form_class_name = built_forms[0].__class__.__name__ if built_form_class_name in ['Building', 'Crop', 'PrimaryComponent']: return if built_form_class_name in ['CropType', 'LandscapeType']: built_form_dependent_db_entity_keys = [ DbEntityKey.FUTURE_AGRICULTURE, DbEntityKey.BASE_AGRICULTURE ] else: built_form_dependent_db_entity_keys = [ DbEntityKey.END_STATE, DbEntityKey.BASE_CANVAS ] for layer_library in LayerLibrary.objects.filter(deleted=False): _on_post_save_tilestache( layer_library.config_entity, db_entity_keys=built_form_dependent_db_entity_keys)
def on_post_save_built_form_tilestache(sender, **kwargs): """ A signal handler to invalidate relevant layers of the tilestache cache after a BuiltForm instances is created or updated. """ # Find all DbEntities that reference built_form. # TODO these should inspect the feature class in the future for the built_form attribute or similar built_forms = kwargs['instance'] logger.info("Processing TileStache updates for built forms: {0}".format( ', '.join(map_property(built_forms, 'name')) )) # if we are just editing the attributes of primary components (which are never visualized) skip the time consuming # layer invalidation and tilestache recreation. built_form_class_name = built_forms[0].__class__.__name__ if built_form_class_name in ['Building', 'Crop', 'PrimaryComponent']: return if built_form_class_name in ['CropType', 'LandscapeType']: built_form_dependent_db_entity_keys = [DbEntityKey.FUTURE_AGRICULTURE, DbEntityKey.BASE_AGRICULTURE] else: built_form_dependent_db_entity_keys = [DbEntityKey.END_STATE, DbEntityKey.BASE_CANVAS] for layer_library in LayerLibrary.objects.filter(deleted=False): _on_post_save_tilestache(layer_library.config_entity, db_entity_keys=built_form_dependent_db_entity_keys)
def add_presentation_media(self, *presentation_media): """ Adds one or more PresentationMedia to the instance's collection. This adopts the donor's PresentationMedia first and then adds. The presentation_media can be subclassed (e.g. Layer or Result) or the base class PresentationMedium instances :return: The computed results after adding the given items """ logger.debug("For Presentation %s (%s) with presentation_media '%s' donor %s (%s) presentation_media: %s, adding presentation_media: %s" % ( self.name, self.id, ', '.join(map_property(self.computed_presentation_media(), 'db_entity_key')), self.donor().name if self.donor() else "No Donor", self.donor().id if self.donor() else '', ', '.join(map_property(self.donor().computed_presentation_media(), 'db_entity_key')) if self.donor() else '', ', '.join(map_property(presentation_media, 'db_entity_key')), )) self._add(self.presentation_media_alias, *presentation_media) logger.debug("Presentation %s (%s) now has its own presentation_media: %s" % ( self.name, self.id, ', '.join(map_property(self.presentation_media.all(), 'db_entity_key')), ))
def _on_built_form_post_save(built_forms): logger.info("Handler: post_save_built_form for {built_forms}".format( built_forms=', '.join(map_property(built_forms, 'name'))) ) user = built_forms[0].updater starting_signal_path = resolvable_module_attr_path(__name__, 'post_save_built_form_initial') return post_save_publishing( starting_signal_path, None, user, instance=built_forms, signal_proportion_lookup=signal_proportion_lookup, dependent_signal_paths=dependent_signal_paths, signal_prefix='post_save_built_form')