def tag_planet_rss(request, tag=None, kind=None): activities = None planet_helper = PlanetTagHelper(ITEMS_PER_FEED, tag=tag) if kind == "all": activities = planet_helper.planet_tag_all() elif kind == "friends": friends_list = planet_helper.get_friends_list(request) activities = planet_helper.planet_tag_friends(friends_list) elif kind == "similar_users": similar_users = planet_helper.get_similar_users_list(request) activities = planet_helper.planet_tag_similar_users(similar_users) elif kind == "short_reviews": activities = planet_helper.planet_tag_reviews() elif kind == "notes": activities = planet_helper.planet_tag_notes() elif kind == "comments": activities = planet_helper.planet_tag_comments() response = HttpResponse(mimetype='application/rss+xml') t = loader.get_template(templates['PLANET_RSS']) c = Context({'activities': activities, 'kind': kind}) response.write(t.render(c)) return response
def tag_planet_rss(request, tag=None, kind=None): activities = None planet_helper = PlanetTagHelper(ITEMS_PER_FEED, tag=tag) if kind == "all": activities = planet_helper.planet_tag_all() elif kind == "friends": friends_list = planet_helper.get_friends_list(request) activities = planet_helper.planet_tag_friends(friends_list) elif kind == "similar_users": similar_users = planet_helper.get_similar_users_list(request) activities = planet_helper.planet_tag_similar_users(similar_users) elif kind == "short_reviews": activities = planet_helper.planet_tag_reviews() elif kind == "notes": activities = planet_helper.planet_tag_notes() elif kind == "comments": activities = planet_helper.planet_tag_comments() response = HttpResponse(mimetype='application/rss+xml') t = loader.get_template(templates['PLANET_RSS']) c = Context({'activities': activities,'kind': kind}) response.write(t.render(c)) return response
def test_saving_comment_activity(self): """ Test saving comment activity """ self.initialize() # set up post for commenting post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() comment = ThreadedComment() comment.user = self.u1 comment.comment = "Lorem ipsum" comment.content_object = post comment.status = Object.PUBLIC_STATUS comment.type = Object.TYPE_COMMENT comment.permalink = "COMMENT" comment.save() activity = UserActivity.objects.get(comment=comment) # testing if activity was saved properly self.failUnlessEqual(activity.title, comment.content_object.get_comment_title()) self.failUnlessEqual(activity.content, comment.comment) if settings.ENSURE_OLD_STYLE_PERMALINKS: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id) ) else: self.failUnlessEqual(activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id)) self.failUnlessEqual(activity.status, comment.status) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT) self.failUnlessEqual(activity.username, self.u1.username) # planet_tag_helper without tag = 1 comment pth = PlanetTagHelper() comments = pth.planet_tag_comments() self.assertEquals(len(comments), 1) # planet_tag_helper with tag 'comedy' = 0 comment # no assigned films to comment pth_tags = PlanetTagHelper(tag="comedy") comments = pth_tags.planet_tag_comments() self.assertEquals(len(comments), 0)
def test_saving_comment_activity(self): """ Test saving comment activity """ self.initialize() # set up post for commenting post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() comment = ThreadedComment() comment.user = self.u1 comment.comment = "Lorem ipsum" comment.content_object = post comment.status = Object.PUBLIC_STATUS comment.type = Object.TYPE_COMMENT comment.permalink = "COMMENT" comment.save() activity = UserActivity.objects.get(comment=comment) # testing if activity was saved properly self.failUnlessEqual(activity.title, comment.content_object.get_comment_title()) self.failUnlessEqual(activity.content, comment.comment) if settings.ENSURE_OLD_STYLE_PERMALINKS: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id)) else: self.failUnlessEqual( activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id)) self.failUnlessEqual(activity.status, comment.status) self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT) self.failUnlessEqual(activity.username, self.u1.username) #planet_tag_helper without tag = 1 comment pth = PlanetTagHelper() comments = pth.planet_tag_comments() self.assertEquals(len(comments), 1) #planet_tag_helper with tag 'comedy' = 0 comment #no assigned films to comment pth_tags = PlanetTagHelper(tag='comedy') comments = pth_tags.planet_tag_comments() self.assertEquals(len(comments), 0)
def test_planet_tag(self): # --- Initialize --- self.initialize() helper_without_tags = PlanetTagHelper() helper_with_tags = PlanetTagHelper(tag='comedy') recom_helper = RecomHelper() user_activity_helper = UserActivityHelper() # --- setup followers --- self.u1.followers.follow(self.u2) self.u1.followers.follow(self.u3) self.u1.followers.follow(self.u4) # similar users from film20.recommendations.bot_helper import do_create_comparators self.films_for_comparator() do_create_comparators() friends_list = recom_helper.get_following_ids_as_list(self.u1) friends_without_activities = helper_without_tags.planet_tag_friends(friends_list) self.assertEquals(len(friends_without_activities), 0) similar_users_list = user_activity_helper.get_similar_users_list(request) similar_users_without_tags = helper_without_tags.planet_tag_similar_users(similar_users_list) self.assertEquals(len(similar_users_without_tags), 0) notes_without_tags = helper_without_tags.planet_tag_notes() self.assertEquals(len(notes_without_tags), 0) all_planet_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_planet_activities), 0) # --- setup User activities --- post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 1) post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 2) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u1 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 3) # Activities with 'comedy' tag all_activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(all_activities_with_tags), 1) # --- setup followers activities --- post = Post() post.title = "#1 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u2 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 4) post = Post() post.title = "#2 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u3 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 5) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u4 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 6) activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(activities_with_tags), 2) all_friends_activities = helper_without_tags.planet_tag_friends(friends_list) self.assertEquals(len(all_friends_activities), 3) friends_activities_with_tag = helper_with_tags.planet_tag_friends(friends_list) self.assertEquals(len(friends_activities_with_tag), 1) # --- Check notes --- all_planet_notes = helper_without_tags.planet_tag_notes() self.assertEquals(len(all_planet_notes), 4) # Post notes with 'comedy' tag notes_activities_with_tag = helper_with_tags.planet_tag_notes() self.assertEquals(len(notes_activities_with_tag), 2) similar_users_activities = helper_without_tags.planet_tag_similar_users(similar_users_list) self.assertEquals(len(similar_users_activities), 2) users_with_tags = helper_with_tags.planet_tag_similar_users(similar_users_list) self.assertEquals(len(users_with_tags), 1) activities = UserActivity.objects.all()
def test_planet_tag(self): # --- Initialize --- self.initialize() helper_without_tags = PlanetTagHelper() helper_with_tags = PlanetTagHelper(tag='comedy') recom_helper = RecomHelper() user_activity_helper = UserActivityHelper() # --- setup followers --- self.u1.followers.follow(self.u2) self.u1.followers.follow(self.u3) self.u1.followers.follow(self.u4) # similar users from film20.recommendations.bot_helper import do_create_comparators self.films_for_comparator() do_create_comparators() friends_list = recom_helper.get_following_ids_as_list(self.u1) friends_without_activities = helper_without_tags.planet_tag_friends( friends_list) self.assertEquals(len(friends_without_activities), 0) similar_users_list = user_activity_helper.get_similar_users_list( request) similar_users_without_tags = helper_without_tags.planet_tag_similar_users( similar_users_list) self.assertEquals(len(similar_users_without_tags), 0) notes_without_tags = helper_without_tags.planet_tag_notes() self.assertEquals(len(notes_without_tags), 0) all_planet_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_planet_activities), 0) # --- setup User activities --- post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 1) post = Post() post.title = "Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u1 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 2) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u1 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 3) # Activities with 'comedy' tag all_activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(all_activities_with_tags), 1) # --- setup followers activities --- post = Post() post.title = "#1 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u2 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 4) post = Post() post.title = "#2 Lorem ipsum" post.permalink = "lorem-ipsum" post.body = "siala lala tralala" post.user = self.u3 post.status = Object.PUBLIC_STATUS post.type = Object.TYPE_POST post.save() post.related_film.add(self.film1) post.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 5) obj = Object.objects.get(id=self.film2.id) shortreview = ShortReview() shortreview.user = self.u4 shortreview.review_text = "sialala bumcyk cyk" shortreview.status = Object.PUBLIC_STATUS shortreview.type = Object.TYPE_SHORT_REVIEW shortreview.object = obj shortreview.kind = ShortReview.REVIEW shortreview.save() all_activities = helper_without_tags.planet_tag_all() self.assertEquals(len(all_activities), 6) activities_with_tags = helper_with_tags.planet_tag_all() self.assertEquals(len(activities_with_tags), 2) all_friends_activities = helper_without_tags.planet_tag_friends( friends_list) self.assertEquals(len(all_friends_activities), 3) friends_activities_with_tag = helper_with_tags.planet_tag_friends( friends_list) self.assertEquals(len(friends_activities_with_tag), 1) # --- Check notes --- all_planet_notes = helper_without_tags.planet_tag_notes() self.assertEquals(len(all_planet_notes), 4) # Post notes with 'comedy' tag notes_activities_with_tag = helper_with_tags.planet_tag_notes() self.assertEquals(len(notes_activities_with_tag), 2) similar_users_activities = helper_without_tags.planet_tag_similar_users( similar_users_list) self.assertEquals(len(similar_users_activities), 2) users_with_tags = helper_with_tags.planet_tag_similar_users( similar_users_list) self.assertEquals(len(users_with_tags), 1) activities = UserActivity.objects.all()