Exemple #1
0
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)
Exemple #2
0
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))
Exemple #3
0
def destroy_confirm(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(teamUser.id, request.user.id)
    teamRepos = RepoManager.list_repo_by_userId(teamUser.id, 0, 1000)
    for teamRepo in teamRepos:
        RepoManager.delete_repo(teamUser, teamUserprofile, teamRepo)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id)
    for teamMember in teamMembers:
        teamMember.visibly = 1
        teamMember.save()
    teamUser.delete()
    teamUserprofile.visibly = 1
    teamUserprofile.save()
    return json_success(u'已经删除了团队帐号')
Exemple #4
0
def destroy_confirm(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(
        teamUser.id, request.user.id)
    teamRepos = RepoManager.list_repo_by_userId(teamUser.id, 0, 1000)
    for teamRepo in teamRepos:
        RepoManager.delete_repo(teamUser, teamUserprofile, teamRepo)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id)
    for teamMember in teamMembers:
        teamMember.visibly = 1
        teamMember.save()
    teamUser.delete()
    teamUserprofile.visibly = 1
    teamUserprofile.save()
    return json_success(u'已经删除了团队帐号')
Exemple #5
0
def repo(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    current = 'repo'; title = u'%s / 仓库列表' % (teamUser.username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(teamUser.id, request.user.id)
    repos = []
    # is team member
    if teamMember:
        repos = RepoManager.list_repo_by_userId(teamUser.id, 0, 1000)
    else:
        repos = RepoManager.list_unprivate_repo_by_userId(teamUser.id, 0, 1000)
    response_dictionary = {'current': current, 'title': title, 'repos': repos}
    response_dictionary.update(_get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/repo.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
Exemple #6
0
def change(request):
    thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id)
    user = None
    is_user_exist = True
    is_exist_repo = False
    username = request.POST.get('username')
    if username is not None and re.match(
            "^[a-zA-Z0-9_-]+$", username
    ) and username != request.user.username and username not in MAIN_NAVS and not username.startswith(
            '-'):
        repo_count = RepoManager.count_repo_by_userId(request.user.id)
        if repo_count > 0:
            return json_httpResponse({'is_exist_repo': True})
        user = GsuserManager.get_user_by_name(username)
        if user is None:
            request.user.username = username
            request.userprofile.username = username
            request.user.save()
            request.userprofile.save()
            for repo in RepoManager.list_repo_by_userId(
                    request.user.id, 0, 100):
                repo.username = username
                repo.save()
            is_user_exist = False
    goto = ''
    email = request.POST.get('email')
    if email is not None and email_re.match(email):
        user = GsuserManager.get_user_by_email(email)
        if user is None:
            Mailer().send_change_email(request.user, email)
            email_suffix = email.split('@')[-1]
            if email_suffix in COMMON_EMAIL_DOMAIN:
                goto = COMMON_EMAIL_DOMAIN[email_suffix]
            is_user_exist = False
    if thirdpartyUser is not None:
        thirdpartyUser.init = 1
        thirdpartyUser.save()
    if username == request.user.username:
        is_user_exist = False
    response_dictionary = {
        'is_exist_repo': is_exist_repo,
        'is_user_exist': is_user_exist,
        'goto': goto,
        'new_username': username,
        'new_email': email
    }
    return json_httpResponse(response_dictionary)
Exemple #7
0
def repo(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    current = 'repo'
    title = u'%s / 仓库列表' % (teamUser.username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(
        teamUser.id, request.user.id)
    repos = []
    # is team member
    if teamMember:
        repos = RepoManager.list_repo_by_userId(teamUser.id, 0, 1000)
    else:
        repos = RepoManager.list_unprivate_repo_by_userId(teamUser.id, 0, 1000)
    response_dictionary = {'current': current, 'title': title, 'repos': repos}
    response_dictionary.update(
        _get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/repo.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Exemple #8
0
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))
Exemple #9
0
def change(request):
    thirdpartyUser = GsuserManager.get_thirdpartyUser_by_id(request.user.id)
    user = None
    is_user_exist = True
    is_exist_repo = False
    username = request.POST.get('username')
    if username is not None and re.match("^[a-zA-Z0-9_-]+$", username) and username != request.user.username and username not in MAIN_NAVS and not username.startswith('-'):
        repo_count = RepoManager.count_repo_by_userId(request.user.id)
        if repo_count > 0:
            return json_httpResponse({'is_exist_repo': True})
        user = GsuserManager.get_user_by_name(username)
        if user is None:
            request.user.username = username
            request.userprofile.username = username
            request.user.save()
            request.userprofile.save()
            for repo in RepoManager.list_repo_by_userId(request.user.id, 0, 100):
                repo.username = username
                repo.save()
            is_user_exist = False
    goto = ''
    email = request.POST.get('email')
    if email is not None and email_re.match(email):
        user = GsuserManager.get_user_by_email(email)
        if user is None:
            Mailer().send_change_email(request.user, email)
            email_suffix = email.split('@')[-1]
            if email_suffix in COMMON_EMAIL_DOMAIN:
                goto = COMMON_EMAIL_DOMAIN[email_suffix]
            is_user_exist = False
    if thirdpartyUser is not None:
        thirdpartyUser.init = 1
        thirdpartyUser.save()
    if username == request.user.username:
        is_user_exist = False
    response_dictionary = { 'is_exist_repo': is_exist_repo, 'is_user_exist': is_user_exist, 'goto': goto, 'new_username': username, 'new_email': email }
    return json_httpResponse(response_dictionary)
Exemple #10
0
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)