def get_common_user_dict(request, gsuser, gsuserprofile): feedAction = FeedAction() raw_watch_users = feedAction.get_watch_users(gsuser.id, 0, 10) raw_bewatch_users = feedAction.get_bewatch_users(gsuser.id, 0, 10) watch_user_ids = [int(x[0]) for x in raw_watch_users] bewatch_user_ids = [int(x[0]) for x in raw_bewatch_users] watch_users_map = GsuserManager.map_users(watch_user_ids) bewatch_users_map = GsuserManager.map_users(bewatch_user_ids) watch_users = [ watch_users_map[x] for x in watch_user_ids if x in watch_users_map ] bewatch_users = [ bewatch_users_map[x] for x in bewatch_user_ids if x in bewatch_users_map ] raw_recommends = GsuserManager.list_recommend_by_userid(gsuser.id, 0, 20) recommends = __conver_to_recommends_vo(raw_recommends) is_watched_user = False if request.user.is_authenticated(): is_watched_user = RepoManager.is_watched_user(request.user.id, gsuser.id) return { 'gsuser': gsuser, 'gsuserprofile': gsuserprofile, 'watch_users': watch_users, 'bewatch_users': bewatch_users, 'recommends': recommends, 'is_watched_user': is_watched_user, 'show_common': True }
def get_common_user_dict(request, gsuser, gsuserprofile): feedAction = FeedAction() raw_watch_users = feedAction.get_watch_users(gsuser.id, 0, 10) raw_bewatch_users = feedAction.get_bewatch_users(gsuser.id, 0, 10) watch_user_ids = [int(x[0]) for x in raw_watch_users] bewatch_user_ids = [int(x[0]) for x in raw_bewatch_users] watch_users_map = GsuserManager.map_users(watch_user_ids) bewatch_users_map = GsuserManager.map_users(bewatch_user_ids) watch_users = [watch_users_map[x] for x in watch_user_ids if x in watch_users_map] bewatch_users = [bewatch_users_map[x] for x in bewatch_user_ids if x in bewatch_users_map] raw_recommends = GsuserManager.list_recommend_by_userid(gsuser.id, 0, 20) recommends = __conver_to_recommends_vo(raw_recommends) is_watched_user = False if request.user.is_authenticated(): is_watched_user = RepoManager.is_watched_user(request.user.id, gsuser.id) return {'gsuser': gsuser, 'gsuserprofile': gsuserprofile, 'watch_users': watch_users, 'bewatch_users': bewatch_users, 'recommends': recommends, 'is_watched_user': is_watched_user, 'show_common': True}
def recommend(request, user_name): gsuser = GsuserManager.get_user_by_name(user_name) if gsuser is None: raise Http404 if request.method == 'POST': recommendsForm = RecommendsForm(request.POST) if recommendsForm.is_valid() and request.user.is_authenticated(): content = recommendsForm.cleaned_data['content'].strip() if content != '': recommend = Recommend() recommend.user_id = gsuser.id recommend.content = content recommend.from_user_id = request.user.id recommend.save() gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id) raw_recommends = GsuserManager.list_recommend_by_userid(gsuser.id, 0, 50) recommends = __conver_to_recommends_vo(raw_recommends) response_dictionary = {'mainnav': 'user', 'recommends': recommends} response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/recommend.html', response_dictionary, context_instance=RequestContext(request))
def recommend(request, user_name): gsuser = GsuserManager.get_user_by_name(user_name) if gsuser is None: raise Http404 if request.method == 'POST': recommendsForm = RecommendsForm(request.POST) if recommendsForm.is_valid() and request.user.is_authenticated(): content = recommendsForm.cleaned_data['content'].strip() if content != '': recommend = Recommend() recommend.user_id = gsuser.id recommend.content = content recommend.from_user_id = request.user.id recommend.save() gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id) raw_recommends = GsuserManager.list_recommend_by_userid(gsuser.id, 0, 50) recommends = __conver_to_recommends_vo(raw_recommends) response_dictionary = {'mainnav': 'user', 'recommends': recommends} response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/recommend.html', response_dictionary, context_instance=RequestContext(request))