Skip to content

Commit

Permalink
4 - A Custom Signal
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforentrepreneurs committed Oct 10, 2017
1 parent 007dd51 commit 540a9e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/analytics/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.dispatch import Signal


object_viewed_signal = Signal(providing_args=['instance', 'request'])
4 changes: 4 additions & 0 deletions src/products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.views.generic import ListView, DetailView
from django.shortcuts import render, get_object_or_404

from analytics.signals import object_viewed_signal
from carts.models import Cart

from .models import Product
Expand Down Expand Up @@ -67,6 +68,7 @@ def get_context_data(self, *args, **kwargs):
def get_object(self, *args, **kwargs):
request = self.request
slug = self.kwargs.get('slug')

#instance = get_object_or_404(Product, slug=slug, active=True)
try:
instance = Product.objects.get(slug=slug, active=True)
Expand All @@ -77,6 +79,8 @@ def get_object(self, *args, **kwargs):
instance = qs.first()
except:
raise Http404("Uhhmmm ")

# object_viewed_signal.send(instance.__class__, instance=instance, request=request)
return instance


Expand Down

0 comments on commit 540a9e1

Please sign in to comment.