Beispiel #1
0
    def _fillwith_notifMessages(self, notifMessages):
        repo_ids = [x.repo_id for x in notifMessages]
        userprofile_ids = [x.user_id for x in notifMessages]
        repo_dict = dict(
            (x.id, x) for x in RepoManager.list_repo_by_ids(repo_ids))
        userprofile_dict = dict(
            (x.id, x)
            for x in GsuserManager.list_userprofile_by_ids(userprofile_ids))
        for notifMessage in notifMessages:
            if notifMessage.repo_id in repo_dict:
                notifMessage.repo = repo_dict[notifMessage.repo_id]
            if notifMessage.from_user_id in userprofile_dict:
                notifMessage.from_userprofile = userprofile_dict[
                    notifMessage.from_user_id]

            if notifMessage.is_at_commit():
                commitHistory = RepoManager.get_commit_by_id(
                    notifMessage.relative_id)
                notifMessage.relative_obj = commitHistory
            elif notifMessage.is_at_issue() or notifMessage.is_issue_cate():
                issue = IssueManager.get_issue_by_id(notifMessage.relative_id)
                notifMessage.relative_obj = issue
            elif notifMessage.is_at_merge(
            ) or notifMessage.is_pull_request_cate():
                pullRequest = RepoManager.get_pullRequest_by_id(
                    notifMessage.relative_id)
                notifMessage.relative_obj = pullRequest
            elif notifMessage.is_at_issue_comment():
                issue_comment = IssueManager.get_issue_comment(
                    notifMessage.relative_id)
                notifMessage.relative_obj = issue_comment
        return notifMessages
Beispiel #2
0
def comment_delete(request, user_name, repo_name, comment_id):
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        return _json_failed()
    issue_comment = IssueManager.get_issue_comment(comment_id)
    if issue_comment is None:
        return _json_failed()
    issue = IssueManager.get_issue(repo.id, issue_comment.issue_id)
    if issue is None or not _has_issue_comment_modify_right(request, issue_comment, repo):
        return _json_failed()
    issue_comment.visibly = 1
    issue_comment.save()
    issue.comment_count = issue.comment_count - 1
    issue.save()
    return _json_ok()
Beispiel #3
0
def issues(request, username, page):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    current = 'issues'
    title = u'%s / 问题' % (teamUser.username)
    feedAction = FeedAction()
    feedAction.set_user_position(teamUser.id, PositionKey.ISSUES)
    page = int(page)
    page_size = 50
    offset = page * page_size
    row_count = page_size + 1
    issues = IssueManager.list_issues_by_teamUserId_assigned(
        teamUser.id, request.user.id, 'modify_time', offset, row_count)

    hasPre = False
    hasNext = False
    if page > 0:
        hasPre = True
    if len(issues) > page_size:
        hasNext = True
        issues.pop()
    response_dictionary = {
        'current': current,
        'title': title,
        'issues': issues,
        'page': page,
        'hasPre': hasPre,
        'hasNext': hasNext
    }
    response_dictionary.update(
        _get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/issues.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Beispiel #4
0
def do_issue(request):
    action = request.POST.get('action', '')
    comment = request.POST.get('comment', '')
    repo_id = request.POST.get('repo_id', '')
    issue_id = request.POST.get('issue_id', '')
    if action == '' or repo_id == '' or issue_id == '':
        return _json_failed()
    repo = RepoManager.get_repo_by_id(int(repo_id))
    issue = IssueManager.get_issue(int(repo_id), int(issue_id))
    if repo is None or issue is None:
        return _json_failed()
    if issue.assigned != request.user.id and repo.user_id != request.user.id:
        return _json_failed()
    orgi_issue = copy.copy(issue)
    if action == 'fixed':
        issue.status = 4
    elif action == 'close':
        issue.status = 5
    elif action == 'reject':
        issue.status = 6
    if comment != '':
        issueComment = IssueComment() 
        issueComment.issue_id = issue.id
        issueComment.user_id = request.user.id
        issueComment.content = comment
        issueComment.save()
        issue.comment_count = issue.comment_count + 1
    issue.save()
    FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id)
    return _json_ok()
Beispiel #5
0
def update(request, user_name, repo_name, issue_id, attr):
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    if issue is None:
        return _json_failed()
    has_issue_modify_right = _has_issue_modify_right(request, issue, repo)
    if not has_issue_modify_right:
        return _json_failed()
    orgi_issue = copy.copy(issue)
    (key, value) = attr.split('___', 1)
    if key == 'assigned':
        user = GsuserManager.get_user_by_name(value)
        if user is None:
            return _json_failed()
        repoMember = RepoManager.get_repo_member(repo.id, user.id)
        if repoMember is None:
            return _json_failed()
        issue.assigned = repoMember.user_id
        issue.save()
        FeedManager.notif_issue_status(request.user, issue, ISSUE_STATUS.ASSIGNED)
        FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id)
        return _json_ok()
    value = int(value)
    if key == 'tracker':
        issue.tracker = value
    elif key == 'status':
        issue.status = value
    elif key == 'priority':
        issue.priority = value
    issue.save()
    FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id)
    return _json_ok()
Beispiel #6
0
def edit(request, user_name, repo_name, issue_id):
    refs = 'master'; path = '.'; current = 'issues'; title = u'%s / %s / 编辑问题' % (user_name, repo_name)
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    has_issue_modify = _has_issue_modify_right(request, issue, repo)
    if issue is None or not has_issue_modify:
        raise Http404
    orgi_issue = copy.copy(issue)
    issueForm = IssueForm(instance = issue)
    issueForm.fill_assigned(repo)
    error = u''
    if request.method == 'POST':
        issueForm = IssueForm(request.POST, instance = issue)
        issueForm.fill_assigned(repo)
        if issueForm.is_valid():
            newIssue = issueForm.save()
            nid = newIssue.id
            FeedManager.notif_issue_at(request.user.id, nid, issueForm.cleaned_data['subject'] + ' ' + issueForm.cleaned_data['content'])
            FeedManager.notif_issue_status(request.user, newIssue, ISSUE_STATUS.ASSIGNED)
            FeedManager.feed_issue_change(request.user, repo, orgi_issue, nid)
            return HttpResponseRedirect('/%s/%s/issues/%s/' % (user_name, repo_name, nid))
        else:
            error = u'issue 内容不能为空'
    response_dictionary = {'mainnav': 'repo', 'current': current, 'title': title, 'path': path, 'issueForm': issueForm, 'error': error, 'issue_id': issue_id}
    response_dictionary.update(ISSUE_ATTRS)
    response_dictionary.update(get_common_repo_dict(request, repo, user_name, repo_name, refs))
    return render_to_response('repo/issue_edit.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
Beispiel #7
0
def comment_delete(request, user_name, repo_name, comment_id):
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        return _json_failed()
    issue_comment = IssueManager.get_issue_comment(comment_id)
    if issue_comment is None:
        return _json_failed()
    issue = IssueManager.get_issue(repo.id, issue_comment.issue_id)
    if issue is None or not _has_issue_comment_modify_right(
            request, issue_comment, repo):
        return _json_failed()
    issue_comment.visibly = 1
    issue_comment.save()
    issue.comment_count = issue.comment_count - 1
    issue.save()
    return _json_ok()
Beispiel #8
0
def do_issue(request):
    action = request.POST.get('action', '')
    comment = request.POST.get('comment', '')
    repo_id = request.POST.get('repo_id', '')
    issue_id = request.POST.get('issue_id', '')
    if action == '' or repo_id == '' or issue_id == '':
        return _json_failed()
    repo = RepoManager.get_repo_by_id(int(repo_id))
    issue = IssueManager.get_issue(int(repo_id), int(issue_id))
    if repo is None or issue is None:
        return _json_failed()
    if issue.assigned != request.user.id and repo.user_id != request.user.id:
        return _json_failed()
    orgi_issue = copy.copy(issue)
    if action == 'fixed':
        issue.status = 4
    elif action == 'close':
        issue.status = 5
    elif action == 'reject':
        issue.status = 6
    if comment != '':
        issueComment = IssueComment()
        issueComment.issue_id = issue.id
        issueComment.user_id = request.user.id
        issueComment.content = comment
        issueComment.save()
        issue.comment_count = issue.comment_count + 1
    issue.save()
    FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id)
    return _json_ok()
Beispiel #9
0
def update(request, user_name, repo_name, issue_id, attr):
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    if issue is None:
        return _json_failed()
    has_issue_modify_right = _has_issue_modify_right(request, issue, repo)
    if not has_issue_modify_right:
        return _json_failed()
    orgi_issue = copy.copy(issue)
    (key, value) = attr.split('___', 1)
    if key == 'assigned':
        user = GsuserManager.get_user_by_name(value)
        if user is None:
            return _json_failed()
        repoMember = RepoManager.get_repo_member(repo.id, user.id)
        if repoMember is None:
            return _json_failed()
        issue.assigned = repoMember.user_id
        issue.save()
        FeedManager.notif_issue_status(request.user, issue,
                                       ISSUE_STATUS.ASSIGNED)
        FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id)
        return _json_ok()
    value = int(value)
    if key == 'tracker':
        issue.tracker = value
    elif key == 'status':
        issue.status = value
    elif key == 'priority':
        issue.priority = value
    issue.save()
    FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id)
    return _json_ok()
Beispiel #10
0
def issues(request, page):
    current = 'issues'
    title = u'%s / 问题' % (request.user.username)
    feedAction = FeedAction()
    feedAction.set_user_position(request.user.id, PositionKey.ISSUES)
    recently_timestamp = feedAction.get_recently_timestamp(
        request.user.id, AttrKey.RECENTLY_TIME_ISSUES)
    page = int(page)
    page_size = 50
    offset = page * page_size
    row_count = page_size + 1
    issues = IssueManager.list_assigned_issues(request.user.id, 'modify_time',
                                               offset, row_count)

    hasPre = False
    hasNext = False
    if page > 0:
        hasPre = True
    if len(issues) > page_size:
        hasNext = True
        issues.pop()
    feedAction.set_recently_timestamp_now(request.user.id,
                                          AttrKey.RECENTLY_TIME_ISSUES)
    response_dictionary = {
        'current': current,
        'title': title,
        'issues': issues,
        'page': page,
        'hasPre': hasPre,
        'hasNext': hasNext,
        'recently_timestamp': recently_timestamp
    }
    return render_to_response('user/issues.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Beispiel #11
0
def show(request, user_name, repo_name, issue_id, page):
    refs = 'master'; path = '.'; current = 'issues'
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    if issue is None:
        raise Http404
    issueCommentForm = IssueCommentForm()
    if request.method == 'POST' and request.user.is_authenticated():
        issueComment = IssueComment() 
        issueComment.issue_id = issue_id
        issueComment.user_id = request.user.id
        issueCommentForm = IssueCommentForm(request.POST, instance = issueComment)
        if issueCommentForm.is_valid():
            cid = issueCommentForm.save().id
            FeedManager.notif_issue_comment_at(request.user.id, cid, issueCommentForm.cleaned_data['content'])
            issue.comment_count = issue.comment_count + 1
            issue.save()
            return HttpResponseRedirect('/%s/%s/issues/%s/' % (user_name, repo_name, issue_id))
    
    page_size = 50; total_count = issue.comment_count; total_page = total_count / page_size
    if total_count != 0 and total_count % page_size == 0:
        total_page = total_page - 1
    if page is None or int(page) > total_page:
        page = total_page
    page = int(page)
    issue_comments = []
    if total_count > 0:
        offset = page*page_size; row_count = page_size
        issue_comments = IssueManager.list_issue_comments(issue_id, offset, row_count)

    memberUsers = RepoManager.list_repo_team_memberUser(repo.id)
    memberUsers = _let_request_user_first(memberUsers, request.user.id)
    assigneds = [x.username for x in memberUsers]

    has_issue_modify_right = _has_issue_modify_right(request, issue, repo)
    title = u'%s / %s / 问题:%s' % (user_name, repo_name, issue.subject)
    response_dictionary = {'mainnav': 'repo', 'current': current, 'title': title, 'path': path, 'issue': issue, 'issue_comments': issue_comments, 'issueCommentForm': issueCommentForm, 'page': page, 'total_page': range(0, total_page+1), 'assigneds': assigneds, 'assigned': issue.assigned, 'tracker': issue.tracker, 'status': issue.status, 'priority': issue.priority, 'has_issue_modify_right': has_issue_modify_right}
    response_dictionary.update(ISSUE_ATTRS)
    response_dictionary.update(get_common_repo_dict(request, repo, user_name, repo_name, refs))
    return render_to_response('repo/issue_show.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
Beispiel #12
0
def issues_list(request, user_name, repo_name, assigned, tracker, status, priority, orderby, page):
    refs = 'master'; path = '.'; current = 'issues'; title = u'%s / %s / 问题列表' % (user_name, repo_name)
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    user_id = request.user.id
    memberUsers = RepoManager.list_repo_team_memberUser(repo.id)
    memberUsers = _let_request_user_first(memberUsers, user_id)
    member_ids = [x.id for x in memberUsers]
    assigneds = [x.username for x in memberUsers]
    assigneds.insert(0, '0')
    if assigned is None:
        assigned = assigneds[0]
    assigned_id = 0
    assigned_user = GsuserManager.get_user_by_name(assigned)
    if assigned_user is not None and assigned in assigneds:
        assigned_id = assigned_user.id
    tracker = int(tracker); status = int(status); priority = int(priority); page = int(page)
    current_attrs = { 'assigned': str(assigned), 'tracker': tracker, 'status': status, 'priority': priority, 'orderby': str(orderby), 'page': page }

    issues = []
    page_size = 50; offset = page*page_size; row_count = page_size + 1
    if assigned_id == 0 and tracker == 0 and status == 0 and priority == 0:
        issues = IssueManager.list_issues(repo.id, orderby, offset, row_count)
    else:
        assigned_ids = member_ids if assigned_id == 0 else [assigned_id]
        trackeres = TRACKERS_VAL if tracker == 0 else [tracker]
        statuses = STATUSES_VAL if status == 0 else [status]
        priorities = PRIORITIES_VAL if priority == 0 else [priority] 
        issues = IssueManager.list_issues_cons(repo.id, assigned_ids, trackeres, statuses, priorities, orderby, offset, row_count)

    hasPre = False ; hasNext = False
    if page > 0:
        hasPre = True 
    if len(issues) > page_size:
        hasNext = True
        issues.pop()
    
    response_dictionary = {'mainnav': 'repo', 'current': current, 'title': title, 'path': path, 'assigneds': assigneds, 'assigned': assigned, 'tracker': tracker, 'status': status, 'priority': priority, 'orderby': orderby, 'page': page, 'current_attrs': current_attrs, 'issues': issues, 'hasPre': hasPre, 'hasNext': hasNext}
    response_dictionary.update(ISSUE_ATTRS)
    response_dictionary.update(get_common_repo_dict(request, repo, user_name, repo_name, refs))
    return render_to_response('repo/issues.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
Beispiel #13
0
def delete(request, user_name, repo_name, issue_id):
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    if issue is not None:
        if _has_issue_modify_right(request, issue, repo):
            issue.visibly = 1
            issue.save()
    return _json_ok()
Beispiel #14
0
def delete(request, user_name, repo_name, issue_id):
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    if issue is not None:
        if _has_issue_modify_right(request, issue, repo):
            issue.visibly = 1
            issue.save()
    return _json_ok()
Beispiel #15
0
 def create(self, notif_cate, notif_type, from_user_id, to_user_id,
            relative_id):
     notifMessage = NotifMessage(
         notif_cate=notif_cate,
         notif_type=notif_type,
         from_user_id=from_user_id,
         to_user_id=to_user_id,
         relative_id=relative_id,
     )
     if not relative_id:
         return notifMessage
     # without AT_MERGE_COMMENT
     if notifMessage.is_at_commit():
         commitHistory = RepoManager.get_commit_by_id(relative_id)
         if commitHistory:
             repo = RepoManager.get_repo_by_id(commitHistory.repo_id)
             if repo:
                 notifMessage.user_id = repo.user_id
                 notifMessage.repo_id = repo.id
     elif notifMessage.is_at_issue() or notifMessage.is_issue_cate():
         issue = IssueManager.get_issue_by_id(relative_id)
         if issue:
             notifMessage.user_id = issue.user_id
             notifMessage.repo_id = issue.repo_id
     elif notifMessage.is_at_merge() or notifMessage.is_pull_request_cate():
         pullRequest = RepoManager.get_pullRequest_by_id(relative_id)
         if pullRequest:
             repo = RepoManager.get_repo_by_id(pullRequest.desc_repo_id)
             if repo:
                 notifMessage.user_id = repo.user_id
                 notifMessage.repo_id = repo.id
     elif notifMessage.is_at_issue_comment():
         issue_comment = IssueManager.get_issue_comment(relative_id)
         if issue_comment:
             issue = IssueManager.get_issue_by_id(issue_comment.issue_id)
             if issue:
                 notifMessage.user_id = issue.user_id
                 notifMessage.repo_id = issue.repo_id
     return notifMessage
Beispiel #16
0
    def feed_issue_change(self, user, repo, orgi_issue, current_issue_id):
        current_issue = IssueManager.get_issue_by_id(current_issue_id)
        if current_issue is None:
            return
        feed_cate = FEED_CATE.ISSUES
        message = ''
        if orgi_issue is None and current_issue is not None:
            feed_type = FEED_TYPE.ISSUES_CREATE
            message = u'新建了问题'
        if orgi_issue is not None and (
                orgi_issue.subject != current_issue.subject
                or orgi_issue.content != current_issue.content
                or orgi_issue.category != current_issue.category):
            feed_type = FEED_TYPE.ISSUES_UPDATE
            message = u'更新了问题'
        # status update
        status_changes = []
        if orgi_issue is not None:
            if orgi_issue.tracker != current_issue.tracker:
                status_changes.append(
                    u'跟踪: ' + ISSUE_ATTR_DICT.TRACKER[current_issue.tracker])
            if orgi_issue.status != current_issue.status:
                status_changes.append(
                    u'状态: ' + ISSUE_ATTR_DICT.STATUS[current_issue.status])
            if orgi_issue.assigned != current_issue.assigned:
                assigned_user = GsuserManager.get_user_by_id(
                    current_issue.assigned)
                if assigned_user is not None:
                    status_changes.append(u'指派给: @' + assigned_user.username)
            if orgi_issue.priority != current_issue.priority:
                status_changes.append(
                    u'优先级: ' +
                    ISSUE_ATTR_DICT.PRIORITY[current_issue.priority])

            if len(status_changes) > 0:
                message = ', '.join(status_changes)
                feed_type = FEED_TYPE.ISSUES_STATUS_CHANGE

        if message != '':
            feed = Feed.create(user.id, repo.id, feed_cate, feed_type,
                               current_issue.id)
            # TODO
            feed.first_refname = message
            feed.save()
            feedAction = FeedAction()
            timestamp = float(time.mktime(feed.create_time.timetuple()))
            feedAction.add_repo_feed(repo.id, timestamp, feed.id)
            if repo.auth_type == 2:
                feedAction.add_pri_user_feed(user.id, timestamp, feed.id)
            else:
                feedAction.add_pub_user_feed(user.id, timestamp, feed.id)
Beispiel #17
0
 def create(self, notif_cate, notif_type, from_user_id, to_user_id, relative_id):
     notifMessage = NotifMessage(
         notif_cate = notif_cate,
         notif_type = notif_type,
         from_user_id = from_user_id,
         to_user_id = to_user_id,
         relative_id = relative_id,
     )
     if not relative_id:
         return notifMessage
     # without AT_MERGE_COMMENT
     if notifMessage.is_at_commit():
         commitHistory = RepoManager.get_commit_by_id(relative_id)
         if commitHistory:
             repo = RepoManager.get_repo_by_id(commitHistory.repo_id)
             if repo:
                 notifMessage.user_id = repo.user_id
                 notifMessage.repo_id = repo.id
     elif notifMessage.is_at_issue() or notifMessage.is_issue_cate():
         issue = IssueManager.get_issue_by_id(relative_id)
         if issue:
             notifMessage.user_id = issue.user_id
             notifMessage.repo_id = issue.repo_id
     elif notifMessage.is_at_merge() or notifMessage.is_pull_request_cate():
         pullRequest = RepoManager.get_pullRequest_by_id(relative_id)
         if pullRequest:
             repo = RepoManager.get_repo_by_id(pullRequest.desc_repo_id)
             if repo:
                 notifMessage.user_id = repo.user_id
                 notifMessage.repo_id = repo.id
     elif notifMessage.is_at_issue_comment():
         issue_comment = IssueManager.get_issue_comment(relative_id)
         if issue_comment:
             issue = IssueManager.get_issue_by_id(issue_comment.issue_id)
             if issue:
                 notifMessage.user_id = issue.user_id
                 notifMessage.repo_id = issue.repo_id
     return notifMessage
Beispiel #18
0
    def _fillwith_notifMessages(self, notifMessages):
        repo_ids = [x.repo_id for x in notifMessages]
        userprofile_ids = [x.user_id for x in notifMessages]
        repo_dict = dict((x.id, x) for x in RepoManager.list_repo_by_ids(repo_ids))
        userprofile_dict = dict((x.id, x) for x in GsuserManager.list_userprofile_by_ids(userprofile_ids))
        for notifMessage in notifMessages:
            if notifMessage.repo_id in repo_dict:
                notifMessage.repo = repo_dict[notifMessage.repo_id]
            if notifMessage.from_user_id in userprofile_dict:
                notifMessage.from_userprofile = userprofile_dict[notifMessage.from_user_id]

            if notifMessage.is_at_commit():
                commitHistory = RepoManager.get_commit_by_id(notifMessage.relative_id)
                notifMessage.relative_obj = commitHistory
            elif notifMessage.is_at_issue() or notifMessage.is_issue_cate():
                issue = IssueManager.get_issue_by_id(notifMessage.relative_id)
                notifMessage.relative_obj = issue
            elif notifMessage.is_at_merge() or notifMessage.is_pull_request_cate():
                pullRequest = RepoManager.get_pullRequest_by_id(notifMessage.relative_id)
                notifMessage.relative_obj = pullRequest
            elif notifMessage.is_at_issue_comment():
                issue_comment = IssueManager.get_issue_comment(notifMessage.relative_id)
                notifMessage.relative_obj = issue_comment
        return notifMessages
Beispiel #19
0
def edit(request, user_name, repo_name, issue_id):
    refs = 'master'
    path = '.'
    current = 'issues'
    title = u'%s / %s / 编辑问题' % (user_name, repo_name)
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    has_issue_modify = _has_issue_modify_right(request, issue, repo)
    if issue is None or not has_issue_modify:
        raise Http404
    orgi_issue = copy.copy(issue)
    issueForm = IssueForm(instance=issue)
    issueForm.fill_assigned(repo)
    error = u''
    if request.method == 'POST':
        issueForm = IssueForm(request.POST, instance=issue)
        issueForm.fill_assigned(repo)
        if issueForm.is_valid():
            newIssue = issueForm.save()
            nid = newIssue.id
            FeedManager.notif_issue_at(
                request.user.id, nid, issueForm.cleaned_data['subject'] + ' ' +
                issueForm.cleaned_data['content'])
            FeedManager.notif_issue_status(request.user, newIssue,
                                           ISSUE_STATUS.ASSIGNED)
            FeedManager.feed_issue_change(request.user, repo, orgi_issue, nid)
            return HttpResponseRedirect('/%s/%s/issues/%s/' %
                                        (user_name, repo_name, nid))
        else:
            error = u'issue 内容不能为空'
    response_dictionary = {
        'mainnav': 'repo',
        'current': current,
        'title': title,
        'path': path,
        'issueForm': issueForm,
        'error': error,
        'issue_id': issue_id
    }
    response_dictionary.update(ISSUE_ATTRS)
    response_dictionary.update(
        get_common_repo_dict(request, repo, user_name, repo_name, refs))
    return render_to_response('repo/issue_edit.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Beispiel #20
0
def issues(request, username, page):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    current = 'issues'; title = u'%s / 问题' % (teamUser.username)
    feedAction = FeedAction()
    feedAction.set_user_position(teamUser.id, PositionKey.ISSUES)
    page = int(page); page_size = 50; offset = page*page_size; row_count = page_size + 1
    issues = IssueManager.list_issues_by_teamUserId_assigned(teamUser.id, request.user.id, 'modify_time', offset, row_count)

    hasPre = False ; hasNext = False
    if page > 0:
        hasPre = True 
    if len(issues) > page_size:
        hasNext = True
        issues.pop()
    response_dictionary = {'current': current, 'title': title, 'issues': issues, 'page': page, 'hasPre': hasPre, 'hasNext': hasNext}
    response_dictionary.update(_get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/issues.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
Beispiel #21
0
    def feed_issue_change(self, user, repo, orgi_issue, current_issue_id):
        current_issue = IssueManager.get_issue_by_id(current_issue_id)
        if current_issue is None:
            return
        feed_cate = FEED_CATE.ISSUES
        message = ''
        if orgi_issue is None and current_issue is not None:
            feed_type = FEED_TYPE.ISSUES_CREATE
            message = u'新建了问题'
        if orgi_issue is not None and (orgi_issue.subject != current_issue.subject or orgi_issue.content != current_issue.content or orgi_issue.category != current_issue.category):
            feed_type = FEED_TYPE.ISSUES_UPDATE
            message = u'更新了问题'
        # status update
        status_changes = []
        if orgi_issue is not None:
            if orgi_issue.tracker != current_issue.tracker:
                status_changes.append(u'跟踪: ' + ISSUE_ATTR_DICT.TRACKER[current_issue.tracker])
            if orgi_issue.status != current_issue.status:
                status_changes.append(u'状态: ' + ISSUE_ATTR_DICT.STATUS[current_issue.status])
            if orgi_issue.assigned != current_issue.assigned:
                assigned_user = GsuserManager.get_user_by_id(current_issue.assigned)
                if assigned_user is not None:
                    status_changes.append(u'指派给: @' + assigned_user.username)
            if orgi_issue.priority != current_issue.priority:
                status_changes.append(u'优先级: ' + ISSUE_ATTR_DICT.PRIORITY[current_issue.priority])
            
            if len(status_changes) > 0:
                message = ', '.join(status_changes)
                feed_type = FEED_TYPE.ISSUES_STATUS_CHANGE

        if message != '':
            feed = Feed.create(user.id, repo.id, feed_cate, feed_type, current_issue.id)
            # TODO
            feed.first_refname = message
            feed.save()
            feedAction = FeedAction()
            timestamp = float(time.mktime(feed.create_time.timetuple()))
            feedAction.add_repo_feed(repo.id, timestamp, feed.id)
            if repo.auth_type == 2:
                feedAction.add_pri_user_feed(user.id, timestamp, feed.id)
            else:
                feedAction.add_pub_user_feed(user.id, timestamp, feed.id)
Beispiel #22
0
def show(request, user_name, repo_name, issue_id, page):
    refs = 'master'
    path = '.'
    current = 'issues'
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    issue = IssueManager.get_issue(repo.id, issue_id)
    if issue is None:
        raise Http404
    issueCommentForm = IssueCommentForm()
    if request.method == 'POST' and request.user.is_authenticated():
        issueComment = IssueComment()
        issueComment.issue_id = issue_id
        issueComment.user_id = request.user.id
        issueCommentForm = IssueCommentForm(request.POST,
                                            instance=issueComment)
        if issueCommentForm.is_valid():
            cid = issueCommentForm.save().id
            FeedManager.notif_issue_comment_at(
                request.user.id, cid, issueCommentForm.cleaned_data['content'])
            issue.comment_count = issue.comment_count + 1
            issue.save()
            return HttpResponseRedirect('/%s/%s/issues/%s/' %
                                        (user_name, repo_name, issue_id))

    page_size = 50
    total_count = issue.comment_count
    total_page = total_count / page_size
    if total_count != 0 and total_count % page_size == 0:
        total_page = total_page - 1
    if page is None or int(page) > total_page:
        page = total_page
    page = int(page)
    issue_comments = []
    if total_count > 0:
        offset = page * page_size
        row_count = page_size
        issue_comments = IssueManager.list_issue_comments(
            issue_id, offset, row_count)

    memberUsers = RepoManager.list_repo_team_memberUser(repo.id)
    memberUsers = _let_request_user_first(memberUsers, request.user.id)
    assigneds = [x.username for x in memberUsers]

    has_issue_modify_right = _has_issue_modify_right(request, issue, repo)
    title = u'%s / %s / 问题:%s' % (user_name, repo_name, issue.subject)
    response_dictionary = {
        'mainnav': 'repo',
        'current': current,
        'title': title,
        'path': path,
        'issue': issue,
        'issue_comments': issue_comments,
        'issueCommentForm': issueCommentForm,
        'page': page,
        'total_page': range(0, total_page + 1),
        'assigneds': assigneds,
        'assigned': issue.assigned,
        'tracker': issue.tracker,
        'status': issue.status,
        'priority': issue.priority,
        'has_issue_modify_right': has_issue_modify_right
    }
    response_dictionary.update(ISSUE_ATTRS)
    response_dictionary.update(
        get_common_repo_dict(request, repo, user_name, repo_name, refs))
    return render_to_response('repo/issue_show.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Beispiel #23
0
def issues_list(request, user_name, repo_name, assigned, tracker, status,
                priority, orderby, page):
    refs = 'master'
    path = '.'
    current = 'issues'
    title = u'%s / %s / 问题列表' % (user_name, repo_name)
    repo = RepoManager.get_repo_by_name(user_name, repo_name)
    if repo is None:
        raise Http404
    user_id = request.user.id
    memberUsers = RepoManager.list_repo_team_memberUser(repo.id)
    memberUsers = _let_request_user_first(memberUsers, user_id)
    member_ids = [x.id for x in memberUsers]
    assigneds = [x.username for x in memberUsers]
    assigneds.insert(0, '0')
    if assigned is None:
        assigned = assigneds[0]
    assigned_id = 0
    assigned_user = GsuserManager.get_user_by_name(assigned)
    if assigned_user is not None and assigned in assigneds:
        assigned_id = assigned_user.id
    tracker = int(tracker)
    status = int(status)
    priority = int(priority)
    page = int(page)
    current_attrs = {
        'assigned': str(assigned),
        'tracker': tracker,
        'status': status,
        'priority': priority,
        'orderby': str(orderby),
        'page': page
    }

    issues = []
    page_size = 50
    offset = page * page_size
    row_count = page_size + 1
    if assigned_id == 0 and tracker == 0 and status == 0 and priority == 0:
        issues = IssueManager.list_issues(repo.id, orderby, offset, row_count)
    else:
        assigned_ids = member_ids if assigned_id == 0 else [assigned_id]
        trackeres = TRACKERS_VAL if tracker == 0 else [tracker]
        statuses = STATUSES_VAL if status == 0 else [status]
        priorities = PRIORITIES_VAL if priority == 0 else [priority]
        issues = IssueManager.list_issues_cons(repo.id, assigned_ids,
                                               trackeres, statuses, priorities,
                                               orderby, offset, row_count)

    hasPre = False
    hasNext = False
    if page > 0:
        hasPre = True
    if len(issues) > page_size:
        hasNext = True
        issues.pop()

    response_dictionary = {
        'mainnav': 'repo',
        'current': current,
        'title': title,
        'path': path,
        'assigneds': assigneds,
        'assigned': assigned,
        'tracker': tracker,
        'status': status,
        'priority': priority,
        'orderby': orderby,
        'page': page,
        'current_attrs': current_attrs,
        'issues': issues,
        'hasPre': hasPre,
        'hasNext': hasNext
    }
    response_dictionary.update(ISSUE_ATTRS)
    response_dictionary.update(
        get_common_repo_dict(request, repo, user_name, repo_name, refs))
    return render_to_response('repo/issues.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Beispiel #24
0
def _fillwith_issue_event(request, feeds):
    for feed in feeds:
        if not feed.is_issue_event():
            continue
        issue = IssueManager.get_issue_by_id(feed.relative_id)
        feed.relative_obj = issue