Example #1
0
    def test_delete(self):
        name = "tag"
        author = "test"
        target_type = 2
        target_id = 3
        newtag = TagName.add(name, author, target_type, target_id)
        newtag.delete()
        tag = TagName.get_by_name_and_target_id(name, target_type, target_id)
        assert tag is None

        tag = TagName.get_by_id(newtag.id)
        assert tag is None
Example #2
0
    def test_delete(self):
        name = "tag"
        author = "test"
        target_type = 2
        target_id = 3
        newtag = TagName.add(name, author, target_type, target_id)
        newtag.delete()
        tag = TagName.get_by_name_and_target_id(name, target_type, target_id)
        assert tag is None

        tag = TagName.get_by_id(newtag.id)
        assert tag is None
Example #3
0
 def add_tag(self, tag, type, target_id, author=None):
     author_id = author if author else self.creator_id
     # create tag if not exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         tag_name = TagName.add(tag, author_id, type, target_id)
     if not tag_name:
         return
     # add tag to issue if not already be added
     issue_tag = Tag.get_by_type_id_and_tag_id(type, self.issue_id,
                                               tag_name.id)
     if issue_tag:
         return
     Tag.add_to_issue(tag_name.id, type, self.issue_id, author_id,
                      target_id)
Example #4
0
 def add_tag(self, tag, type, target_id, author=None):
     author_id = author if author else self.creator_id
     # create tag if not exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         tag_name = TagName.add(tag, author_id, type, target_id)
     if not tag_name:
         return
     # add tag to issue if not already be added
     issue_tag = Tag.get_by_type_id_and_tag_id(
         type, self.issue_id, tag_name.id)
     if issue_tag:
         return
     Tag.add_to_issue(
         tag_name.id, type, self.issue_id, author_id, target_id)
Example #5
0
    def test_gets_by_tag_id(self):
        name = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name = TagName.add(name, author, target_type, target_id)
        assert tag_name.name == name

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        tags = Tag.gets_by_tag_id(tag_name.id)

        assert len(tags) == 3

        type_ids = [t.type_id for t in tags]
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids
Example #6
0
    def test_gets_by_tag_id(self):
        name = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name = TagName.add(name, author, target_type, target_id)
        assert tag_name.name == name

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        tags = Tag.gets_by_tag_id(tag_name.id)

        assert len(tags) == 3

        type_ids = [t.type_id for t in tags]
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids
Example #7
0
 def _q_lookup(self, request, part):
     # TODO: check no '/' in tag name
     name = part
     target_type = self.target.tag_type
     target_id = self.target.id
     tag = TagName.get_by_name_and_target_id(name, target_type, target_id)
     if tag:
         return TagUI(self.target, tag)
     raise TraversalError
Example #8
0
 def _q_lookup(self, request, part):
     # TODO: check no '/' in tag name
     name = part
     target_type = self.target.tag_type
     target_id = self.target.id
     tag = TagName.get_by_name_and_target_id(name, target_type, target_id)
     if tag:
         return TagUI(self.target, tag)
     raise TraversalError
Example #9
0
 def test_add(self):
     name = "tag"
     author = "test"
     target_type = 2
     target_id = 3
     tag = TagName.add(name, author, target_type, target_id)
     assert tag.name == name
     assert tag.author_id == author
     assert tag.target_type == target_type
     assert tag.target_id == target_id
Example #10
0
 def remove_tag(self, tag, type, target_id):
     # check if tag exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         return
     # delete tag relationship if exists
     issue_tag = Tag.get_by_type_id_and_tag_id(type, self.issue_id,
                                               tag_name.id)
     if issue_tag:
         issue_tag.delete()
Example #11
0
    def test_get(self):
        name = "tag"
        author = "test"
        target_type = 2
        target_id = 3
        newtag = TagName.add(name, author, target_type, target_id)
        tag = TagName.get_by_name_and_target_id(name, target_type, target_id)
        assert tag.id == newtag.id
        assert tag.name == name
        assert tag.author_id == author
        assert tag.target_type == target_type
        assert tag.target_id == target_id

        tag = TagName.get_by_id(newtag.id)
        assert tag.id == newtag.id
        assert tag.name == name
        assert tag.author_id == author
        assert tag.target_type == target_type
        assert tag.target_id == target_id
Example #12
0
    def test_get(self):
        name = "tag"
        author = "test"
        target_type = 2
        target_id = 3
        newtag = TagName.add(name, author, target_type, target_id)
        tag = TagName.get_by_name_and_target_id(name, target_type, target_id)
        assert tag.id == newtag.id
        assert tag.name == name
        assert tag.author_id == author
        assert tag.target_type == target_type
        assert tag.target_id == target_id

        tag = TagName.get_by_id(newtag.id)
        assert tag.id == newtag.id
        assert tag.name == name
        assert tag.author_id == author
        assert tag.target_type == target_type
        assert tag.target_id == target_id
Example #13
0
 def remove_tag(self, tag, type, target_id):
     # check if tag exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         return
     # delete tag relationship if exists
     issue_tag = Tag.get_by_type_id_and_tag_id(
         type, self.issue_id, tag_name.id)
     if issue_tag:
         issue_tag.delete()
Example #14
0
 def test_add(self):
     name = "tag"
     author = "test"
     target_type = 2
     target_id = 3
     tag = TagName.add(name, author, target_type, target_id)
     assert tag.name == name
     assert tag.author_id == author
     assert tag.target_type == target_type
     assert tag.target_id == target_id
     tag.delete()
Example #15
0
    def test_get_type_ids_by_names_and_target_id(self):
        name1 = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name1 = TagName.add(name1, author, target_type, target_id)
        assert tag_name1.name == name1

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name1.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name1.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name1.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1], target_id)

        assert len(type_ids) == 3
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids

        name2 = "tag2"
        tag_name2 = TagName.add(name2, author, target_type, target_id)
        assert tag_name2.name == name2

        type_id4 = 4
        tag3 = Tag.add(tag_name2.id, type, type_id3, author_id, target_id)
        tag4 = Tag.add(tag_name2.id, type, type_id4, author_id, target_id)

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1, name2], target_id)

        print type_ids
        assert len(type_ids) == 1
        assert type_id3 in type_ids
Example #16
0
    def test_get_type_ids_by_names_and_target_id(self):
        name1 = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name1 = TagName.add(name1, author, target_type, target_id)
        assert tag_name1.name == name1

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name1.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name1.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name1.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1], target_id)

        assert len(type_ids) == 3
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids

        name2 = "tag2"
        tag_name2 = TagName.add(name2, author, target_type, target_id)
        assert tag_name2.name == name2

        type_id4 = 4
        tag3 = Tag.add(tag_name2.id, type, type_id3, author_id, target_id)
        tag4 = Tag.add(tag_name2.id, type, type_id4, author_id, target_id)

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1, name2], target_id)

        print type_ids
        assert len(type_ids) == 1
        assert type_id3 in type_ids
Example #17
0
        def index(request):
            if list_type == 'search':
                key_word = request.get_form_var('q', None)
                if not key_word:
                    return self._index(request)

            milestone_number = request.get_form_var('milestone')
            state = request.get_form_var('state', 'open')
            page = request.get_form_var('page', 1)
            project_name = self.proj_name
            user = request.user
            project = self.project
            order = get_order_type(request, 'project_issues_order')  # noqa 目前支持list_type = repo的sort_by
            n_open_issues = project.n_open_issues
            n_closed_issues = project.n_closed_issues
            n_everyone_issues = 0
            n_assigned_issues = 0
            n_created_issues = 0
            n_pages = 0
            selected_tag_names = request.get_form_var('tags', '')
            start = ISSUES_COUNT_PER_PAGE * (int(page) - 1)
            limit = ISSUES_COUNT_PER_PAGE

            is_closed_tab = None if state == "open" else True
            issue_list = []
            total_issues = 0
            opts = dict(project=project, state=state, start=start,
                        limit=limit, order=order)
            if selected_tag_names:
                selected_tag_names = selected_tag_names.split(',')
                tags = filter(None, [TagName.get_project_issue_tag(
                    name, project) for name in selected_tag_names])
                opts['tags'] = tags
            show_tags = project.get_group_tags(selected_tag_names)

            if milestone_number:
                milestone = Milestone.get_by_project(
                    project, number=milestone_number)
                opts['milestone'] = milestone

            # FIXME: why user or list_type ?
            if user or list_type in ('repo', 'search'):
                if list_type == 'search':
                    # FIXME: search with assigned or creator
                    search_result = IssueSearch.search_a_phrase(
                        key_word, self.project.id,
                        size=n_open_issues + n_closed_issues,
                        state=state) or []
                    search_issue_ids = []
                    if search_result and not search_result.get('error'):
                        search_issue_ids = [
                            id for id, in SearchEngine.decode(
                                search_result, ['issue_id'])]
                    # FIXME: is search_issue_ids int[]?
                    opts['issue_ids'] = search_issue_ids
                elif list_type == 'created_by':
                    opts['creator'] = user
                elif list_type == 'assigned':
                    opts['assignee'] = user
                # FIXME: update n_closed_issues & n_open_issues
                multi_dict = ProjectIssue.get_multi_by(**opts)
                issue_list = multi_dict['issues']
                total_issues = multi_dict['total']

                if user:
                    if list_type == 'repo':
                        n_assigned_issues = user.get_n_assigned_issues_by_project(project.id, state)  # noqa
                        n_created_issues = user.get_n_created_issues_by_project(project.id, state)  # noqa
                    elif list_type == 'created_by':
                        n_assigned_issues = user.get_n_assigned_issues_by_project(project.id, state)  # noqa
                        n_created_issues = total_issues
                    elif list_type == 'assigned':
                        n_assigned_issues = total_issues
                        n_created_issues = user.get_n_created_issues_by_project(project.id, state)  # noqa
                    elif list_type == 'search' and search_issue_ids:
                        n_assigned_issues = ProjectIssue.get_n_by_issue_ids_and_assignee_id(  # noqa
                            search_issue_ids, state, user.name)
                        n_created_issues = ProjectIssue.get_n_by_issue_ids_and_creator_id(  # noqa
                            search_issue_ids, state, user.name)
                n_pages = (total_issues - 1) / ISSUES_COUNT_PER_PAGE + 1

            # tags 的选择只会改变选中的filter的显示issue数
            if list_type in ('repo', 'search'):
                n_everyone_issues = total_issues
            else:
                n_everyone_issues = n_open_issues \
                    if state == "open" else n_closed_issues
            return st('issue/issues.html', **locals())
Example #18
0
        def index(request):
            if list_type == 'search':
                key_word = request.get_form_var('q', None)
                if not key_word:
                    return self._index(request)

            milestone_number = request.get_form_var('milestone')
            state = request.get_form_var('state', 'open')
            page = request.get_form_var('page', 1)
            project_name = self.proj_name
            user = request.user
            project = self.project
            order = get_order_type(
                request,
                'project_issues_order')  # noqa 目前支持list_type = repo的sort_by
            n_open_issues = project.n_open_issues
            n_closed_issues = project.n_closed_issues
            n_everyone_issues = 0
            n_assigned_issues = 0
            n_created_issues = 0
            n_pages = 0
            selected_tag_names = request.get_form_var('tags', '')
            start = ISSUES_COUNT_PER_PAGE * (int(page) - 1)
            limit = ISSUES_COUNT_PER_PAGE

            is_closed_tab = None if state == "open" else True
            issue_list = []
            total_issues = 0
            opts = dict(project=project,
                        state=state,
                        start=start,
                        limit=limit,
                        order=order)
            if selected_tag_names:
                selected_tag_names = selected_tag_names.split(',')
                tags = filter(None, [
                    TagName.get_project_issue_tag(name, project)
                    for name in selected_tag_names
                ])
                opts['tags'] = tags
            show_tags = project.get_group_tags(selected_tag_names)

            if milestone_number:
                milestone = Milestone.get_by_project(project,
                                                     number=milestone_number)
                opts['milestone'] = milestone

            # FIXME: why user or list_type ?
            if user or list_type in ('repo', 'search'):
                if list_type == 'search':
                    # FIXME: search with assigned or creator
                    search_result = IssueSearch.search_a_phrase(
                        key_word,
                        self.project.id,
                        size=n_open_issues + n_closed_issues,
                        state=state) or []
                    search_issue_ids = []
                    if search_result and not search_result.get('error'):
                        search_issue_ids = [
                            id for id, in SearchEngine.decode(
                                search_result, ['issue_id'])
                        ]
                    # FIXME: is search_issue_ids int[]?
                    opts['issue_ids'] = search_issue_ids
                elif list_type == 'created_by':
                    opts['creator'] = user
                elif list_type == 'assigned':
                    opts['assignee'] = user
                # FIXME: update n_closed_issues & n_open_issues
                multi_dict = ProjectIssue.get_multi_by(**opts)
                issue_list = multi_dict['issues']
                total_issues = multi_dict['total']

                if user:
                    if list_type == 'repo':
                        n_assigned_issues = user.get_n_assigned_issues_by_project(
                            project.id, state)  # noqa
                        n_created_issues = user.get_n_created_issues_by_project(
                            project.id, state)  # noqa
                    elif list_type == 'created_by':
                        n_assigned_issues = user.get_n_assigned_issues_by_project(
                            project.id, state)  # noqa
                        n_created_issues = total_issues
                    elif list_type == 'assigned':
                        n_assigned_issues = total_issues
                        n_created_issues = user.get_n_created_issues_by_project(
                            project.id, state)  # noqa
                    elif list_type == 'search' and search_issue_ids:
                        n_assigned_issues = ProjectIssue.get_n_by_issue_ids_and_assignee_id(  # noqa
                            search_issue_ids, state, user.name)
                        n_created_issues = ProjectIssue.get_n_by_issue_ids_and_creator_id(  # noqa
                            search_issue_ids, state, user.name)
                n_pages = (total_issues - 1) / ISSUES_COUNT_PER_PAGE + 1

            # tags 的选择只会改变选中的filter的显示issue数
            if list_type in ('repo', 'search'):
                n_everyone_issues = total_issues
            else:
                n_everyone_issues = n_open_issues \
                    if state == "open" else n_closed_issues
            return st('issue/issues.html', **locals())