Permalink
Browse files

Add ability to record links to specific object on response

  • Loading branch information...
1 parent 4bdd632 commit d6fdde0b5f5a9419b057765d39ba2a9a257c3910 @paltman paltman committed Nov 20, 2012
Showing with 21 additions and 4 deletions.
  1. +12 −4 anafero/models.py
  2. +9 −0 docs/usage.rst
View
@@ -76,10 +76,10 @@ def create(cls, redirect_to, user=None, label="", target=None):
return obj
@classmethod
- def record_response(cls, request, action_string):
+ def record_response(cls, request, action_string, target=None):
referral = cls.referral_for_request(request)
if referral:
- return referral.respond(request, action_string)
+ return referral.respond(request, action_string, target=target)
@classmethod
def referral_for_request(cls, request):
@@ -93,7 +93,7 @@ def referral_for_request(cls, request):
except IndexError:
pass
- def respond(self, request, action_string, user=None):
+ def respond(self, request, action_string, user=None, target=None):
if user is None:
if request.user.is_authenticated():
user = request.user
@@ -110,7 +110,8 @@ def respond(self, request, action_string, user=None):
session_key=request.session.session_key,
ip_address=ip_address,
action=action_string,
- user=user
+ user=user,
+ target=target
)
def filtered_responses(self):
@@ -127,4 +128,11 @@ class ReferralResponse(models.Model):
ip_address = models.CharField(max_length=45)
action = models.CharField(max_length=128)
+ target_content_type = models.ForeignKey(ContentType, null=True)
+ target_object_id = models.PositiveIntegerField(null=True)
+ target = generic.GenericForeignKey(
+ ct_field="target_content_type",
+ fk_field="target_object_id"
+ )
+
created_at = models.DateTimeField(default=timezone.now)
View
@@ -65,6 +65,15 @@ doesn't have any previously recorded referral responses. In addition, if the use
has responded to more than one Referral code, then this will associate the
activity with the most recent response.
+In addition, this supports passing an options ``target`` keyward argument, if
+you wanted to record associations with specific objects. For example::
+
+ Referral.record_response(request, "SOME_ACTION", target=some_object)
+
+This will record a generic foreign key to ``some_object`` that you can use elsewhere
+to identify activity from your referral at a deeper level than just based on
+the action label.
+
.. _Referral.referral_for_request:

0 comments on commit d6fdde0

Please sign in to comment.