def celery_track_content_vote( user_id, vote_id, vote_type, meta, update ): User = apps.get_model('user.User') user = User.objects.get(id=user_id) Vote = apps.get_model(f'{vote_type}.Vote') vote = Vote.objects.get(id=vote_id) rating = vote.vote_type review_properties = { '$user_id': str(user.id), '$content_id': f'{type(vote).__name__}_{vote.id}', '$status': '$active', '$review': { '$contact_email': user.email, '$rating': rating } } track_type = '$update_content' if update else '$create_content' try: response = client.track(track_type, review_properties, return_score=False) print(response.body) return response.body except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)
def celery_track_content_paper(user_id, paper_id, meta, update): User = apps.get_model('user.User') user = User.objects.get(id=user_id) Paper = apps.get_model('paper.Paper') paper = Paper.objects.get(id=paper_id) post_properties = { # Required fields '$user_id': str(user.id), '$content_id': f'{type(paper).__name__}_{paper.id}', # Recommended fields '$status': '$active', # Required $post object '$post': { '$subject': paper.title, '$body': paper.paper_title, '$contact_email': user.email, '$contact_address': { '$name': f'{user.first_name} {user.last_name}', }, '$categories': list(paper.hubs.values_list('slug', flat=True)), } } track_type = '$update_content' if update else '$create_content' try: response = client.track(track_type, post_properties, return_score=False) print(response.body) return response.body except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)
def celery_track_content_comment( user_id, comment_id, comment_type, meta, is_thread, update, ): User = apps.get_model('user.User') user = User.objects.get(id=user_id) Discussion = apps.get_model(f'discussion.{comment_type}') comment = Discussion.objects.get(id=comment_id) root_content_id = '' if comment.paper is not None: root_content_id = ( f'{type(comment.paper).__name__}_{comment.paper.id}' ) comment_properties = { # Required fields '$user_id': str(user.id), # must be unique across all content types '$content_id': f'{type(comment).__name__}_{comment.id}', # Recommended fields '$status': '$active', # Required $comment object '$comment': { '$body': comment.plain_text, '$contact_email': user.email, '$root_content_id': root_content_id, } } if not is_thread: comment_properties['$comment']['$parent_comment_id'] = ( f'{type(comment.parent).__name__}_{comment.parent.id}' ) track_type = '$update_content' if update else '$create_content' try: response = client.track(track_type, comment_properties, return_score=False) print(response.body) return response.body except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)
def track_flag_content(self, user, content_id, referer_id): # https://sift.com/developers/docs/curl/events-api/reserved-events/flag-content if not user: return None properties = { '$user_id': str(user.id), '$content_id': content_id, '$flagged_by': str(referer_id), } try: response = client.track('$flag_content', properties) print(response.body) except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)
def celery_track_login(user_id, meta, login_status): User = apps.get_model('user.User') user = User.objects.get(id=user_id) properties = { '$user_id': str(user.id), '$login_status': login_status, '$username': user.username, } try: response = client.track('$login', properties, return_score=False) print(response.body) return response.body except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)
def celery_track_account(user_id, meta, update): User = apps.get_model('user.User') user = User.objects.get(id=user_id) properties = { # Required Fields '$user_id': str(user.id), # Supported Fields '$user_email': user.email, '$name': f'{user.first_name} {user.last_name}', '$social_sign_on_type': '$google', } track_type = '$update_account' if update else '$create_account' try: response = client.track(track_type, properties, return_score=False) print(response.body) return response.body except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)
def celery_track_content_bullet_point(user_id, bullet_point_id, meta, update): User = apps.get_model('user.User') user = User.objects.get(id=user_id) BulletPoint = apps.get_model('bullet_point.BulletPoint') bullet_point = BulletPoint.objects.get(id=bullet_point_id) root_content_id = '' if bullet_point.paper is not None: root_content_id = ( f'{type(bullet_point.paper).__name__}_{bullet_point.paper.id}' ) comment_properties = { # Required fields '$user_id': str(user.id), # must be unique across all content types '$content_id': f'{type(bullet_point).__name__}_{bullet_point.id}', # Recommended fields '$status': '$active', # Required $comment object '$comment': { '$body': bullet_point.plain_text, '$contact_email': user.email, '$root_content_id': root_content_id, } } track_type = '$update_content' if update else '$create_content' try: response = client.track(track_type, comment_properties, return_score=False) print(response.body) return response.body except sift.client.ApiException as e: sentry.log_error(e) print(e.api_error_message)