def save(self, *args, **kwargs): super(FoundryComment, self).save(*args, **kwargs) from activity.models import UserActivity UserActivity.track_activity(user=self.user, activity=activity_constants.ACTIVITY_COMMENTED, sub=ugettext('<a href="%s">%s</a>' % (self.content_object.get_absolute_url(), self.comment)), content_object=self, image_object=self.user.member)
def like(request, content_type, id, vote): #content_type = content_type.replace("-", ".") app, modelname = content_type.split('-') object = ContentType.objects.get(app_label=app, model__iexact=modelname).model_class().objects.get(id=id) if can_vote(object, request.user, request): UserActivity.track_activity(user=request.user.member, activity=activity_constants.ACTIVITY_LIKED, sub=ugettext('<a href="%s">%s</a>' % (object.get_absolute_url(), object.comment if isinstance(object, FoundryComment) else object.title)), content_object=object, image_object=object) return likes_views.like(request, content_type, id, vote)
def get(self, request, *args, **kwargs): try: current_url = request.META['HTTP_REFERER'] if self.type == 'Facebook': url = 'http://www.facebook.com/sharer/sharer.php?u=%s' % urllib.quote(current_url) elif self.type == 'Twitter': url = 'https://twitter.com/intent/tweet?original_referer=%s' % urllib.quote(current_url) else: return Http404('Unknown share type.') UserActivity.track_activity(user=request.user, activity=activity_constants.ACTIVITY_SOCIAL_SHARE, sub=ugettext('<a href="%s">%s</a> via %s' % (request.META['HTTP_REFERER'], request.META['HTTP_REFERER'], self.type))) return HttpResponseRedirect(url) except Exception, e: return Http404(e.message)
def accept(self): self.state = 'accepted' self.save() # Delete notifications if no more friend requests if not MemberFriend.objects.filter(friend=self.friend, state='invited').exclude(id=self.id).exists(): link, dc = Link.objects.get_or_create( title=ugettext("You have pending friend requests"), view_name='my-friend-requests' ) for obj in Notification.objects.filter(member=self.friend, link=link): obj.delete() UserActivity.track_activity(user=self.friend, activity=activity_constants.ACTIVITY_ESTABLISHED_FRIENDSHIP, sub=ugettext('You accepted a Friend Request from <a href="%s">%s</a>' % (reverse('member-detail', args=[self.member.username]), self.member)), content_object=self, image_object=self.member) UserActivity.track_activity(user=self.member, activity=activity_constants.ACTIVITY_ESTABLISHED_FRIENDSHIP, sub=ugettext('Your friend <a href="%s">%s</a> accepted your Friend Request. ' % (reverse('member-detail', args=[self.friend.username]), self.friend)), content_object=self, image_object=self.friend)
def post_save_user(sender, instance, created, **kwargs): """Handler for User post save.""" if created: UserActivity.track_activity(instance, constants.ACTIVITY_SIGNED_UP)