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 watch_user(request, user_name): title = u'%s / 关注的用户' % user_name gsuser = GsuserManager.get_user_by_name(user_name) if gsuser is None: raise Http404 gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id) feedAction = FeedAction() raw_watch_users = feedAction.get_watch_users(gsuser.id, 0, 100) watch_user_ids = [int(x[0]) for x in raw_watch_users] watch_users_map = GsuserManager.map_users(watch_user_ids) watch_users = [watch_users_map[x] for x in watch_user_ids if x in watch_users_map] raw_bewatch_users = feedAction.get_bewatch_users(gsuser.id, 0, 100) bewatch_user_ids = [int(x[0]) for x in raw_bewatch_users] bewatch_users_map = GsuserManager.map_users(bewatch_user_ids) bewatch_users = [bewatch_users_map[x] for x in bewatch_user_ids if x in bewatch_users_map] # fixed on detect need_fix = False if len(watch_users) != gsuserprofile.watch: gsuserprofile.watch = len(watch_users) need_fix = True if len(bewatch_users) < 100 and len(bewatch_users) != gsuserprofile.be_watched: gsuserprofile.be_watched = len(bewatch_users) need_fix = True if need_fix: gsuserprofile.save() response_dictionary = {'mainnav': 'user', 'title': title, 'watch_users': watch_users, 'bewatch_users': bewatch_users} response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/watch_user.html', response_dictionary, context_instance=RequestContext(request))
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 watch_user(request, user_name): title = u'%s / 关注的用户' % user_name gsuser = GsuserManager.get_user_by_name(user_name) if gsuser is None: raise Http404 gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id) feedAction = FeedAction() raw_watch_users = feedAction.get_watch_users(gsuser.id, 0, 100) watch_user_ids = [int(x[0]) for x in raw_watch_users] watch_users_map = GsuserManager.map_users(watch_user_ids) watch_users = [ watch_users_map[x] for x in watch_user_ids if x in watch_users_map ] raw_bewatch_users = feedAction.get_bewatch_users(gsuser.id, 0, 100) bewatch_user_ids = [int(x[0]) for x in raw_bewatch_users] bewatch_users_map = GsuserManager.map_users(bewatch_user_ids) bewatch_users = [ bewatch_users_map[x] for x in bewatch_user_ids if x in bewatch_users_map ] # fixed on detect need_fix = False if len(watch_users) != gsuserprofile.watch: gsuserprofile.watch = len(watch_users) need_fix = True if len(bewatch_users) < 100 and len( bewatch_users) != gsuserprofile.be_watched: gsuserprofile.be_watched = len(bewatch_users) need_fix = True if need_fix: gsuserprofile.save() response_dictionary = { 'mainnav': 'user', 'title': title, 'watch_users': watch_users, 'bewatch_users': bewatch_users } response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/watch_user.html', response_dictionary, context_instance=RequestContext(request))
def list_watch_user(self, repo_id): watchHistory = query(WatchHistory, None, 'watchhistory_l_repoId', [repo_id]) user_ids = [o.user_id for o in watchHistory] user_map = GsuserManager.map_users(user_ids) watch_user = [] for user_id in user_ids: if user_id in user_map: watch_user.append(user_map[user_id]) return watch_user
def explore(request): repo_ids = get_hot_repo_ids() raw_repos = RepoManager.list_repo_by_ids(repo_ids) repos = [x for x in raw_repos if x.auth_type != 2] user_ids = [x.user_id for x in repos] users_dict = GsuserManager.map_users(user_ids) username_dict = dict([(users_dict[x]['id'], users_dict[x]['username']) for x in users_dict]) userimgurl_dict = dict([(users_dict[x]['id'], users_dict[x]['imgurl']) for x in users_dict]) feedAction = FeedAction() latest_feeds = feedAction.get_latest_feeds(0, 100) feeds_as_json = latest_feeds_as_json(request, latest_feeds) response_dictionary = {'repos': repos, 'users_dict': users_dict, 'username_dict': username_dict, 'userimgurl_dict': userimgurl_dict, 'feeds_as_json': feeds_as_json} return render_to_response('explore/explore.html', response_dictionary, context_instance=RequestContext(request))
def __conver_to_recommends_vo(raw_recommends): user_ids = [x.from_user_id for x in raw_recommends] users_map = GsuserManager.map_users(user_ids) recommends_vo = [x.to_recommend_vo(users_map) for x in raw_recommends] return recommends_vo