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

liqd / adhocracy-plus / 18908688697

29 Oct 2025 12:59PM UTC coverage: 44.622% (-44.5%) from 89.135%
18908688697

Pull #2986

github

web-flow
Merge 1dfde8ee7 into 445e1d498
Pull Request #2986: Draft: Speed up Github Ci Tests

3012 of 6750 relevant lines covered (44.62%)

0.45 hits per line

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

0.0
/apps/projects/insights.py
1
from typing import Iterable
×
2
from typing import List
×
3

4
from django.core.exceptions import FieldDoesNotExist
×
5

6
from adhocracy4.polls.models import Answer
×
7
from adhocracy4.polls.models import Poll
×
8
from adhocracy4.polls.models import Vote
×
9
from adhocracy4.projects.models import Project
×
10
from adhocracy4.ratings.models import Rating
×
11
from apps.budgeting.models import Proposal
×
12
from apps.ideas.models import Idea
×
13
from apps.interactiveevents.models import Like
×
14
from apps.interactiveevents.models import LiveQuestion
×
15
from apps.mapideas.models import MapIdea
×
16
from apps.projects.helpers import get_all_comments_project
×
17
from apps.projects.models import ProjectInsight
×
18
from apps.topicprio.models import Topic
×
19

20

21
def create_insights(projects: Iterable[Project]) -> List[ProjectInsight]:
×
22
    return [create_insight(project=project) for project in projects]
×
23

24

25
def create_insight(project: Project) -> ProjectInsight:
×
26
    modules = project.modules.all()
×
27

28
    ideas = Idea.objects.filter(module__in=modules)
×
29
    map_ideas = MapIdea.objects.filter(module__in=modules)
×
30
    comments = get_all_comments_project(project=project)
×
31
    proposals = Proposal.objects.filter(module__in=modules)
×
32
    polls = Poll.objects.filter(module__in=modules)
×
33
    votes = Vote.objects.filter(choice__question__poll__in=polls)
×
34
    answers = Answer.objects.filter(question__poll__in=polls)
×
35
    live_questions = LiveQuestion.objects.filter(module__in=modules)
×
36
    likes = Like.objects.filter(livequestion__in=live_questions)
×
37
    topics = Topic.objects.filter(module__in=modules)
×
38

39
    values = [Rating.POSITIVE, Rating.NEGATIVE]
×
40
    ratings_ideas = Rating.objects.filter(idea__in=ideas, value__in=values)
×
41
    ratings_map_ideas = Rating.objects.filter(mapidea__in=map_ideas, value__in=values)
×
42
    ratings_comments = Rating.objects.filter(comment__in=comments, value__in=values)
×
43
    ratings_topics = Rating.objects.filter(topic__in=topics, value__in=values)
×
44

45
    creator_objects = [
×
46
        comments,
47
        ratings_comments,
48
        ratings_ideas,
49
        ratings_map_ideas,
50
        ratings_topics,
51
        ideas,
52
        map_ideas,
53
        votes,
54
        answers,
55
        proposals,
56
    ]
57

58
    rating_objects = [
×
59
        ratings_comments,
60
        ratings_map_ideas,
61
        ratings_topics,
62
        ratings_ideas,
63
        likes,
64
    ]
65

66
    idea_objects = [ideas, map_ideas, proposals, topics]
×
67

68
    insight, _ = ProjectInsight.objects.get_or_create(project=project)
×
69

70
    insight.comments = comments.count()
×
71
    insight.ratings = sum(x.count() for x in rating_objects)
×
72
    insight.written_ideas = sum(x.count() for x in idea_objects)
×
73
    insight.poll_answers = votes.count() + answers.count()
×
74
    insight.live_questions = live_questions.count()
×
75

76
    insight.active_participants.clear()
×
77
    unregistered_participants = set()
×
78

79
    for obj in creator_objects:
×
80
        # ignore objects which don't have a creator, they are counted in the next step.
81
        ids = list(
×
82
            obj.filter(creator__isnull=False)
83
            .values_list("creator", flat=True)
84
            .distinct()
85
            .order_by()
86
        )
87
        insight.active_participants.add(*ids)
×
88
        # content from unregistered users doesn't have a creator but a content_id
89
        if model_field_exists(obj.model, "content_id"):
×
90
            content_ids = set(
×
91
                obj.filter(content_id__isnull=False)
92
                .values_list("content_id", flat=True)
93
                .distinct()
94
                .order_by()
95
            )
96
            unregistered_participants = unregistered_participants.union(content_ids)
×
97

98
    insight.unregistered_participants = len(unregistered_participants)
×
99
    insight.save()
×
100
    return insight
×
101

102

103
def model_field_exists(cls, field):
×
104
    try:
×
105
        cls._meta.get_field(field)
×
106
        return True
×
107
    except FieldDoesNotExist:
×
108
        return False
×
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

© 2025 Coveralls, Inc