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

rafalp / Misago / 17496798327

05 Sep 2025 02:59PM UTC coverage: 96.509% (-0.3%) from 96.769%
17496798327

Pull #1995

github

web-flow
Merge 17284d7d7 into 6bb938c90
Pull Request #1995: Move `Post` model from `misago.threads` to `misago.posts`

1884 of 1974 new or added lines in 149 files covered. (95.44%)

305 existing lines in 16 files now uncovered.

66716 of 69129 relevant lines covered (96.51%)

0.97 hits per line

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

63.83
/misago/threads/utils.py
1
from urllib.parse import urlparse
1✔
2

3
from django.urls import Resolver404, resolve
1✔
4

5
from .models import PostLike
1✔
6

7

8
def add_categories_to_items(root_category, categories, items):
1✔
9
    categories_dict = {}
1✔
10
    for category in categories:
1✔
11
        categories_dict[category.pk] = category
1✔
12
        if category.parent_id:
1✔
13
            category.parent = categories_dict[category.parent_id]
1✔
14

15
    for item in items:
1✔
UNCOV
16
        item.category = categories_dict[item.category_id]
×
17

18

19
def add_likes_to_posts(user, posts):
1✔
20
    if user.is_anonymous:
×
21
        return
×
22

23
    posts_map = {}
×
24
    for post in posts:
×
25
        posts_map[post.id] = post
×
26
        post.is_liked = False
×
27

28
    queryset = PostLike.objects.filter(liker=user, post_id__in=posts_map.keys())
×
29

30
    for like in queryset.values("post_id"):
×
31
        posts_map[like["post_id"]].is_liked = True
×
32

33

34
SUPPORTED_THREAD_ROUTES = {
1✔
35
    "misago:thread": "id",
36
    "misago:thread-post": "pk",
37
    "misago:thread-last": "pk",
38
    "misago:thread-new": "pk",
39
    "misago:thread-unapproved": "pk",
40
}
41

42

43
def get_thread_id_from_url(request, url):  # pylint: disable=too-many-return-statements
1✔
44
    clean_url = str(url).strip()
1✔
45
    url_bits = urlparse(clean_url)
1✔
46

47
    if url_bits.netloc and url_bits.netloc != request.get_host():
1✔
48
        return None
1✔
49

50
    if url_bits.path.startswith(request.get_host()):
1✔
51
        clean_path = url_bits.path.lstrip(request.get_host())
×
52
    else:
53
        clean_path = url_bits.path
1✔
54

55
    wsgi_alias = request.path_info[: len(request.path_info) * -1]
1✔
56
    if wsgi_alias and not clean_path.startswith(wsgi_alias):
1✔
57
        return None
×
58

59
    try:
1✔
60
        resolution = resolve(clean_path[len(wsgi_alias) :])
1✔
61
    except Resolver404:
1✔
62
        return None
1✔
63

64
    if not resolution.namespaces:
1✔
65
        return None
×
66

67
    url_name = "%s:%s" % (":".join(resolution.namespaces), resolution.url_name)
1✔
68
    kwargname = SUPPORTED_THREAD_ROUTES.get(url_name)
1✔
69

70
    if not kwargname:
1✔
71
        return None
1✔
72

73
    try:
×
74
        return int(resolution.kwargs.get(kwargname))
×
75
    except (TypeError, ValueError):
×
76
        return None
×
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