• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rafalp / Misago / 9487666026

12 Jun 2024 06:16PM UTC coverage: 97.699% (-1.0%) from 98.716%
9487666026

push

github

web-flow
Replace forum options with account settings (#1742)

1947 of 1979 new or added lines in 68 files covered. (98.38%)

661 existing lines in 143 files now uncovered.

52601 of 53840 relevant lines covered (97.7%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.67
/misago/threads/threadtypes/treesmap.py
1
from django.utils.module_loading import import_string
1✔
2

3
from ...conf import settings
1✔
4

5

6
class TreesMap:
1✔
7
    """Object that maps trees to strategies"""
8

9
    def __init__(self, types_modules):
1✔
10
        self.is_loaded = False
1✔
11
        self.types_modules = types_modules
1✔
12

13
    def load(self):
1✔
14
        self.types = self.load_types(self.types_modules)
1✔
15
        self.trees = self.load_trees(self.types)
1✔
16
        self.roots = self.get_roots(self.trees)
1✔
17
        self.is_loaded = True
1✔
18

19
    def load_types(self, types_modules):
1✔
20
        loaded_types = {}
1✔
21
        for path in types_modules:
1✔
22
            type_cls = import_string(path)
1✔
23
            loaded_types[type_cls.root_name] = type_cls()
1✔
24
        return loaded_types
1✔
25

26
    def load_trees(self, types):
1✔
27
        from ...categories.models import Category
1✔
28

29
        trees = {}
1✔
30
        for category in Category.objects.filter(level=0, special_role__in=types.keys()):
1✔
31
            trees[category.tree_id] = types[category.special_role]
1✔
32
        return trees
1✔
33

34
    def get_roots(self, trees):
1✔
35
        roots = {}
1✔
36
        for tree_id in trees:
1✔
37
            roots[trees[tree_id].root_name] = tree_id
1✔
38
        return roots
1✔
39

40
    def get_type_for_tree_id(self, tree_id):
1✔
41
        if not self.is_loaded:
1✔
UNCOV
42
            self.load()
×
43

44
        try:
1✔
45
            return self.trees[tree_id]
1✔
46
        except KeyError:
1✔
47
            raise KeyError("'%s' tree id has no type defined" % tree_id)
1✔
48

49
    def get_tree_id_for_root(self, root_name):
1✔
50
        if not self.is_loaded:
1✔
51
            self.load()
1✔
52

53
        try:
1✔
54
            return self.roots[root_name]
1✔
55
        except KeyError:
1✔
56
            raise KeyError('"%s" root has no tree defined' % root_name)
1✔
57

58

59
trees_map = TreesMap(settings.MISAGO_THREAD_TYPES)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc