def notif_pull_request_status(self, pullRequest, pullStatus): notif_type = NOTIF_TYPE.MERGE_CREATE_PULL_REQUEST message = '' if pullStatus == PULL_STATUS.NEW: message = u'新建了' merge_user_profile = GsuserManager.get_userprofile_by_id(pullRequest.merge_user_id) if merge_user_profile is not None: notifMessage = NotifMessage.create(NOTIF_CATE.MERGE, NOTIF_TYPE.MERGE_CREATE_PULL_REQUEST, pullRequest.pull_user_id, pullRequest.merge_user_id, pullRequest.id) notifMessage.message = message self.message_save_and_notif(notifMessage) merge_user_profile.unread_message = merge_user_profile.unread_message + 1 merge_user_profile.save() return if pullStatus == PULL_STATUS.MERGED_FAILED: notif_type = NOTIF_TYPE.MERGE_MERGED_FAILED_PULL_REQUEST message = u'合并失败' elif pullStatus == PULL_STATUS.MERGED: notif_type = NOTIF_TYPE.MERGE_MERGED_PULL_REQUEST message = u'合并了' elif pullStatus == PULL_STATUS.REJECTED: notif_type = NOTIF_TYPE.MERGE_REJECTED_PULL_REQUEST message = u'拒绝了' elif pullStatus == PULL_STATUS.CLOSE: notif_type = NOTIF_TYPE.MERGE_CLOSE_PULL_REQUEST message = u'关闭了' pull_user_profile = GsuserManager.get_userprofile_by_id(pullRequest.pull_user_id) if pull_user_profile is not None: notifMessage = NotifMessage.create(NOTIF_CATE.MERGE, notif_type, pullRequest.merge_user_id, pullRequest.pull_user_id, pullRequest.id) notifMessage.message = message self.message_save_and_notif(notifMessage) pull_user_profile.unread_message = pull_user_profile.unread_message + 1 pull_user_profile.save()
def list_teamMember_by_teamUserId(self, team_user_id): userprofile = GsuserManager.get_userprofile_by_id(team_user_id) if userprofile.is_team_account == 0: return [] teamMembers = query(TeamMember, team_user_id, 'teammember_l_teamUserId', [team_user_id]) for x in teamMembers: x.user = GsuserManager.get_userprofile_by_id(x.user_id) x.team_user = userprofile return teamMembers
def list_teamMember_by_userId(self, user_id): userprofile = GsuserManager.get_userprofile_by_id(user_id) if userprofile.has_joined_team == 0: return [] teamMembers = query(TeamMember, None, 'teammember_l_userId', [user_id]) for x in teamMembers: x.user = GsuserManager.get_userprofile_by_id(x.user_id) x.team_user = GsuserManager.get_userprofile_by_id(x.team_user_id) return teamMembers
def fillwith(self): self.repo = RepoManager.get_repo_by_id(self.repo_id) self.creator_userprofile = GsuserManager.get_userprofile_by_id(self.creator_user_id) self.assigned_userprofile = GsuserManager.get_userprofile_by_id(self.assigned) if self.tracker in ISSUE_ATTRS['REV_TRACKERS']: self.tracker_v = ISSUE_ATTRS['REV_TRACKERS'][self.tracker] if self.status in ISSUE_ATTRS['REV_STATUSES']: self.status_v = ISSUE_ATTRS['REV_STATUSES'][self.status] if self.priority in ISSUE_ATTRS['REV_PRIORITIES']: self.priority_v = ISSUE_ATTRS['REV_PRIORITIES'][self.priority]
def fillwith(self): self.pull_user = GsuserManager.get_userprofile_by_id(self.pull_user_id) self.merge_user = GsuserManager.get_userprofile_by_id(self.merge_user_id) self.source_repo = RepoManager.get_repo_by_id(self.source_repo_id) self.desc_repo = RepoManager.get_repo_by_id(self.desc_repo_id) self.short_title = self.title self.short_desc = self.desc if len(self.short_title) > 20: self.short_title = self.short_title[0:20] + '...' if len(self.short_desc) > 20: self.short_desc = self.short_desc[0:20] + '...' self.status_view = PULL_STATUS.VIEW_MAP[self.status] self.status_label = PULL_STATUS.LABEL_MAP[self.status]
def get_teamMember_by_teamUserId_userId(self, team_user_id, user_id): # for team user global permission if team_user_id == 0: teamMember = query_first(TeamMember, team_user_id, 'teammember_s_teamUserId_userId', [team_user_id, user_id]) return teamMember team_userprofile = GsuserManager.get_userprofile_by_id(team_user_id) if team_userprofile and team_userprofile.is_team_account == 0: return None teamMember = query_first(TeamMember, team_user_id, 'teammember_s_teamUserId_userId', [team_user_id, user_id]) if not teamMember: return None teamMember.user = GsuserManager.get_userprofile_by_id(user_id) teamMember.team_user = team_userprofile return teamMember
def fillwith(self): self.pull_user = GsuserManager.get_userprofile_by_id(self.pull_user_id) self.merge_user = GsuserManager.get_userprofile_by_id( self.merge_user_id) self.source_repo = RepoManager.get_repo_by_id(self.source_repo_id) self.desc_repo = RepoManager.get_repo_by_id(self.desc_repo_id) self.short_title = self.title self.short_desc = self.desc if len(self.short_title) > 20: self.short_title = self.short_title[0:20] + '...' if len(self.short_desc) > 20: self.short_desc = self.short_desc[0:20] + '...' self.status_view = PULL_STATUS.VIEW_MAP[self.status] self.status_label = PULL_STATUS.LABEL_MAP[self.status]
def watch_repo(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_repos = feedAction.get_watch_repos(gsuser.id, 0, 100) watch_repo_ids = [int(x[0]) for x in raw_watch_repos] watch_repos_map = RepoManager.merge_repo_map_ignore_visibly(watch_repo_ids) watch_repos = [ watch_repos_map[x] for x in watch_repo_ids if x in watch_repos_map ] response_dictionary = { 'mainnav': 'user', 'title': title, 'watch_repos': watch_repos } # fixed on detect if len(watch_repos) != gsuserprofile.watchrepo: gsuserprofile.watchrepo = len(watch_repos) gsuserprofile.save() response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/watch_repo.html', response_dictionary, context_instance=RequestContext(request))
def notif_at(self, notif_type, from_user_id, relative_id, message): at_name_list = FeedUtils.list_atname(message) user_unread_message_dict = {} for at_name in at_name_list: at_user = GsuserManager.get_user_by_name(at_name) if at_user is not None: to_user_id = at_user.id notifMessage = None # disable duplicate notify exists_notifMessage = self.get_notifmessage_by_userId_notifType_relativeId(to_user_id, notif_type, relative_id) if exists_notifMessage is not None: continue if notif_type == NOTIF_TYPE.AT_COMMIT: notifMessage = NotifMessage.create_at_commit(from_user_id, to_user_id, relative_id) elif notif_type == NOTIF_TYPE.AT_MERGE: notifMessage = NotifMessage.create_at_merge(from_user_id, to_user_id, relative_id) elif notif_type == NOTIF_TYPE.AT_ISSUE: notifMessage = NotifMessage.create_at_issue(from_user_id, to_user_id, relative_id) elif notif_type == NOTIF_TYPE.AT_ISSUE_COMMENT: notifMessage = NotifMessage.create_at_issue_comment(from_user_id, to_user_id, relative_id) if notifMessage is None: continue self.message_save_and_notif(notifMessage) if to_user_id not in user_unread_message_dict: user_unread_message_dict[to_user_id] = 0 user_unread_message_dict[to_user_id] = user_unread_message_dict[to_user_id] + 1 for to_user_id, unread_message in user_unread_message_dict.items(): at_userprofile = GsuserManager.get_userprofile_by_id(to_user_id) at_userprofile.unread_message = at_userprofile.unread_message + unread_message at_userprofile.save()
def group(request, username, group_id): teamUser = GsuserManager.get_user_by_name(username) teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id) teamGroup = TeamManager.get_teamGroup_by_id(group_id) if not teamGroup or teamGroup.team_user_id != teamUser.id: raise Http404 groupMembers = TeamManager.list_groupMember_by_teamGroupId(teamGroup.id) userIdInGroupSet = Set([x.member_user_id for x in groupMembers]) teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id) teamMembersNotInGroup = [ x for x in teamMembers if x.user_id not in userIdInGroupSet ] current = 'settings' sub_nav = 'groups' title = u'%s / 设置 / 组管理 / %s' % (teamUser.username, teamGroup.name) response_dictionary = { 'current': current, 'sub_nav': sub_nav, 'title': title, 'teamGroup': teamGroup, 'groupMembers': groupMembers, 'teamMembersNotInGroup': teamMembersNotInGroup } response_dictionary.update( _get_common_team_dict(request, teamUser, teamUserprofile)) return render_to_response('team/group.html', response_dictionary, context_instance=RequestContext(request))
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_userprofile(request): if not hasattr(request, '_cached_userprofile'): if request.user.is_authenticated(): request._cached_userprofile = GsuserManager.get_userprofile_by_id(request.user.id) else: request._cached_userprofile = Userprofile() return request._cached_userprofile
def fillwith(self): self.push_userprofile = GsuserManager.get_userprofile_by_id(self.push_user_id) self.repo = RepoManager.get_repo_by_id(self.repo_id) self.short_refname = self.refname if self.refname and '/' in self.refname: self.short_refname = self.refname[self.refname.rfind('/')+1:] for commit in self.commits: commit.fillwith()
def get_userprofile(request): if not hasattr(request, '_cached_userprofile'): if request.user.is_authenticated(): request._cached_userprofile = GsuserManager.get_userprofile_by_id( request.user.id) else: request._cached_userprofile = Userprofile() return request._cached_userprofile
def fillwith(self): self.push_userprofile = GsuserManager.get_userprofile_by_id( self.push_user_id) self.repo = RepoManager.get_repo_by_id(self.repo_id) self.short_refname = self.refname if self.refname and '/' in self.refname: self.short_refname = self.refname[self.refname.rfind('/') + 1:] for commit in self.commits: commit.fillwith()
def update_user_repo_quote(self, user, repo, diff_size): userprofile = GsuserManager.get_userprofile_by_id(user.id) userprofile.used_quote = userprofile.used_quote + diff_size repo.used_quote = repo.used_quote + diff_size if userprofile.used_quote < 0: userprofile.used_quote = 0 if repo.used_quote < 0: repo.used_quote = 0 userprofile.save() repo.save()
def groups(request, username): teamUser = GsuserManager.get_user_by_name(username) teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id) teamGroups = TeamManager.list_teamGroup_by_teamUserId(teamUser.id) current = 'settings'; sub_nav = 'groups'; title = u'%s / 设置 / 组管理' % (teamUser.username) response_dictionary = {'current': current, 'sub_nav': sub_nav, 'title': title, 'teamGroups': teamGroups} response_dictionary.update(_get_common_team_dict(request, teamUser, teamUserprofile)) return render_to_response('team/groups.html', response_dictionary, context_instance=RequestContext(request))
def get_permissionItem_by_setId_userId(self, set_id, user_id): if set_id == 0: return None permissionItem = query_first(PermissionItem, set_id, 'permissionitem_s_setId_userId', [set_id, user_id]) if not permissionItem: return None permissionItem.userprofile = GsuserManager.get_userprofile_by_id(permissionItem.user_id) if permissionItem.permission in PERMISSION.VIEW: permissionItem.permission_view = PERMISSION.VIEW[permissionItem.permission] return permissionItem
def update_user_repo_quote(self, user, repo, diff_size): userprofile = GsuserManager.get_userprofile_by_id(user.id) userprofile.used_quote = userprofile.used_quote + diff_size repo.used_quote = repo.used_quote + diff_size if userprofile.used_quote < 0: userprofile.used_quote = 0 if repo.used_quote < 0: repo.used_quote = 0 userprofile.save() repo.save()
def _get_team_user_userprofile(request, username): current_user = GsuserManager.get_user_by_name(username) if not current_user: return (request.user, request.userprofile) teamMember = TeamManager.get_teamMember_by_teamUserId_userId(current_user.id, request.user.id) if not teamMember: return (request.user, request.userprofile) current_userprofile = GsuserManager.get_userprofile_by_id(current_user.id) if current_userprofile: return (current_user, current_userprofile) return (request.user, request.userprofile)
def stats(request, user_name): user = GsuserManager.get_user_by_name(user_name) if user is None: raise Http404 stats_dict = get_stats_dict(request, user) gsuserprofile = GsuserManager.get_userprofile_by_id(user.id) response_dictionary = {'title': u'%s / 最近统计' % (user.username), 'gsuserprofile': gsuserprofile} response_dictionary.update(stats_dict) return render_to_response('user/stats.html', response_dictionary, context_instance=RequestContext(request))
def get_attrs(username, reponame): user = GsuserManager.get_user_by_name(username) if not user: return_all_none() userprofile = GsuserManager.get_userprofile_by_id(user.id) if not userprofile: return_all_none() repo = RepoManager.get_repo_by_userId_name(user.id, reponame) if not repo: return_all_none() abs_repo_path = repo.get_abs_repopath() return (user, userprofile, repo, abs_repo_path)
def star_repo(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) star_repos = RepoManager.list_star_repo(gsuser.id, 0, 500) response_dictionary = {'mainnav': 'user', 'title': title, 'star_repos': star_repos} response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/star_repo.html', response_dictionary, context_instance=RequestContext(request))
def get_attrs(username, reponame): user = GsuserManager.get_user_by_name(username) if not user: return_all_none() userprofile = GsuserManager.get_userprofile_by_id(user.id) if not userprofile: return_all_none() repo = RepoManager.get_repo_by_userId_name(user.id, reponame) if not repo: return_all_none() abs_repo_path = repo.get_abs_repopath() return (user, userprofile, repo, abs_repo_path)
def _get_team_user_userprofile(request, username): current_user = GsuserManager.get_user_by_name(username) if not current_user: return (request.user, request.userprofile) teamMember = TeamManager.get_teamMember_by_teamUserId_userId( current_user.id, request.user.id) if not teamMember: return (request.user, request.userprofile) current_userprofile = GsuserManager.get_userprofile_by_id(current_user.id) if current_userprofile: return (current_user, current_userprofile) return (request.user, request.userprofile)
def add_member(self, repo, user): if repo is None or user is None or repo.user_id == user.id: return None userprofile = GsuserManager.get_userprofile_by_id(user.id) userprofile.has_joined_repo = 1 userprofile.save() repoMember = self.get_repo_member(repo.id, user.id) if repoMember is None: repoMember = RepoMember() repoMember.repo_id = repo.id repoMember.user_id = user.id repoMember.save()
def add_member(self, repo, user): if repo is None or user is None or repo.user_id == user.id: return None userprofile = GsuserManager.get_userprofile_by_id(user.id) userprofile.has_joined_repo = 1 userprofile.save() repoMember = self.get_repo_member(repo.id, user.id) if repoMember is None: repoMember = RepoMember() repoMember.repo_id = repo.id repoMember.user_id = user.id repoMember.save()
def notif_pull_request_status(self, pullRequest, pullStatus): notif_type = NOTIF_TYPE.MERGE_CREATE_PULL_REQUEST message = '' if pullStatus == PULL_STATUS.NEW: message = u'新建了' merge_user_profile = GsuserManager.get_userprofile_by_id( pullRequest.merge_user_id) if merge_user_profile is not None: notifMessage = NotifMessage.create( NOTIF_CATE.MERGE, NOTIF_TYPE.MERGE_CREATE_PULL_REQUEST, pullRequest.pull_user_id, pullRequest.merge_user_id, pullRequest.id) notifMessage.message = message self.message_save_and_notif(notifMessage) merge_user_profile.unread_message = merge_user_profile.unread_message + 1 merge_user_profile.save() return if pullStatus == PULL_STATUS.MERGED_FAILED: notif_type = NOTIF_TYPE.MERGE_MERGED_FAILED_PULL_REQUEST message = u'合并失败' elif pullStatus == PULL_STATUS.MERGED: notif_type = NOTIF_TYPE.MERGE_MERGED_PULL_REQUEST message = u'合并了' elif pullStatus == PULL_STATUS.REJECTED: notif_type = NOTIF_TYPE.MERGE_REJECTED_PULL_REQUEST message = u'拒绝了' elif pullStatus == PULL_STATUS.CLOSE: notif_type = NOTIF_TYPE.MERGE_CLOSE_PULL_REQUEST message = u'关闭了' pull_user_profile = GsuserManager.get_userprofile_by_id( pullRequest.pull_user_id) if pull_user_profile is not None: notifMessage = NotifMessage.create(NOTIF_CATE.MERGE, notif_type, pullRequest.merge_user_id, pullRequest.pull_user_id, pullRequest.id) notifMessage.message = message self.message_save_and_notif(notifMessage) pull_user_profile.unread_message = pull_user_profile.unread_message + 1 pull_user_profile.save()
def start(): users = User.objects.all() for user in users: userprofile = GsuserManager.get_userprofile_by_id(user.id) if not userprofile: continue if not re.match('[a-zA-Z0-9-_]+', user.username): continue userstats = {} userstats['username'] = user.username userstats['email'] = user.email userstats['date_joined'] = user.date_joined.strftime('%Y/%m/%d %H:%M:%S') userstats['last_login'] = user.last_login.strftime('%Y/%m/%d %H:%M:%S') repos = RepoManager.list_repo_by_userId(user.id, 0, 1000) userstats['repo_total_count'] = len(repos) first_time_commit = None; last_time_commit = None; commits = 0; forks = 0; repo_private_count = 0 for repo in repos: commits = commits + repo.commit if repo.auth_type != 0: repo_private_count = repo_private_count + 1 if repo.fork_repo_id != 0: forks = forks + 1 commitHistorys = CommitHistory.objects.filter(visibly=0).filter(repo_id=repo.id).order_by('create_time')[0:1] if len(commitHistorys) > 0: first_time_commitHistory = commitHistorys[0] if first_time_commit is None or first_time_commit > first_time_commitHistory.create_time: first_time_commit = first_time_commitHistory.create_time commitHistorys = CommitHistory.objects.filter(visibly=0).filter(repo_id=repo.id).order_by('-create_time')[0:1] if len(commitHistorys) > 0: last_time_commitHistory = commitHistorys[0] if last_time_commit is None or last_time_commit < last_time_commitHistory.create_time: last_time_commit = last_time_commitHistory.create_time userstats['repo_private_count'] = repo_private_count if first_time_commit: userstats['first_time_commit'] = first_time_commit.strftime('%Y/%m/%d %H:%M:%S') else: userstats['first_time_commit'] = '' if last_time_commit: userstats['last_time_commit'] = last_time_commit.strftime('%Y/%m/%d %H:%M:%S') else: userstats['last_time_commit'] = '' userstats['commits'] = commits userstats['watch_repo'] = userprofile.watchrepo userstats['fork_repo'] = forks pullrequests = RepoManager.list_pullRequest_by_pullUserId(user.id) userstats['pullrequests'] = len(pullrequests) issues = Issue.objects.filter(visibly=0).filter(creator_user_id=user.id)[0:1000] userstats['issues'] = len(issues) userpubkeys = KeyauthManager.list_userpubkey_by_userId(user.id) userstats['ssh_key'] = len(userpubkeys) csv_items = [userstats['username'], userstats['email'], userstats['date_joined'], userstats['last_login'], str(int(userstats['repo_total_count'])), str(int(userstats['repo_private_count'])), userstats['first_time_commit'], userstats['last_time_commit'], str(int(userstats['commits'])), str(int(userstats['watch_repo'])), str(int(userstats['fork_repo'])), str(int(userstats['pullrequests'])), str(int(userstats['issues'])), str(int(userstats['ssh_key']))] print ','.join(csv_items)
def get_user_repo_attr(username, reponame): nones = (None, None, None, None) user = GsuserManager.get_user_by_name(username) if not user: return nones userprofile = GsuserManager.get_userprofile_by_id(user.id) if not userprofile: return nones repo = RepoManager.get_repo_by_userId_name(user.id, reponame) if not repo: return nones abs_repopath = repo.get_abs_repopath() return (user, userprofile, repo, abs_repopath)
def get_user_repo_attr(username, reponame): nones = (None, None, None, None) user = GsuserManager.get_user_by_name(username) if not user: return nones userprofile = GsuserManager.get_userprofile_by_id(user.id) if not userprofile: return nones repo = RepoManager.get_repo_by_userId_name(user.id, reponame) if not repo: return nones abs_repopath = repo.get_abs_repopath() return (user, userprofile, repo, abs_repopath)
def list_joined_repo_by_userId(self, user_id, offset, row_count): userprofile = GsuserManager.get_userprofile_by_id(user_id) if userprofile is None or userprofile.has_joined_repo == 0: return [] repoemembers = query(RepoMember, None, 'repomember_l_userId', [user_id, offset, row_count]) joined_repos = [] for repoemember in repoemembers: repo = self.get_repo_by_id(repoemember.repo_id) if repo is None: repoemember.delete() continue joined_repos.append(repo) return joined_repos
def 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) if gsuserprofile.is_team_account == 1 and TeamManager.is_teamMember( gsuser.id, request.user.id): return HttpResponseRedirect('/%s/-/dashboard/' % user_name) recommendsForm = RecommendsForm() repos = [] if gsuser.id == request.user.id: repos = RepoManager.list_repo_by_userId(gsuser.id, 0, 100) else: repos = RepoManager.list_unprivate_repo_by_userId(gsuser.id, 0, 100) now = datetime.now() last30days = timeutils.getlast30days(now) last30days_commit = get_last30days_commit(gsuser) feedAction = FeedAction() raw_watch_repos = feedAction.get_watch_repos(gsuser.id, 0, 10) watch_repo_ids = [int(x[0]) for x in raw_watch_repos] watch_repos_map = RepoManager.merge_repo_map(watch_repo_ids) watch_repos = [ watch_repos_map[x] for x in watch_repo_ids if x in watch_repos_map ] pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 10) pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 10) feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds) star_repos = RepoManager.list_star_repo(gsuser.id, 0, 20) response_dictionary = { 'mainnav': 'user', 'title': title, 'recommendsForm': recommendsForm, 'repos': repos, 'watch_repos': watch_repos, 'star_repos': star_repos, 'last30days': last30days, 'last30days_commit': last30days_commit, 'feeds_as_json': feeds_as_json } response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/user.html', response_dictionary, context_instance=RequestContext(request))
def get_notifsetting_by_userId(self, user_id): notifSetting = query_first(NotifSetting, user_id, 'notifsetting_s_userId', [user_id]) if not notifSetting: userprofile = GsuserManager.get_userprofile_by_id(user_id) if not userprofile: return None notifSetting = NotifSetting( user_id = user_id, notif_types = 'all', notif_fqcy = 0, email = userprofile.email, ) notifSetting.save() return notifSetting
def stats(request, user_name): user = GsuserManager.get_user_by_name(user_name) if user is None: raise Http404 stats_dict = get_stats_dict(request, user) gsuserprofile = GsuserManager.get_userprofile_by_id(user.id) response_dictionary = { 'title': u'%s / 最近统计' % (user.username), 'gsuserprofile': gsuserprofile } response_dictionary.update(stats_dict) return render_to_response('user/stats.html', response_dictionary, context_instance=RequestContext(request))
def stats(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) now = datetime.now() last30days = timeutils.getlast30days(now) last30days_commit = get_last30days_commit(gsuser) response_dictionary = {'mainnav': 'user', 'title': title, 'last30days': last30days, 'last30days_commit': last30days_commit} response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/stats.html', response_dictionary, context_instance=RequestContext(request))
def list_star_user(self, repo_id, offset, row_count): stars = query(Star, None, 'star_l_repoId', [repo_id, offset, row_count]) userprofiles = [] for x in stars: user = GsuserManager.get_user_by_id(x.user_id) userprofile = GsuserManager.get_userprofile_by_id(x.user_id) if userprofile is None or userprofile.visibly == 1: x.visibly = 1 x.save() continue userprofile.date_joined = time.mktime(user.date_joined.timetuple()) userprofile.last_login = time.mktime(user.last_login.timetuple()) userprofiles.append(userprofile) return userprofiles
def list_joined_repo_by_userId(self, user_id, offset, row_count): userprofile = GsuserManager.get_userprofile_by_id(user_id) if userprofile is None or userprofile.has_joined_repo == 0: return [] repoemembers = query(RepoMember, None, 'repomember_l_userId', [user_id, offset, row_count]) joined_repos = [] for repoemember in repoemembers: repo = self.get_repo_by_id(repoemember.repo_id) if repo is None: repoemember.delete() continue joined_repos.append(repo) return joined_repos
def list_star_user(self, repo_id, offset, row_count): stars = query(Star, None, 'star_l_repoId', [repo_id, offset, row_count]) userprofiles = [] for x in stars: user = GsuserManager.get_user_by_id(x.user_id) userprofile = GsuserManager.get_userprofile_by_id(x.user_id) if userprofile is None or userprofile.visibly == 1: x.visibly = 1 x.save() continue userprofile.date_joined = time.mktime(user.date_joined.timetuple()) userprofile.last_login = time.mktime(user.last_login.timetuple()) userprofiles.append(userprofile) return userprofiles
def get_notifsetting_by_userId(self, user_id): notifSetting = query_first(NotifSetting, user_id, 'notifsetting_s_userId', [user_id]) if not notifSetting: userprofile = GsuserManager.get_userprofile_by_id(user_id) if not userprofile: return None notifSetting = NotifSetting( user_id=user_id, notif_types='all', notif_fqcy=0, email=userprofile.email, ) notifSetting.save() return notifSetting
def active(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() pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 50) pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 50) feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds) response_dictionary = {'mainnav': 'user', 'title': title, 'feeds_as_json': feeds_as_json} response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/active.html', response_dictionary, context_instance=RequestContext(request))
def group(request, username, group_id): teamUser = GsuserManager.get_user_by_name(username) teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id) teamGroup = TeamManager.get_teamGroup_by_id(group_id) if not teamGroup or teamGroup.team_user_id != teamUser.id: raise Http404 groupMembers = TeamManager.list_groupMember_by_teamGroupId(teamGroup.id) userIdInGroupSet = Set([x.member_user_id for x in groupMembers]) teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id) teamMembersNotInGroup = [x for x in teamMembers if x.user_id not in userIdInGroupSet] current = 'settings'; sub_nav = 'groups'; title = u'%s / 设置 / 组管理 / %s' % (teamUser.username, teamGroup.name) response_dictionary = {'current': current, 'sub_nav': sub_nav, 'title': title, 'teamGroup': teamGroup, 'groupMembers': groupMembers, 'teamMembersNotInGroup': teamMembersNotInGroup} response_dictionary.update(_get_common_team_dict(request, teamUser, teamUserprofile)) return render_to_response('team/group.html', response_dictionary, context_instance=RequestContext(request))
def star_repo(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) star_repos = RepoManager.list_star_repo(gsuser.id, 0, 500) response_dictionary = { 'mainnav': 'user', 'title': title, 'star_repos': star_repos } response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/star_repo.html', response_dictionary, context_instance=RequestContext(request))
def list_repo_team_memberUser(self, repo_id): repo = self.get_repo_by_id(repo_id) if not repo: return [] repoemembers = self.list_repomember(repo_id) user_ids = [x.user_id for x in repoemembers] userprofile = GsuserManager.get_userprofile_by_id(repo.user_id) if not userprofile: return [] if userprofile.is_team_account == 0: user_ids.insert(0, repo.user_id) if userprofile.is_team_account == 1: teamMembers = TeamManager.list_teamMember_by_teamUserId(userprofile.id) for x in teamMembers: if x.user_id not in user_ids: user_ids.append(x.user_id) return GsuserManager.list_userprofile_by_ids(user_ids)
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_repo_team_memberUser(self, repo_id): repo = self.get_repo_by_id(repo_id) if not repo: return [] repoemembers = self.list_repomember(repo_id) user_ids = [x.user_id for x in repoemembers] userprofile = GsuserManager.get_userprofile_by_id(repo.user_id) if not userprofile: return [] if userprofile.is_team_account == 0: user_ids.insert(0, repo.user_id) if userprofile.is_team_account == 1: teamMembers = TeamManager.list_teamMember_by_teamUserId( userprofile.id) for x in teamMembers: if x.user_id not in user_ids: user_ids.append(x.user_id) return GsuserManager.list_userprofile_by_ids(user_ids)
def groups(request, username): teamUser = GsuserManager.get_user_by_name(username) teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id) teamGroups = TeamManager.list_teamGroup_by_teamUserId(teamUser.id) current = 'settings' sub_nav = 'groups' title = u'%s / 设置 / 组管理' % (teamUser.username) response_dictionary = { 'current': current, 'sub_nav': sub_nav, 'title': title, 'teamGroups': teamGroups } response_dictionary.update( _get_common_team_dict(request, teamUser, teamUserprofile)) return render_to_response('team/groups.html', response_dictionary, context_instance=RequestContext(request))
def message_save_and_notif(self, notifMessage): notifMessage.save() userprofile = GsuserManager.get_userprofile_by_id(notifMessage.to_user_id) header = u'来自Gitshell的通知' notifSetting = self.get_notifsetting_by_userId(notifMessage.to_user_id) last_notif_time = notifSetting.last_notif_time if not last_notif_time: last_notif_time = datetime.now() notif_fqcy = notifSetting.notif_fqcy if notif_fqcy == 0: notifMessage = self._fillwith_notifMessages([notifMessage])[0] html = self.render_notifMessages_as_html(userprofile, header, [notifMessage]) Mailer().send_html_mail(header, html, None, [notifSetting.email]) if notif_fqcy > 0: expect_notif_time = last_notif_time + timedelta(minutes=notif_fqcy) if expect_notif_time != notifSetting.expect_notif_time: notifSetting.expect_notif_time = expect_notif_time notifSetting.save()
def notif_issue_status(self, user, issue, issueStatus): notif_cat = NOTIF_CATE.ISSUES message = '' if issueStatus == ISSUE_STATUS.ASSIGNED: notif_type = NOTIF_TYPE.ISSUE_ASSIGNED message = u'指派了' exists_notifMessage = self.get_notifmessage_by_userId_notifType_relativeId(issue.assigned, notif_type, issue.id) if exists_notifMessage: return assigned_userprofile = GsuserManager.get_userprofile_by_id(issue.assigned) if assigned_userprofile: notifMessage = NotifMessage.create(notif_cat, notif_type, user.id, issue.assigned, issue.id) notifMessage.message = message self.message_save_and_notif(notifMessage) assigned_userprofile.unread_message = assigned_userprofile.unread_message + 1 assigned_userprofile.save() else: return
def message_save_and_notif(self, notifMessage): notifMessage.save() userprofile = GsuserManager.get_userprofile_by_id( notifMessage.to_user_id) header = u'来自Gitshell的通知' notifSetting = self.get_notifsetting_by_userId(notifMessage.to_user_id) last_notif_time = notifSetting.last_notif_time if not last_notif_time: last_notif_time = datetime.now() notif_fqcy = notifSetting.notif_fqcy if notif_fqcy == 0: notifMessage = self._fillwith_notifMessages([notifMessage])[0] html = self.render_notifMessages_as_html(userprofile, header, [notifMessage]) Mailer().send_html_mail(header, html, None, [notifSetting.email]) if notif_fqcy > 0: expect_notif_time = last_notif_time + timedelta(minutes=notif_fqcy) if expect_notif_time != notifSetting.expect_notif_time: notifSetting.expect_notif_time = expect_notif_time notifSetting.save()
def stats(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) now = datetime.now() last30days = timeutils.getlast30days(now) last30days_commit = get_last30days_commit(gsuser) response_dictionary = { 'mainnav': 'user', 'title': title, 'last30days': last30days, 'last30days_commit': last30days_commit } response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/stats.html', response_dictionary, context_instance=RequestContext(request))
def active(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() pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 50) pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 50) feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds) response_dictionary = { 'mainnav': 'user', 'title': title, 'feeds_as_json': feeds_as_json } response_dictionary.update( get_common_user_dict(request, gsuser, gsuserprofile)) return render_to_response('user/active.html', response_dictionary, context_instance=RequestContext(request))
def notif_issue_status(self, user, issue, issueStatus): notif_cat = NOTIF_CATE.ISSUES message = '' if issueStatus == ISSUE_STATUS.ASSIGNED: notif_type = NOTIF_TYPE.ISSUE_ASSIGNED message = u'指派了' exists_notifMessage = self.get_notifmessage_by_userId_notifType_relativeId( issue.assigned, notif_type, issue.id) if exists_notifMessage: return assigned_userprofile = GsuserManager.get_userprofile_by_id( issue.assigned) if assigned_userprofile: notifMessage = NotifMessage.create(notif_cat, notif_type, user.id, issue.assigned, issue.id) notifMessage.message = message self.message_save_and_notif(notifMessage) assigned_userprofile.unread_message = assigned_userprofile.unread_message + 1 assigned_userprofile.save() else: return
def notif_at(self, notif_type, from_user_id, relative_id, message): at_name_list = FeedUtils.list_atname(message) user_unread_message_dict = {} for at_name in at_name_list: at_user = GsuserManager.get_user_by_name(at_name) if at_user is not None: to_user_id = at_user.id notifMessage = None # disable duplicate notify exists_notifMessage = self.get_notifmessage_by_userId_notifType_relativeId( to_user_id, notif_type, relative_id) if exists_notifMessage is not None: continue if notif_type == NOTIF_TYPE.AT_COMMIT: notifMessage = NotifMessage.create_at_commit( from_user_id, to_user_id, relative_id) elif notif_type == NOTIF_TYPE.AT_MERGE: notifMessage = NotifMessage.create_at_merge( from_user_id, to_user_id, relative_id) elif notif_type == NOTIF_TYPE.AT_ISSUE: notifMessage = NotifMessage.create_at_issue( from_user_id, to_user_id, relative_id) elif notif_type == NOTIF_TYPE.AT_ISSUE_COMMENT: notifMessage = NotifMessage.create_at_issue_comment( from_user_id, to_user_id, relative_id) if notifMessage is None: continue self.message_save_and_notif(notifMessage) if to_user_id not in user_unread_message_dict: user_unread_message_dict[to_user_id] = 0 user_unread_message_dict[ to_user_id] = user_unread_message_dict[to_user_id] + 1 for to_user_id, unread_message in user_unread_message_dict.items(): at_userprofile = GsuserManager.get_userprofile_by_id(to_user_id) at_userprofile.unread_message = at_userprofile.unread_message + unread_message at_userprofile.save()
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))