def setUp(self):
     dbStub.addResult([[1]])
     dbStub.addResult([])
     self.cm = trac.core.ComponentManager()
     self.req = DummyReq()
     self.path = 'path'  # dummy env.path
     self.project_name = "path"
     self.bind_called = False
     self.unbind_called = False
     self.orig_bind = CQDECategoryStore(
     ).bind_category_project  #@UndefinedVariable
     self.orig_unbind = CQDECategoryStore(
     ).unbind_category_project  #@UndefinedVariable
     CQDECategoryStore().bind_category_project = self.bind
     CQDECategoryStore().unbind_category_project = self.unbind
Ejemplo n.º 2
0
    def process_request(self, req):
        """ Process request for listing, creating and removing projects
        """
        categories = []
        q_filter = req.args.get('q')
        limit = req.args.get('limit')
        contexts = req.args.get('contexts[]')
        if contexts:
            if not isinstance(contexts, list):
                contexts = [contexts]

        # Second option: provide contexts in comma separated list
        if not contexts:
            contexts = req.args.get('contexts')
            if contexts:
                contexts = contexts.split(',')

        if q_filter:
            catstore = CQDECategoryStore()
            categories = catstore.get_category_by_name_filter(q_filter, limit, contexts)

        # Construct response in JSON list format
        data = ''
        try:
            data = json.dumps([category.name.encode("utf-8").split("#")[0] for category in categories])
        except Exception, e:
            self.log.exception('Returning JSON from categories failed')
Ejemplo n.º 3
0
    def _show_regular_page(self, req):
        req_data = {}
        # Resolve some static data needed on page (categories and project count)
        cs = CQDECategoryStore()
        all_categories = cs.get_all_categories()

        all_contexts = cs.get_contexts()
        combined_context_ids, combined_contexts, non_combined_contexts = self.get_combined_contexts(
            all_contexts)

        # Total count of projects and count of projects in categories
        direct_category_counts = Projects().get_project_counts_per_category(
            req.authname)

        req_data['direct_category_counts'] = direct_category_counts
        req_data['combined_context_ids'] = combined_context_ids
        req_data['non_combined_contexts'] = non_combined_contexts

        self.set_category_data_into_request_data(all_categories, req_data)

        add_stylesheet(req, 'multiproject/css/multiproject.css')
        add_script(req, 'multiproject/js/jquery.ba-bbq.js')
        add_script(req, 'multiproject/js/explore.js')

        return "find.html", {
            'top_categories': req_data['top_categories'],
            'categories': req_data['root_categories_of_combined_contexts'],
            'nonbrowsable_cntxt': req_data['non_empty_non_combined_contexts'],
            'selected_tab': self.DEFAULT_TAB,
            'tabs': self.TABS}, \
            None
Ejemplo n.º 4
0
 def test_unbind(self):
     dbStub.addResult([])
     c = CQDECategoryStore()
     self.assertTrue(c.unbind_category_project(1, 2))
     self.assertTrue(dbStub.cursors[0].query.lower().startswith(
         "delete from project_categories"))
     self.assertTrue(dbStub.closed)
Ejemplo n.º 5
0
 def test_fetch_context_data_error(self):
     dbStub.addResult(categories)
     dbStub.addResult(subcategories)
     dbStub.setExceptions(True)
     c = CQDECategoryStore()
     data = c.fetch_context_data()
     self.assertFalse(data)
     self.assertTrue(dbStub.closed)
Ejemplo n.º 6
0
 def test_fetch_available_categories_error(self):
     dbStub.addResult(categories)
     dbStub.addResult(subcategories)
     dbStub.setExceptions(True)
     c = CQDECategoryStore()
     data = c.fetch_available_categories(1, 2, 3)
     self.assertFalse(data)
     self.assertTrue(dbStub.closed)
Ejemplo n.º 7
0
 def test_fetch_selected_categories_error(self):
     dbStub.addResult(contextlist)  # 2 contexts
     dbStub.addResult(cat_list)
     dbStub.addResult([])
     dbStub.setExceptions(True)
     c = CQDECategoryStore()
     data = c.fetch_selected_categories(2)
     self.assertFalse(data)
     self.assertTrue(dbStub.closed)
Ejemplo n.º 8
0
    def get_project_categories(self, projects):
        """ Returns a map of project categories
            project_id => category string
        """
        cs = CQDECategoryStore()
        project_categories = {}

        for project in projects:
            cats = cs.get_all_project_categories(project.id, ordered=True)
            cats_joined = ', '.join([cat.name.split("#")[0] for cat in cats])
            project_categories[project.id] = cats_joined

        return project_categories
Ejemplo n.º 9
0
 def test_fetch_available_categories(self):
     dbStub.addResult(categories)
     dbStub.addResult(subcategories)
     dbStub.addResult([])  # end recursion
     c = CQDECategoryStore()
     data = c.fetch_available_categories(1, 2, 3)
     self.assertTrue(data)
     self.assertEquals(len(data), 3)
     self.assertEquals(data[3]['name'], 'cats')
     childs = data[3]['childs']
     self.assertTrue(childs)
     self.assertEquals(len(childs), 2)
     self.assertEquals(childs[6]['name'], 'subcat1')
     self.assertTrue(dbStub.closed)
Ejemplo n.º 10
0
 def test_fetch_selected_categories(self):
     dbStub.addResult(contextlist)  # 2 contexts
     dbStub.addResult(cat_list)
     dbStub.addResult([])
     c = CQDECategoryStore()
     data = c.fetch_selected_categories(2)
     self.assertTrue(data)
     self.assertEquals(len(data), 2)
     self.assertEquals(len(data[1]), 3)
     self.assertEquals(len(data[2]), 0)
     self.assertEquals(data[1][0].name, 'cats')
     self.assertEquals(data[1][1].name, 'dogs')
     self.assertEquals(data[1][2].name, 'bugs')
     self.assertTrue(dbStub.closed)
Ejemplo n.º 11
0
    def getProjectCategories(self, req):
        """ Returns projects categorizations
        """
        categorylist = []

        store = CQDECategoryStore()

        for context in store.get_contexts():
            contextcategories = []
            categories = store.get_categories(context.context_id)
            for category in categories:
                contextcategories.append(category.name)
            categorylist.append(context.name)
            categorylist.append(contextcategories)

        return categorylist
Ejemplo n.º 12
0
    def test_fetch_context_data(self):
        dbStub.addResult(contextlist)  # 2 contexts
        dbStub.addResult(category_tree)  # 3 categories
        dbStub.addResult([])  # no subcategories for each of the 3 categ.
        dbStub.addResult([])
        dbStub.addResult([])
        dbStub.addResult(subcategories)  # 2 project_categories
        dbStub.addResult([])

        c = CQDECategoryStore()
        data = c.fetch_context_data()
        self.assertTrue(data)
        self.assertEquals(len(data), 2)
        self.assertEquals(data[1]['name'], 'context1')
        self.assertEquals(len(data[1]['categories']), 3)
        self.assertTrue(dbStub.closed)
Ejemplo n.º 13
0
    def render_admin_panel(self, req, cat, page, path_info):
        req.perm.require("TRAC_ADMIN")
        self.categorystore = CQDECategoryStore()

        data = {}
        if req.method == 'POST':
            if req.args.get('add'):
                self.add_category(req)
            if req.args.get('remove'):
                self.remove_category(req)
            if req.args.get('edit'):
                self.edit_category(req)
            if req.args.get('move'):
                self.move_category_to_new_context(req)
            if req.args.get('merge'):
                self.merge_to_category(req)
            if req.args.get('reposition'):
                self.move_category_to_new_parent(req)

        contexts = self.categorystore.get_contexts()
        context_by_id = {}
        categories_per_context = {}
        for context in contexts:
            context_by_id[context.context_id] = context
            categories_per_context[context.context_id] = \
                self.categorystore.get_all_categories_in_context(context.context_id)
        is_rdf_description = lambda x: x.startswith('http://')

        data['context_by_id'] = context_by_id
        data['categories_per_context'] = categories_per_context
        data['envurl'] = req.base_path
        data['invalid_categories'] = self.categorystore.get_categories_with_invalid_context()
        data['is_rdf_description'] = is_rdf_description
        add_script(req, 'multiproject/js/jquery-ui.js')
        add_script(req, 'multiproject/js/categorization.js')
        add_stylesheet(req, 'multiproject/css/jquery-ui.css')
        return 'admin_categoryeditor.html', data
 def tearDown(self):
     dbStub.reset()
     self.cm = None
     self.req = None
     CQDECategoryStore().bind_category_project = self.orig_bind
     CQDECategoryStore().unbind_category_project = self.orig_unbind
Ejemplo n.º 15
0
 def test_unbind_error(self):
     dbStub.addResult([])
     dbStub.setExceptions(True)
     c = CQDECategoryStore()
     self.assertFalse(c.unbind_category_project(1, 2))
     self.assertTrue(dbStub.closed)
Ejemplo n.º 16
0
 def __init__(self):
     self.categ = CQDECategoryStore()
     self.first_context = None
Ejemplo n.º 17
0
    def _get_project_categories(self, project):
        """
        Create list of categories. License, Language and Development status are shown separately
        and are therefore taken out from the category listing.
        """
        # Get api
        cs = CQDECategoryStore()

        # Get categories and specialcase contexts
        categories = cs.get_all_project_categories(project.id)
        contexts = cs.get_contexts()

        combined_categories = []
        separated_categories_per_context = {}

        categories_by_any_context_id = {}
        context_by_id = {}

        # Setup the contexts dicts
        for context in contexts:
            context_by_id[context.context_id] = context
            if context.summary_name:
                # If context has summary name, it is shown as separated in the summary page
                new_list = []
                categories_by_any_context_id[context.context_id] = new_list
                separated_categories_per_context[context.context_id] = new_list
            else:
                categories_by_any_context_id[
                    context.context_id] = combined_categories

        sort_opts = {
            'key': lambda c: c.name,
            'cmp': lambda x, y: cmp(x.lower(), y.lower())
        }

        # Now, categories_by_any_context_id has key for each context id
        for category in categories:
            categories_by_any_context_id[category.context].append(category)
        for context_id in separated_categories_per_context:
            separated_categories_per_context[context_id].sort(**sort_opts)

        combined_categories.sort(**sort_opts)

        # Sort alphabetically, case-insensitively
        context_order = [
            c.context_id
            for c in sorted(map(lambda id: context_by_id[id],
                                separated_categories_per_context.keys()),
                            key=lambda c: c.summary_name)
        ]

        languages = []
        for context_id in separated_categories_per_context:
            context = context_by_id[context_id]
            if (context.summary_name and context.summary_name.lower()
                    in ('language', 'natural language')):
                # Here, we expect that the description contains the language tag.
                # http://www.w3schools.com/tags/att_meta_http_equiv.asp
                # http://www.w3.org/TR/2011/WD-html-markup-20110113/meta.http-equiv.content-language.html
                languages = [
                    c.description
                    for c in separated_categories_per_context[context_id]
                ]

        return (combined_categories, separated_categories_per_context,
                context_by_id, context_order, languages)