justquick / django-activity-stream

Generate generic activity streams from the actions on your site. Users can follow any actors' activities for personalized streams.
http://django-activity-stream.rtfd.io/en/latest/
BSD 3-Clause "New" or "Revised" License
2.38k stars 482 forks source link

name 'request' is not defined #425

Closed maciejurm closed 5 years ago

maciejurm commented 5 years ago

Hi, I try to add request.user like documentation said: action.send(request.user, verb='joined', target=group)

But when I add request.user to signal and try to save object error appear: "name 'request' is not defined". User model in app.py is registered.

My model and signal: `class Subject(models.Model): title = models.CharField(max_length=255) embed = models.URLField(max_length=255, blank=True, null=True) slug = AutoSlugField(populate_from='title', unique=True) body = models.TextField() image = models.ImageField(upload_to='subject') author = models.ForeignKey(User, on_delete=models.CASCADE) active = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now_add=True) board = models.ForeignKey(Board, on_delete=models.CASCADE, related_name='subjects')

class Meta:
    verbose_name = 'Post'

def get_absolute_url(self):
    return reverse('subject_detail',
                   args=[self.slug])

def my_handler(sender, instance, created, **kwargs): action.send(request.user, instance, verb='dodał post')

post_save.connect(my_handler, sender=Subject)`

cb109 commented 5 years ago

This is not related to actstream at all. Your method my_handler() does not know what request is, and how should it, there simply is no request in that context. You are doing this wrong. A request and its associated User is part of the view layer, not the model, you must add your signal handler there.