Exemple #1
0
 def add_milestone(self, user, name=None, milestone_id=None):
     from vilya.models.milestone import Milestone
     target = self.target
     if name:
         ms = Milestone.get_by_project(target, name=name)
         if not ms:
             ms = Milestone.create_by_project(self.target, name, user)
     elif milestone_id:
         ms = Milestone.get_by(milestone_id)
     else:
         return None
     ims = IssueMilestone.get_by_issue(self)
     if ims:
         ims.milestone_id = ms.id
         ims.save()
     else:
         ims = IssueMilestone.create_by_issue(self, ms, user)
Exemple #2
0
 def add_milestone(self, user, name=None, milestone_id=None):
     from vilya.models.milestone import Milestone
     target = self.target
     if name:
         ms = Milestone.get_by_project(target, name=name)
         if not ms:
             ms = Milestone.create_by_project(self.target, name, user)
     elif milestone_id:
         ms = Milestone.get_by(milestone_id)
     else:
         return None
     ims = IssueMilestone.get_by_issue(self)
     if ims:
         ims.milestone_id = ms.id
         ims.save()
     else:
         ims = IssueMilestone.create_by_issue(self, ms, user)
Exemple #3
0
 def test_add_milestone(self):
     user = User('testuser')
     project = self.project
     name = "Test Milestone 1"
     ms = Milestone.create_by_project(project, name, user)
     self.assertEqual(ms.name, name)
     self.assertEqual(int(ms.target_id), project.id)
     self.assertEqual(int(ms.target_type), PROJECT_MILESTONE_TYPE)
     self.assertEqual(ms.creator_id, user.name)
Exemple #4
0
 def test_add_milestone(self):
     user = User('testuser')
     project = self.project
     name = "Test Milestone 1"
     ms = Milestone.create_by_project(project, name, user)
     self.assertEqual(ms.name, name)
     self.assertEqual(int(ms.target_id), project.id)
     self.assertEqual(int(ms.target_type), PROJECT_MILESTONE_TYPE)
     self.assertEqual(ms.creator_id, user.name)
 def setUp(self):
     super(TestCase, self).setUp()
     self.project = get_temp_project()
     self.issue = ProjectIssue.add('test',
                                   'test description',
                                   'test',
                                   project=self.project.id)
     user = User('testuser')
     project = self.project
     name = "Test Milestone 1"
     ms = Milestone.create_by_project(project, name, user)
     self.milestone = ms
 def setUp(self):
     super(TestCase, self).setUp()
     self.project = get_temp_project()
     self.issue = ProjectIssue.add('test',
                                   'test description',
                                   'test',
                                   project=self.project.id)
     user = User('testuser')
     project = self.project
     name = "Test Milestone 1"
     ms = Milestone.create_by_project(project, name, user)
     self.milestone = ms
Exemple #7
0
    def test_get_milestone(self):
        user1 = User('testuser1')
        user2 = User('testuser2')
        project = self.project
        name1 = "Test Milestone 1"
        name2 = "Test Milestone 2"
        ms1 = Milestone.create_by_project(project, name1, user1)
        ms2 = Milestone.create_by_project(project, name2, user2)

        ms = Milestone.get_by_project(project, number=ms1.target_number)
        self.assertEqual(ms.name, name1)
        self.assertEqual(int(ms.target_id), project.id)
        self.assertEqual(ms.id, ms1.id)
        self.assertEqual(ms.target_number, ms1.target_number)
        self.assertEqual(ms.creator_id, user1.name)

        ms = Milestone.get_by_project(project, name=name2)
        self.assertEqual(ms.name, name2)
        self.assertEqual(int(ms.target_id), project.id)
        self.assertEqual(ms.id, ms2.id)
        self.assertEqual(ms.target_number, ms2.target_number)
        self.assertEqual(ms.creator_id, user2.name)
Exemple #8
0
    def test_get_milestone(self):
        user1 = User('testuser1')
        user2 = User('testuser2')
        project = self.project
        name1 = "Test Milestone 1"
        name2 = "Test Milestone 2"
        ms1 = Milestone.create_by_project(project, name1, user1)
        ms2 = Milestone.create_by_project(project, name2, user2)

        ms = Milestone.get_by_project(project, number=ms1.target_number)
        self.assertEqual(ms.name, name1)
        self.assertEqual(int(ms.target_id), project.id)
        self.assertEqual(ms.id, ms1.id)
        self.assertEqual(ms.target_number, ms1.target_number)
        self.assertEqual(ms.creator_id, user1.name)

        ms = Milestone.get_by_project(project, name=name2)
        self.assertEqual(ms.name, name2)
        self.assertEqual(int(ms.target_id), project.id)
        self.assertEqual(ms.id, ms2.id)
        self.assertEqual(ms.target_number, ms2.target_number)
        self.assertEqual(ms.creator_id, user2.name)
Exemple #9
0
 def milestone_percentage(self):
     from vilya.models.milestone import Milestone
     m_id = self.milestone_id
     m = Milestone.get_by(m_id) if m_id else None
     return m.percentage if m else 0
Exemple #10
0
 def milestone_name(self):
     from vilya.models.milestone import Milestone
     m_id = self.milestone_id
     m = Milestone.get_by(m_id) if m_id else None
     return m.name if m else ''
Exemple #11
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())
Exemple #12
0
 def milestone(self):
     return Milestone.get_by(self.milestone_id)
Exemple #13
0
 def issue_milestones(self):
     rs = Milestone.gets_by_project(self)
     return rs
Exemple #14
0
 def milestone_percentage(self):
     from vilya.models.milestone import Milestone
     m_id = self.milestone_id
     m = Milestone.get_by(m_id) if m_id else None
     return m.percentage if m else 0
Exemple #15
0
 def milestone_name(self):
     from vilya.models.milestone import Milestone
     m_id = self.milestone_id
     m = Milestone.get_by(m_id) if m_id else None
     return m.name if m else ''
Exemple #16
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())
Exemple #17
0
 def issue_milestones(self):
     rs = Milestone.gets_by_project(self)
     return rs