Skip to content

pre_delete signal problem #96

Closed
kouroshshafi opened this Issue Jun 10, 2012 · 6 comments

2 participants

@kouroshshafi

I have the following code added to get rid of the actions whose action_target_content_object is removed. I don't know why it raises
ModelNotActionable. If I just remove this piece of code, everything works smoothly!? Anyhelp would be appreciated.

This code is in my main.models that contains Post (as its Model). I have also a post_save signal that creates the right Action object.

@receiver(pre_delete, sender=Post)
def pre_delete_handler(sender, instance, **kwargs):

    try :
        ac = get_object_or_404(Action, verb = _('posted'), action_object_content_type = ContentType.objects.get_for_model(sender), action_object_object_id = instance.id)
        ac.delete()
    except:
        pass

@kouroshshafi

First of all, even if I remove this issue

Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: 'Action' object is not callable

by using simply

h = Action.objects.get(verb= _('posted'), action_object_content_type = ContentType.objects.get_for_model(sender), action_object_object_id = instance.id)

sender being Post and instance is an instance of Post. btw That's how I create my action instance in the same place as I write the above code (main.models). main is my app name.

@receiver(post_save, sender=Post)
def my_handler(sender,instance, **kwargs):
    if instance.author:
            action.send(instance.author, verb=_('posted'), action_object=instance)

I still get the same error that my "post" is not actionable model; I am sure I have added it to my actionable models already.

@kouroshshafi

How can I check whether that part of code related to defining ModelActionable is imported sooner than when I want to delete my posts. I have no idea if I am in the right direction. But it would be nice to have some sort of signal to cleanup after the referenced Foreignkeys are deleted. this would be a request for a new feature.

@kouroshshafi

Well, the situation has got worse and even cannot get nothing to work. I don't know why. when I run in bash the following commands, it is really strange.

#settings.py
ACTSTREAM_ACTION_MODELS =  ['auth.user', 'auth.group', 'sites.site', 'comments.comment', 'main.Post',]
ACTSTREAM_MANAGER = 'actstream.managers.ActionManager'
# main/models.py
class Post(models.Model):


    author = models.ForeignKey(User, related_name="note")
    body = models.TextField(_('item_body'), null=False, blank=False)
    created = models.DateTimeField( _('created_at'), auto_now_add=True)




    class Meta:
        verbose_name        = _('postitem')
        ordering = ['-created']
        get_latest_by       = 'created'

Now strangely in my bash:

from actstream.settings import MODELS
MODELS.values()

for the models.Post I get None and for the rest of models it is ok!!!!? some help please

@kouroshshafi

OK. I got it working. the source of problem is when It import MODELS into exceptions.py, strangely it cannot fetch my Post model. well, the workaround is to have the MODELS creation in the definition of check_actionable_model in exceptions.py :) now everything works as expected. I lost a lot of time for some reason that I don't even understand.

def check_actionable_model(model):
    """
    If the model is not defined in the ``MODELS`` setting this check raises the
    ``ModelNotActionable`` exception.
    """
    #from actstream.settings import MODELS
    from django.conf import settings
    from django.db.models import get_model  
    MODELS = {}
    for model in getattr(settings, 'ACTSTREAM_ACTION_MODELS', ('auth.User',)):
        MODELS[model.lower()] = model = get_model(*model.split('.'))


    model = model if hasattr(model, 'objects') else model.__class__
    if not model in MODELS.values():
        raise ModelNotActionable(model)
@justquick
Owner

i think putting ur main app after actstream in INSTALLED_APPS would have fixed this problem as well

@kouroshshafi

No, that doesn't help :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.