artifacts = os.path.basename(self.artifacts.name) organizations = os.path.basename(self.organizations.name) uniArgs = (self.name, agents, artifacts, organizations) return '%s (%s, %s, %s)' % uniArgs def get_config_filepath(self): from django.core.files.storage import default_storage filename = get_config_filename(self) return default_storage.path(filename) file_post_saves = [] file_post_deletes = [] for field in ['agents', 'artifacts', 'organizations']: file_post_saves.append(create_callback_post_save(field)) file_post_deletes.append(create_callback_post_delete(field)) # TODO implement me def config_post_save(sender, instance, created, **kwargs): pass def config_post_delete(sender, instance, **kwargs): try: os.remove(instance.get_config_filepath()) except OSError, e: # TODO log me print e
agents = os.path.basename(self.agents.name) artifacts = os.path.basename(self.artifacts.name) organizations = os.path.basename(self.organizations.name) uniArgs = (self.name, agents, artifacts, organizations) return '%s (%s, %s, %s)' % uniArgs def get_config_filepath(self): from django.core.files.storage import default_storage filename = get_config_filename(self) return default_storage.path(filename) file_post_saves = [ ] file_post_deletes = [ ] for field in [ 'agents', 'artifacts', 'organizations' ]: file_post_saves.append(create_callback_post_save(field)) file_post_deletes.append(create_callback_post_delete(field)) # TODO implement me def config_post_save(sender, instance, created, **kwargs): pass def config_post_delete(sender, instance, **kwargs): try: os.remove(instance.get_config_filepath()) except OSError, e: # TODO log me print e for file_post_save in file_post_saves: models.signals.post_save.connect(file_post_save, sender=Solution)
file = models.FileField( upload_to=functools.partial(dir_upload_to, 'agents')) cardinality = models.IntegerField() class Artifact(BaseFileComponent): file = models.FileField( upload_to=functools.partial(dir_upload_to, 'artifacts')) class Organization(BaseFileComponent): file = models.FileField( upload_to=functools.partial(dir_upload_to, 'organizations')) file_post_save = create_callback_post_save('file') file_post_delete = create_callback_post_delete('file') def for_each_subclass(base, callback): if base._meta.abstract: children = base.__subclasses__() for child in children: for_each_subclass(child, callback) else: callback(base) def set_file_signals(sender): models.signals.post_save.connect(file_post_save, sender=sender) models.signals.post_delete.connect(file_post_delete, sender=sender)
class BaseFileComponent(BaseDefaultFileComponent): subenvironment = models.ForeignKey(SubEnvironment) class Meta: abstract = True class Agent(BaseFileComponent): file = models.FileField(upload_to=functools.partial(dir_upload_to, 'agents')) class Artifact(BaseFileComponent): file = models.FileField(upload_to=functools.partial(dir_upload_to, 'artifacts')) class Organization(BaseFileComponent): file = models.FileField(upload_to=functools.partial(dir_upload_to, 'organizations')) file_post_save = create_callback_post_save('file') file_post_delete = create_callback_post_delete('file') def for_each_subclass(base, callback): if base._meta.abstract: children = base.__subclasses__() for child in children: for_each_subclass(child, callback) else: callback(base) def set_file_signals(sender): models.signals.post_save.connect(file_post_save, sender=sender) models.signals.post_delete.connect(file_post_delete, sender=sender) for_each_subclass(BaseDefaultFileComponent, set_file_signals)