wbnews 1.58.3__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wbnews/.coveragerc +23 -0
- wbnews/__init__.py +1 -0
- wbnews/admin.py +30 -0
- wbnews/apps.py +9 -0
- wbnews/factories.py +36 -0
- wbnews/filters/__init__.py +1 -0
- wbnews/filters/news.py +46 -0
- wbnews/fixtures/wbnews.yaml +1 -0
- wbnews/import_export/__init__.py +0 -0
- wbnews/import_export/backends/__init__.py +1 -0
- wbnews/import_export/backends/news.py +36 -0
- wbnews/import_export/handlers/__init__.py +1 -0
- wbnews/import_export/handlers/news.py +57 -0
- wbnews/import_export/parsers/__init__.py +0 -0
- wbnews/import_export/parsers/emails/__init__.py +0 -0
- wbnews/import_export/parsers/emails/news.py +39 -0
- wbnews/import_export/parsers/emails/utils.py +65 -0
- wbnews/import_export/parsers/rss/__init__.py +0 -0
- wbnews/import_export/parsers/rss/news.py +58 -0
- wbnews/locale/de/LC_MESSAGES/django.mo +0 -0
- wbnews/locale/de/LC_MESSAGES/django.po +166 -0
- wbnews/locale/de/LC_MESSAGES/django.po.translated +173 -0
- wbnews/locale/en/LC_MESSAGES/django.mo +0 -0
- wbnews/locale/en/LC_MESSAGES/django.po +159 -0
- wbnews/locale/fr/LC_MESSAGES/django.mo +0 -0
- wbnews/locale/fr/LC_MESSAGES/django.po +162 -0
- wbnews/migrations/0001_initial_squashed_0005_alter_news_import_source.py +349 -0
- wbnews/migrations/0006_alter_news_language.py +122 -0
- wbnews/migrations/0007_auto_20240103_0955.py +43 -0
- wbnews/migrations/0008_alter_news_language.py +123 -0
- wbnews/migrations/0009_newsrelationship_analysis_newsrelationship_sentiment.py +94 -0
- wbnews/migrations/0010_newsrelationship_important.py +17 -0
- wbnews/migrations/0011_newsrelationship_content_object_repr.py +18 -0
- wbnews/migrations/0012_alter_news_unique_together_news_identifier_and_more.py +91 -0
- wbnews/migrations/0013_alter_news_datetime.py +19 -0
- wbnews/migrations/0014_newsrelationship_unique_news_relationship.py +27 -0
- wbnews/migrations/__init__.py +0 -0
- wbnews/models/__init__.py +3 -0
- wbnews/models/llm/cleaned_news.py +66 -0
- wbnews/models/news.py +131 -0
- wbnews/models/relationships.py +45 -0
- wbnews/models/sources.py +73 -0
- wbnews/models/utils.py +15 -0
- wbnews/serializers.py +134 -0
- wbnews/signals.py +4 -0
- wbnews/tasks.py +16 -0
- wbnews/tests/__init__.py +0 -0
- wbnews/tests/conftest.py +6 -0
- wbnews/tests/parsers/__init__.py +0 -0
- wbnews/tests/parsers/test_emails.py +25 -0
- wbnews/tests/test_models.py +80 -0
- wbnews/tests/test_utils.py +7 -0
- wbnews/tests/tests.py +12 -0
- wbnews/urls.py +25 -0
- wbnews/utils.py +57 -0
- wbnews/viewsets/__init__.py +12 -0
- wbnews/viewsets/buttons.py +42 -0
- wbnews/viewsets/display.py +148 -0
- wbnews/viewsets/endpoints.py +34 -0
- wbnews/viewsets/menu.py +29 -0
- wbnews/viewsets/titles.py +44 -0
- wbnews/viewsets/views.py +168 -0
- wbnews-1.58.3.dist-info/METADATA +7 -0
- wbnews-1.58.3.dist-info/RECORD +65 -0
- wbnews-1.58.3.dist-info/WHEEL +5 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from django.dispatch import receiver
|
|
2
|
+
from django.utils.translation import gettext as _
|
|
3
|
+
from rest_framework.reverse import reverse
|
|
4
|
+
from wbcore.contrib.icons import WBIcon
|
|
5
|
+
from wbcore.enums import RequestType
|
|
6
|
+
from wbcore.metadata.configs import buttons as bt
|
|
7
|
+
from wbcore.metadata.configs.buttons.view_config import ButtonViewConfig
|
|
8
|
+
from wbcore.signals.instance_buttons import add_extra_button
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class NewsButtonConfig(ButtonViewConfig):
|
|
12
|
+
def get_custom_list_instance_buttons(self):
|
|
13
|
+
buttons = set()
|
|
14
|
+
buttons.add(bt.HyperlinkButton(key="open_link", label=_("Open News"), icon=WBIcon.LINK.icon))
|
|
15
|
+
if self.request.user.is_superuser and (pk := self.view.kwargs.get("pk")):
|
|
16
|
+
buttons.add(
|
|
17
|
+
bt.ActionButton(
|
|
18
|
+
method=RequestType.PATCH,
|
|
19
|
+
identifiers=("wbnews:newsrelationship",),
|
|
20
|
+
endpoint=reverse("wbnews:news-refreshrelationship", args=[pk]),
|
|
21
|
+
action_label=_("Reset relationships"),
|
|
22
|
+
label=_("Reset relationships"),
|
|
23
|
+
icon=WBIcon.REGENERATE.icon,
|
|
24
|
+
title=_("Reset relationships"),
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
return buttons
|
|
28
|
+
|
|
29
|
+
def get_custom_instance_buttons(self):
|
|
30
|
+
return self.get_custom_list_instance_buttons()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class NewsRelationshipButtonConfig(ButtonViewConfig):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@receiver(add_extra_button)
|
|
38
|
+
def add_new_extra_button(sender, instance, request, view, pk=None, **kwargs):
|
|
39
|
+
if instance and pk and view:
|
|
40
|
+
content_type = view.get_content_type()
|
|
41
|
+
endpoint = f'{reverse("wbnews:newsrelationship-list", args=[], request=request)}?content_type={content_type.id}&object_id={pk}'
|
|
42
|
+
return bt.WidgetButton(endpoint=endpoint, label="News", icon=WBIcon.NEWSPAPER.icon)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from django.utils.translation import gettext as _
|
|
4
|
+
from wbcore.metadata.configs import display as dp
|
|
5
|
+
from wbcore.metadata.configs.display.instance_display.shortcuts import (
|
|
6
|
+
Display,
|
|
7
|
+
create_simple_display,
|
|
8
|
+
create_simple_section,
|
|
9
|
+
)
|
|
10
|
+
from wbcore.metadata.configs.display.instance_display.utils import repeat_field
|
|
11
|
+
from wbcore.metadata.configs.display.view_config import DisplayViewConfig
|
|
12
|
+
|
|
13
|
+
from wbnews.models import NewsRelationship
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SourceDisplayConfig(DisplayViewConfig):
|
|
17
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
18
|
+
return dp.ListDisplay(
|
|
19
|
+
fields=[
|
|
20
|
+
dp.Field(key="title", label=_("Title")),
|
|
21
|
+
dp.Field(key="identifier", label=_("RSS feed")),
|
|
22
|
+
dp.Field(key="author", label=_("Author")),
|
|
23
|
+
dp.Field(key="description", label=_("Description")),
|
|
24
|
+
dp.Field(key="updated", label=_("Last Update")),
|
|
25
|
+
]
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def get_instance_display(self) -> Display:
|
|
29
|
+
return create_simple_display(
|
|
30
|
+
[
|
|
31
|
+
["title", "identifier"],
|
|
32
|
+
["author", "updated"],
|
|
33
|
+
[repeat_field(2, "description")],
|
|
34
|
+
[repeat_field(2, "news_section")],
|
|
35
|
+
],
|
|
36
|
+
[create_simple_section("news_section", "News", [["news"]], "news", collapsed=False)],
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class NewsDisplayConfig(DisplayViewConfig):
|
|
41
|
+
def get_instance_display(self) -> Display:
|
|
42
|
+
return create_simple_display(
|
|
43
|
+
[
|
|
44
|
+
["datetime", "source"],
|
|
45
|
+
["language", "link"],
|
|
46
|
+
[repeat_field(2, "summary")],
|
|
47
|
+
[repeat_field(2, "description")],
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
52
|
+
return dp.ListDisplay(
|
|
53
|
+
fields=[
|
|
54
|
+
dp.Field(key="datetime", label=_("Datetime")),
|
|
55
|
+
dp.Field(key="title", label=_("Title")),
|
|
56
|
+
dp.Field(key="summary", label=_("Summary")),
|
|
57
|
+
dp.Field(key="description", label=_("Description")),
|
|
58
|
+
# dp.Field(key="tags", label=_("Edited")),
|
|
59
|
+
dp.Field(key="source", label=_("Source")),
|
|
60
|
+
dp.Field(key="language", label=_("Language")),
|
|
61
|
+
dp.Field(key="image_url", label=_("Image")),
|
|
62
|
+
]
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class NewsRelationshipDisplayConfig(DisplayViewConfig):
|
|
67
|
+
def get_instance_display(self) -> Display:
|
|
68
|
+
if self.new_mode:
|
|
69
|
+
return create_simple_display(
|
|
70
|
+
[
|
|
71
|
+
["news", "news"],
|
|
72
|
+
["important", "sentiment"],
|
|
73
|
+
["analysis", "analysis"],
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
return create_simple_display(
|
|
78
|
+
[
|
|
79
|
+
["news", "news"],
|
|
80
|
+
["content_type", "object_id"],
|
|
81
|
+
[
|
|
82
|
+
"important",
|
|
83
|
+
"sentiment",
|
|
84
|
+
],
|
|
85
|
+
["analysis", "analysis"],
|
|
86
|
+
["summary", "summary"],
|
|
87
|
+
["description", "description"],
|
|
88
|
+
]
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
92
|
+
fields = (
|
|
93
|
+
[dp.Field(key="content_object_repr", label=_("Linked Object"))]
|
|
94
|
+
if self.view.object_id is None and self.view.content_type is None
|
|
95
|
+
else []
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
fields.extend(
|
|
99
|
+
[
|
|
100
|
+
dp.Field(key="datetime", label=_("Datetime")),
|
|
101
|
+
dp.Field(key="analysis", label=_("Analysis")),
|
|
102
|
+
dp.Field(key="title", label=_("Title")),
|
|
103
|
+
dp.Field(key="summary", label=_("Summary")),
|
|
104
|
+
dp.Field(key="description", label=_("Description")),
|
|
105
|
+
dp.Field(key="important", label=_("Important")),
|
|
106
|
+
dp.Field(key="source", label=_("Source")),
|
|
107
|
+
]
|
|
108
|
+
)
|
|
109
|
+
return dp.ListDisplay(
|
|
110
|
+
fields=fields,
|
|
111
|
+
formatting=[
|
|
112
|
+
dp.Formatting(
|
|
113
|
+
column="sentiment",
|
|
114
|
+
formatting_rules=[
|
|
115
|
+
dp.FormattingRule(condition=("==", s.value), style={"backgroundColor": s.get_color()})
|
|
116
|
+
for s in NewsRelationship.SentimentChoices
|
|
117
|
+
],
|
|
118
|
+
)
|
|
119
|
+
],
|
|
120
|
+
legends=[
|
|
121
|
+
dp.Legend(
|
|
122
|
+
items=[dp.LegendItem(icon=s.get_color(), label=s.label) for s in NewsRelationship.SentimentChoices]
|
|
123
|
+
)
|
|
124
|
+
],
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class NewsSourceDisplayConfig(DisplayViewConfig):
|
|
129
|
+
def get_instance_display(self) -> Display:
|
|
130
|
+
return create_simple_display(
|
|
131
|
+
[
|
|
132
|
+
[repeat_field(2, "title")],
|
|
133
|
+
["datetime", "language", "link"],
|
|
134
|
+
[repeat_field(2, "description")],
|
|
135
|
+
]
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
139
|
+
return dp.ListDisplay(
|
|
140
|
+
fields=[
|
|
141
|
+
dp.Field(key="datetime", label=_("Datetime")),
|
|
142
|
+
dp.Field(key="title", label=_("Title")),
|
|
143
|
+
dp.Field(key="description", label=_("Description")),
|
|
144
|
+
dp.Field(key="language", label=_("Language")),
|
|
145
|
+
# dp.Field(key="tags", label="_(Edited")),
|
|
146
|
+
# dp.Field(key="link", label="_(Link"))
|
|
147
|
+
]
|
|
148
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from rest_framework.reverse import reverse
|
|
2
|
+
from wbcore.metadata.configs.endpoints import EndpointViewConfig
|
|
3
|
+
from wbcore.utils.urls import get_urlencode_endpoint
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NewsEndpointConfig(EndpointViewConfig):
|
|
7
|
+
def get_endpoint(self, **kwargs):
|
|
8
|
+
return None
|
|
9
|
+
|
|
10
|
+
def get_instance_endpoint(self, **kwargs):
|
|
11
|
+
return reverse("wbnews:news-list", request=self.request)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class NewsSourceEndpointConfig(NewsEndpointConfig):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class NewsRelationshipEndpointConfig(EndpointViewConfig):
|
|
19
|
+
def get_endpoint(self, **kwargs):
|
|
20
|
+
return reverse("wbnews:newsrelationship-list", args=[], request=self.request)
|
|
21
|
+
|
|
22
|
+
def get_create_endpoint(self, **kwargs):
|
|
23
|
+
params = {}
|
|
24
|
+
if ct := self.view.content_type:
|
|
25
|
+
params["content_type"] = ct.id
|
|
26
|
+
if object_id := self.view.object_id:
|
|
27
|
+
params["object_id"] = object_id
|
|
28
|
+
return get_urlencode_endpoint(self.get_endpoint(**kwargs), params)
|
|
29
|
+
|
|
30
|
+
# def get_instance_endpoint(self, **kwargs):
|
|
31
|
+
# return reverse("wbnews:news-list", args=[], request=self.request)
|
|
32
|
+
#
|
|
33
|
+
# def get_update_endpoint(self, **kwargs):
|
|
34
|
+
# return self.get_endpoint(**kwargs)
|
wbnews/viewsets/menu.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from django.utils.translation import gettext_lazy as _
|
|
2
|
+
from wbcore.menus import ItemPermission, MenuItem
|
|
3
|
+
from wbcore.permissions.shortcuts import is_internal_user
|
|
4
|
+
|
|
5
|
+
NEWS_MENUITEM = MenuItem(
|
|
6
|
+
label=_("News"),
|
|
7
|
+
endpoint="wbnews:news-list",
|
|
8
|
+
permission=ItemPermission(permissions=["wbnews.view_news"]),
|
|
9
|
+
)
|
|
10
|
+
NEWSRELATIONSHIP_MENUITEM = MenuItem(
|
|
11
|
+
label=_("News Relationships"),
|
|
12
|
+
endpoint="wbnews:newsrelationship-list",
|
|
13
|
+
permission=ItemPermission(permissions=["wbnews.view_news"]),
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
NEWSSOURCE_MENUITEM = MenuItem(
|
|
17
|
+
label=_("Sources"),
|
|
18
|
+
endpoint="wbnews:source-list",
|
|
19
|
+
permission=ItemPermission(
|
|
20
|
+
method=lambda request: is_internal_user(request.user), permissions=["wbnews.view_newssource"]
|
|
21
|
+
),
|
|
22
|
+
add=MenuItem(
|
|
23
|
+
label=_("Create Source"),
|
|
24
|
+
endpoint="wbnews:source-list",
|
|
25
|
+
permission=ItemPermission(
|
|
26
|
+
method=lambda request: is_internal_user(request.user), permissions=["wbnews.add_newssource"]
|
|
27
|
+
),
|
|
28
|
+
),
|
|
29
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from django.utils.translation import gettext as _
|
|
2
|
+
from wbcore.metadata.configs.titles import TitleViewConfig
|
|
3
|
+
|
|
4
|
+
from wbnews.models import NewsSource
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SourceModelTitleConfig(TitleViewConfig):
|
|
8
|
+
def get_list_title(self):
|
|
9
|
+
return _("Sources")
|
|
10
|
+
|
|
11
|
+
def get_instance_title(self):
|
|
12
|
+
if "pk" in self.view.kwargs:
|
|
13
|
+
return _("Source: {source}").format(source=str(self.view.get_object()))
|
|
14
|
+
return _("News Source")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class NewsTitleConfig(TitleViewConfig):
|
|
18
|
+
def get_list_title(self):
|
|
19
|
+
return _("News Flow")
|
|
20
|
+
|
|
21
|
+
def get_instance_title(self):
|
|
22
|
+
if "pk" in self.view.kwargs:
|
|
23
|
+
return str(self.view.get_object())
|
|
24
|
+
return _("News")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class NewsSourceModelTitleConfig(TitleViewConfig):
|
|
28
|
+
def get_list_title(self):
|
|
29
|
+
source = NewsSource.objects.get(id=self.view.kwargs["source_id"])
|
|
30
|
+
return _("News from {source}").format(source=source.title)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class NewsRelationshipTitleConfig(TitleViewConfig):
|
|
34
|
+
def get_list_title(self):
|
|
35
|
+
if self.view and (content_object := self.view.content_object):
|
|
36
|
+
return _("News Article for {}").format(str(content_object))
|
|
37
|
+
return _("News Article")
|
|
38
|
+
|
|
39
|
+
def get_instance_title(self):
|
|
40
|
+
try:
|
|
41
|
+
instance = self.view.get_object()
|
|
42
|
+
return str(instance)
|
|
43
|
+
except AssertionError:
|
|
44
|
+
return _("News Article")
|
wbnews/viewsets/views.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from functools import reduce
|
|
2
|
+
from operator import or_
|
|
3
|
+
|
|
4
|
+
from django.contrib.contenttypes.models import ContentType
|
|
5
|
+
from django.db.models import F, Q
|
|
6
|
+
from django.shortcuts import get_object_or_404
|
|
7
|
+
from django.utils.functional import cached_property
|
|
8
|
+
from rest_framework.decorators import action
|
|
9
|
+
from rest_framework.permissions import IsAdminUser
|
|
10
|
+
from rest_framework.response import Response
|
|
11
|
+
from wbcore import viewsets
|
|
12
|
+
from wbcore.content_type.utils import get_ancestors_content_type
|
|
13
|
+
|
|
14
|
+
from wbnews.models import News, NewsRelationship, NewsSource
|
|
15
|
+
from wbnews.serializers import (
|
|
16
|
+
NewsModelSerializer,
|
|
17
|
+
NewsRelationshipModelSerializer,
|
|
18
|
+
NewsRepresentationSerializer,
|
|
19
|
+
SourceModelSerializer,
|
|
20
|
+
SourceRepresentationSerializer,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from ..filters import NewsFilterSet, NewsRelationshipFilterSet
|
|
24
|
+
from .buttons import NewsButtonConfig, NewsRelationshipButtonConfig
|
|
25
|
+
from .display import (
|
|
26
|
+
NewsDisplayConfig,
|
|
27
|
+
NewsRelationshipDisplayConfig,
|
|
28
|
+
NewsSourceDisplayConfig,
|
|
29
|
+
SourceDisplayConfig,
|
|
30
|
+
)
|
|
31
|
+
from .endpoints import NewsEndpointConfig, NewsRelationshipEndpointConfig, NewsSourceEndpointConfig
|
|
32
|
+
from .titles import (
|
|
33
|
+
NewsRelationshipTitleConfig,
|
|
34
|
+
NewsSourceModelTitleConfig,
|
|
35
|
+
NewsTitleConfig,
|
|
36
|
+
SourceModelTitleConfig,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class NewsRepresentationViewSet(viewsets.RepresentationViewSet):
|
|
41
|
+
queryset = News.objects.all()
|
|
42
|
+
serializer_class = NewsRepresentationSerializer
|
|
43
|
+
filterset_fields = {"title": ["icontains"]}
|
|
44
|
+
ordering_fields = ["datetime"]
|
|
45
|
+
ordering = ["-datetime"]
|
|
46
|
+
search_fields = ["title", "description"]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class SourceRepresentationViewSet(viewsets.RepresentationViewSet):
|
|
50
|
+
queryset = NewsSource.objects.all()
|
|
51
|
+
serializer_class = SourceRepresentationSerializer
|
|
52
|
+
filterset_fields = {"title": ["icontains"]}
|
|
53
|
+
ordering_fields = ordering = ["title"]
|
|
54
|
+
search_fields = ["title"]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class SourceModelViewSet(viewsets.ReadOnlyModelViewSet):
|
|
58
|
+
serializer_class = SourceModelSerializer
|
|
59
|
+
queryset = NewsSource.objects.all()
|
|
60
|
+
filterset_fields = {"title": ["icontains"]}
|
|
61
|
+
ordering_fields = ordering = ["title"]
|
|
62
|
+
search_fields = ["title"]
|
|
63
|
+
|
|
64
|
+
display_config_class = SourceDisplayConfig
|
|
65
|
+
title_config_class = SourceModelTitleConfig
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class NewsModelViewSet(viewsets.ReadOnlyModelViewSet):
|
|
69
|
+
serializer_class = NewsModelSerializer
|
|
70
|
+
filterset_class = NewsFilterSet
|
|
71
|
+
ordering_fields = ["datetime"]
|
|
72
|
+
ordering = ["-datetime"]
|
|
73
|
+
search_fields = ["title", "description"]
|
|
74
|
+
|
|
75
|
+
queryset = News.objects.select_related("source")
|
|
76
|
+
|
|
77
|
+
button_config_class = NewsButtonConfig
|
|
78
|
+
display_config_class = NewsDisplayConfig
|
|
79
|
+
title_config_class = NewsTitleConfig
|
|
80
|
+
endpoint_config_class = NewsEndpointConfig
|
|
81
|
+
|
|
82
|
+
def get_queryset(self):
|
|
83
|
+
qs = super().get_queryset()
|
|
84
|
+
if (content_type_id := self.kwargs.get("content_type")) and (object_id := self.kwargs.get("content_id")):
|
|
85
|
+
content_type = ContentType.objects.get_for_id(content_type_id)
|
|
86
|
+
content_object = content_type.get_object_for_this_type(id=object_id)
|
|
87
|
+
content_types = list(get_ancestors_content_type(content_type))
|
|
88
|
+
# we ensure that for MPTT model, all descendants news are included as well
|
|
89
|
+
if hasattr(content_object, "get_family"):
|
|
90
|
+
conditions = []
|
|
91
|
+
for descendant in content_object.get_family():
|
|
92
|
+
for ct in content_types:
|
|
93
|
+
conditions.append(Q(content_type=ct, object_id=descendant.id))
|
|
94
|
+
else:
|
|
95
|
+
conditions = [Q(content_type=ct, object_id=object_id) for ct in content_types]
|
|
96
|
+
relationships = NewsRelationship.objects.filter(reduce(or_, conditions))
|
|
97
|
+
qs = qs.filter(relationships__in=relationships)
|
|
98
|
+
return qs.distinct()
|
|
99
|
+
|
|
100
|
+
@action(detail=True, methods=["PATCH"], permission_classes=[IsAdminUser])
|
|
101
|
+
def refreshrelationship(self, request, pk=None):
|
|
102
|
+
"""
|
|
103
|
+
Action to allow administrator to reset news relationships and recreate them on demand.
|
|
104
|
+
"""
|
|
105
|
+
new = get_object_or_404(News, pk=pk)
|
|
106
|
+
relationships = new.relationships.all()
|
|
107
|
+
if content_type_id := self.request.GET.get("content_type_id", None):
|
|
108
|
+
relationships = relationships.filter(content_type_id=content_type_id)
|
|
109
|
+
if object_id := self.request.GET.get("content_id", None):
|
|
110
|
+
relationships = relationships.filter(object_id=object_id)
|
|
111
|
+
relationships.delete()
|
|
112
|
+
new.update_and_create_news_relationships()
|
|
113
|
+
return Response({"status": "ok"})
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class NewsRelationshipModelViewSet(viewsets.ModelViewSet):
|
|
117
|
+
IDENTIFIER = "wbnews:newsrelationship"
|
|
118
|
+
serializer_class = NewsRelationshipModelSerializer
|
|
119
|
+
queryset = NewsRelationship.objects.all()
|
|
120
|
+
display_config_class = NewsRelationshipDisplayConfig
|
|
121
|
+
title_config_class = NewsRelationshipTitleConfig
|
|
122
|
+
button_config_class = NewsRelationshipButtonConfig
|
|
123
|
+
endpoint_config_class = NewsRelationshipEndpointConfig
|
|
124
|
+
ordering = ["-datetime"]
|
|
125
|
+
filterset_class = NewsRelationshipFilterSet
|
|
126
|
+
|
|
127
|
+
@cached_property
|
|
128
|
+
def content_type(self) -> ContentType:
|
|
129
|
+
if content_type_id := self.request.GET.get("content_type", self.request.POST.get("content_type")):
|
|
130
|
+
return ContentType.objects.get_for_id(content_type_id)
|
|
131
|
+
|
|
132
|
+
@cached_property
|
|
133
|
+
def object_id(self) -> int:
|
|
134
|
+
return self.request.GET.get("object_id", self.request.POST.get("object_id"))
|
|
135
|
+
|
|
136
|
+
@cached_property
|
|
137
|
+
def content_object(self):
|
|
138
|
+
if (object_id := self.object_id) and self.content_type:
|
|
139
|
+
return self.content_type.get_object_for_this_type(id=object_id)
|
|
140
|
+
|
|
141
|
+
def get_queryset(self):
|
|
142
|
+
queryset = super().get_queryset()
|
|
143
|
+
|
|
144
|
+
if self.content_type:
|
|
145
|
+
content_types = list(get_ancestors_content_type(self.content_type))
|
|
146
|
+
queryset = queryset.filter(content_type__in=content_types)
|
|
147
|
+
if self.content_object:
|
|
148
|
+
# we ensure that for MPTT model, all descendants news are included as well
|
|
149
|
+
if hasattr(self.content_object, "get_family"):
|
|
150
|
+
queryset = queryset.filter(object_id__in=[obj.id for obj in self.content_object.get_family()])
|
|
151
|
+
else:
|
|
152
|
+
queryset = queryset.filter(object_id=self.object_id)
|
|
153
|
+
return queryset.select_related("news").annotate(
|
|
154
|
+
source=F("news__source"),
|
|
155
|
+
title=F("news__title"),
|
|
156
|
+
description=F("news__description"),
|
|
157
|
+
summary=F("news__summary"),
|
|
158
|
+
datetime=F("news__datetime"),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class NewsSourceModelViewSet(NewsModelViewSet):
|
|
163
|
+
def get_queryset(self):
|
|
164
|
+
return super().get_queryset().filter(source_id=self.kwargs["source_id"])
|
|
165
|
+
|
|
166
|
+
display_config_class = NewsSourceDisplayConfig
|
|
167
|
+
title_config_class = NewsSourceModelTitleConfig
|
|
168
|
+
endpoint_config_class = NewsSourceEndpointConfig
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
wbnews/.coveragerc,sha256=OOkT651L0NuoSVSXKZiLAbnQmHe9DRoLOzo1_S_buQc,383
|
|
2
|
+
wbnews/__init__.py,sha256=J-j-u0itpEFT6irdmWmixQqYMadNl1X91TxUmoiLHMI,22
|
|
3
|
+
wbnews/admin.py,sha256=cn-PF0LclyQ0FFNfw0mdVoW7v3g0b9uotTiAFKmLVPQ,832
|
|
4
|
+
wbnews/apps.py,sha256=l4kfE3Pux84Fb34xNgKDxcxRHuPCp6odCGFE9Sa3Wzw,212
|
|
5
|
+
wbnews/factories.py,sha256=_EBIeMafeiyAjnSAG-xXxdqw7vVwAu8u-DfdLn8mtHk,1172
|
|
6
|
+
wbnews/serializers.py,sha256=KihExQ_GS1fNZnojryEcfU32xlTiPn-K2WGO0Zc84Cw,4732
|
|
7
|
+
wbnews/signals.py,sha256=eqipwffwJnDQWUZ9VTKr5Jp-OMXLmVSNwoIsawnCKvM,192
|
|
8
|
+
wbnews/tasks.py,sha256=ce9JbXKnJnf7La74h0LPwm3yrygHNe1BKZju_4m1itw,384
|
|
9
|
+
wbnews/urls.py,sha256=2Gs9RGU8x6tNOLJiuG17n_ik82QVb8jlw7bU07Lk_S4,1008
|
|
10
|
+
wbnews/utils.py,sha256=h4TdMbUL0qQ2h3o3jEpGuGwT90TWiryVRtBXc7avLW0,1955
|
|
11
|
+
wbnews/filters/__init__.py,sha256=FXJcPsLQePCU-fzjpIu44Dsdu9vCckLHr0Kr-8Z_-C4,59
|
|
12
|
+
wbnews/filters/news.py,sha256=glG45wx_Jxee57H43oqCCJIjQumrNUh8pVXiD0hBM6E,1662
|
|
13
|
+
wbnews/fixtures/wbnews.yaml,sha256=cDu1UWYwIFxz-hdivW7rxLYsNOweBm4GdN1GDsycN90,173164
|
|
14
|
+
wbnews/import_export/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
wbnews/import_export/backends/__init__.py,sha256=_2HnB9uCuGhQDNg-Z0V2uIvKn26LtRBXAxUBoNetBIo,30
|
|
16
|
+
wbnews/import_export/backends/news.py,sha256=QqMeAWYh4U3W4Sng0HlHx11RoR1LV_WZmRUr58dYrVg,1461
|
|
17
|
+
wbnews/import_export/handlers/__init__.py,sha256=zOeENt9cpEcSLG9ZaVb4otmbTnLAa0XdTPsUjD11dXs,36
|
|
18
|
+
wbnews/import_export/handlers/news.py,sha256=cdrtWIP3XOU8NMYZKF8VLYH5qHmPLboUm_GwNAvO2ew,2181
|
|
19
|
+
wbnews/import_export/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
wbnews/import_export/parsers/emails/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
wbnews/import_export/parsers/emails/news.py,sha256=8fSgjSPuSmdfGKV1IxLMWriqGhDAG-tiZUyAgWpjZ_M,1236
|
|
22
|
+
wbnews/import_export/parsers/emails/utils.py,sha256=k7R1HZx18FKXRq10COARFgHjjBadsWe1DY3AHCrwHRs,2207
|
|
23
|
+
wbnews/import_export/parsers/rss/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
wbnews/import_export/parsers/rss/news.py,sha256=H89avqOU_AUAyHiIXd_tfoMbcqy67GgDQ2-ucihDpks,2076
|
|
25
|
+
wbnews/locale/de/LC_MESSAGES/django.mo,sha256=M70N6el-I7EymxHLw9n773Bimbztf8s8equWa9SydBs,1283
|
|
26
|
+
wbnews/locale/de/LC_MESSAGES/django.po,sha256=furtxh-NgkodwE4dv0uXaRtWF2z3NxWtEw64tH9OMN4,3494
|
|
27
|
+
wbnews/locale/de/LC_MESSAGES/django.po.translated,sha256=ILRIDL_vON91Do5QhZr5N85Y4vsOAIHsaU8QX0FiEA4,3962
|
|
28
|
+
wbnews/locale/en/LC_MESSAGES/django.mo,sha256=UXCQbz2AxBvh-IQ7bGgjoBnijo8h9DfE9107A-2Mgkk,337
|
|
29
|
+
wbnews/locale/en/LC_MESSAGES/django.po,sha256=K7SPoXdLZHyOOAoIOEydgJwl1qdQMrK3uapd4EMrVIg,3125
|
|
30
|
+
wbnews/locale/fr/LC_MESSAGES/django.mo,sha256=t4lh3zX7kshbDAFzXa5HU_YGPXkPzKqODNXL2MeZ5KQ,429
|
|
31
|
+
wbnews/locale/fr/LC_MESSAGES/django.po,sha256=kRBjvETEy0GMPqX0H6EArGqrtzhYXwswjUW-JDajlbM,3232
|
|
32
|
+
wbnews/migrations/0001_initial_squashed_0005_alter_news_import_source.py,sha256=4qxqfpAYVeU16GsWaj7kUbtOk0ZLzuECTfzhUfmni2A,14596
|
|
33
|
+
wbnews/migrations/0006_alter_news_language.py,sha256=necqSWKi20sHLok-RO9He3vnmMlmmdx07AiN3lnZPBM,4638
|
|
34
|
+
wbnews/migrations/0007_auto_20240103_0955.py,sha256=YzkH_LSWH_8qdw_BrKaTN5vqLNCPnjMlJZxs03Xbbvw,1478
|
|
35
|
+
wbnews/migrations/0008_alter_news_language.py,sha256=4tbpcVSey9PJOdf8xWndl1R8GmhmflpVQtI8YTwcevw,4648
|
|
36
|
+
wbnews/migrations/0009_newsrelationship_analysis_newsrelationship_sentiment.py,sha256=ud_yO6skjVx2s32snxzai6Z4Uao1s-40v6UZaq4k64I,3432
|
|
37
|
+
wbnews/migrations/0010_newsrelationship_important.py,sha256=seK-bFIzXa6uzja0gPnRhwS4vNgY_sR3sMm_OmP8sZE,440
|
|
38
|
+
wbnews/migrations/0011_newsrelationship_content_object_repr.py,sha256=oJUhx__5WI6TjPGPqqEqBgb3yDluc02hhh05nXTjbHw,428
|
|
39
|
+
wbnews/migrations/0012_alter_news_unique_together_news_identifier_and_more.py,sha256=SLtQiREJYMwOytGGLqaCYr_9pSeD_XD5ax7lXSETT3w,3111
|
|
40
|
+
wbnews/migrations/0013_alter_news_datetime.py,sha256=q4Gbxo25jClsv9b1kfTqBLmpPNHAq7LxOgEZeLYYRk4,497
|
|
41
|
+
wbnews/migrations/0014_newsrelationship_unique_news_relationship.py,sha256=aZUHLMKRMaXHJrrbnV9O2ZJRDVjbpkb9NjVPB7VKVW0,1073
|
|
42
|
+
wbnews/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
+
wbnews/models/__init__.py,sha256=KKIcQbpCPCVNJUPJs2MtpN9Q2Wb34Qdk-C7w6AAOy7w,99
|
|
44
|
+
wbnews/models/news.py,sha256=yRbOpVG69yssvJPzv9bZJGMoFcb9n2uLaG2mz2j8oxM,5203
|
|
45
|
+
wbnews/models/relationships.py,sha256=bcQbRa-ObS9h67pIuIrodD63RnkzbaOaRT4L6ctBoI0,1841
|
|
46
|
+
wbnews/models/sources.py,sha256=N3-rBg4myeGG_stHvKiNnSoH0yS-LS_Zr_UeKPMBr5s,2629
|
|
47
|
+
wbnews/models/utils.py,sha256=1JQxV4WxmmFGl7MdVtJoEeao3vnqqVwCi7mhSToaUvM,600
|
|
48
|
+
wbnews/models/llm/cleaned_news.py,sha256=PA0McsgMmR0TOZUNWs55sBnsCXGbaC61VtVFbJ8vx28,2226
|
|
49
|
+
wbnews/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
50
|
+
wbnews/tests/conftest.py,sha256=UEZOYH5Av-Cqqq5t8WQCR7QJdNnajhthBPpF8AnwQjY,186
|
|
51
|
+
wbnews/tests/test_models.py,sha256=op79cYyz9f5dX1uRBztw-E0J4HYAY8K-7cz4kBCN0qk,3278
|
|
52
|
+
wbnews/tests/test_utils.py,sha256=PsyHH_F_y-Uy3mdVgDINH19bPEd1bmZT_UQ7yu87BNU,278
|
|
53
|
+
wbnews/tests/tests.py,sha256=OADY-vbKZBe0bjjVEO1KNzRYAP2JA9mWkO9pZuh1TSs,280
|
|
54
|
+
wbnews/tests/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
55
|
+
wbnews/tests/parsers/test_emails.py,sha256=dStdTPI7Ns1jSw5PDbDEc84FJaoNPnBHC4BskWDDMxY,1073
|
|
56
|
+
wbnews/viewsets/__init__.py,sha256=2OhRiJy0MVK9TdMpFmS9x9jl_gM-CjBxUoUHlZB3_8U,531
|
|
57
|
+
wbnews/viewsets/buttons.py,sha256=6m_IdRYCQgTH4mD51DUoOa8Vx1y1-2zPQydUdvL_nF4,1788
|
|
58
|
+
wbnews/viewsets/display.py,sha256=fwMZLlwxHcNHM4AppwYpYTOicLD_pXaQ4QeFeIl4whk,5315
|
|
59
|
+
wbnews/viewsets/endpoints.py,sha256=2slGDJin_SA2heWsIaMdNTUN46FqZJvusbY1jhAaeZM,1165
|
|
60
|
+
wbnews/viewsets/menu.py,sha256=XTShfTIykN9t7oclosPfFVb1r6o46QyglEEe1C7QCMk,979
|
|
61
|
+
wbnews/viewsets/titles.py,sha256=iMyiGBMBpzng8s2ySVLqEOwueHRnAoEuc75dt9nCPjc,1367
|
|
62
|
+
wbnews/viewsets/views.py,sha256=SMCDT6bJMQblyqX5cQ7X3qDe0zxTVWh1q7Aqj0fBo2Q,6795
|
|
63
|
+
wbnews-1.58.3.dist-info/METADATA,sha256=Of_T-Un-gjp033MNIR24CfpYEs5pZKZbxp24XgKz7SE,215
|
|
64
|
+
wbnews-1.58.3.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
|
|
65
|
+
wbnews-1.58.3.dist-info/RECORD,,
|