remove UniqueContentRule model
Some checks are pending
Build and Push Docker Image / build (push) Waiting to run
Some checks are pending
Build and Push Docker Image / build (push) Waiting to run
This commit is contained in:
parent
cb227c6daf
commit
b6d3efa014
@ -10,7 +10,6 @@ from apps.home.models import (
|
|||||||
ContentFilter,
|
ContentFilter,
|
||||||
MessageMutator,
|
MessageMutator,
|
||||||
MessageStyle,
|
MessageStyle,
|
||||||
UniqueContentRule,
|
|
||||||
DiscordChannel,
|
DiscordChannel,
|
||||||
Subscription,
|
Subscription,
|
||||||
Content,
|
Content,
|
||||||
@ -200,14 +199,6 @@ class MessageStyleSerializer(DynamicModelSerializer):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
# region Rules
|
|
||||||
|
|
||||||
class UniqueContentRuleSerializer(DynamicModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = UniqueContentRule
|
|
||||||
fields = ("id", "name", "value")
|
|
||||||
|
|
||||||
|
|
||||||
# region Subscriptions
|
# region Subscriptions
|
||||||
|
|
||||||
class DiscordChannelField(serializers.PrimaryKeyRelatedField):
|
class DiscordChannelField(serializers.PrimaryKeyRelatedField):
|
||||||
@ -249,7 +240,6 @@ class SubscriptionSerializer(DynamicModelSerializer):
|
|||||||
allow_null=False
|
allow_null=False
|
||||||
)
|
)
|
||||||
message_style_detail = serializers.SerializerMethodField()
|
message_style_detail = serializers.SerializerMethodField()
|
||||||
unique_rules_detail = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Subscription
|
model = Subscription
|
||||||
@ -268,9 +258,7 @@ class SubscriptionSerializer(DynamicModelSerializer):
|
|||||||
"filters",
|
"filters",
|
||||||
"filters_detail",
|
"filters_detail",
|
||||||
"message_style",
|
"message_style",
|
||||||
"message_style_detail",
|
"message_style_detail"
|
||||||
"unique_rules",
|
|
||||||
"unique_rules_detail"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_channels_detail(self, obj: Subscription):
|
def get_channels_detail(self, obj: Subscription):
|
||||||
@ -291,12 +279,6 @@ class SubscriptionSerializer(DynamicModelSerializer):
|
|||||||
return MessageStyleSerializer(obj.message_style).data
|
return MessageStyleSerializer(obj.message_style).data
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_unique_rules_detail(self, obj: Subscription):
|
|
||||||
request = self.context.get("request")
|
|
||||||
if request.method == "GET":
|
|
||||||
return UniqueContentRuleSerializer(obj.unique_rules.all(), many=True).data
|
|
||||||
return []
|
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
server = data.get("server") or self.context.get("server")
|
server = data.get("server") or self.context.get("server")
|
||||||
if not server:
|
if not server:
|
||||||
|
@ -15,9 +15,7 @@ from .views import (
|
|||||||
Subscription_ListView,
|
Subscription_ListView,
|
||||||
Subscription_DetailView,
|
Subscription_DetailView,
|
||||||
Content_ListView,
|
Content_ListView,
|
||||||
Content_DetailView,
|
Content_DetailView
|
||||||
UniqueContentRule_ListView,
|
|
||||||
UniqueContentRule_DetailView
|
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@ -58,11 +56,5 @@ urlpatterns = [
|
|||||||
path("content/", include([
|
path("content/", include([
|
||||||
path("", Content_ListView.as_view()),
|
path("", Content_ListView.as_view()),
|
||||||
path("<int:pk>/", Content_DetailView.as_view())
|
path("<int:pk>/", Content_DetailView.as_view())
|
||||||
])),
|
|
||||||
|
|
||||||
# region Unique Rules
|
|
||||||
path("unique-content-rules/", include([
|
|
||||||
path("", UniqueContentRule_ListView.as_view()),
|
|
||||||
path("<int:pk>/", UniqueContentRule_DetailView.as_view())
|
|
||||||
]))
|
]))
|
||||||
]
|
]
|
||||||
|
@ -17,8 +17,7 @@ from apps.home.models import (
|
|||||||
MessageMutator,
|
MessageMutator,
|
||||||
MessageStyle,
|
MessageStyle,
|
||||||
Subscription,
|
Subscription,
|
||||||
Content,
|
Content
|
||||||
UniqueContentRule
|
|
||||||
)
|
)
|
||||||
from apps.authentication.models import DiscordUser, ServerMember
|
from apps.authentication.models import DiscordUser, ServerMember
|
||||||
from .metadata import ExpandedMetadata
|
from .metadata import ExpandedMetadata
|
||||||
@ -28,8 +27,7 @@ from .serializers import (
|
|||||||
MessageMutatorSerializer,
|
MessageMutatorSerializer,
|
||||||
MessageStyleSerializer,
|
MessageStyleSerializer,
|
||||||
SubscriptionSerializer,
|
SubscriptionSerializer,
|
||||||
ContentSerializer,
|
ContentSerializer
|
||||||
UniqueContentRuleSerializer
|
|
||||||
)
|
)
|
||||||
from .permissions import HasServerAccess
|
from .permissions import HasServerAccess
|
||||||
from .errors import NotAMemberError
|
from .errors import NotAMemberError
|
||||||
@ -200,7 +198,7 @@ class MessageStyle_DetailView(ChangableDetailView):
|
|||||||
# region Subscriptions
|
# region Subscriptions
|
||||||
|
|
||||||
class Subscription_ListView(ListCreateView):
|
class Subscription_ListView(ListCreateView):
|
||||||
filterset_fields = ("id", "server", "name", "url", "created_at", "updated_at", "extra_notes", "active", "publish_threshold", "filters", "message_style", "unique_rules")
|
filterset_fields = ("id", "server", "name", "url", "created_at", "updated_at", "extra_notes", "active", "publish_threshold", "filters", "message_style")
|
||||||
search_fields = ("name", "url", "extra_notes")
|
search_fields = ("name", "url", "extra_notes")
|
||||||
ordering_fields = ("id", "server", "name", "url", "created_at", "updated_at", "extra_notes", "active", "message_style")
|
ordering_fields = ("id", "server", "name", "url", "created_at", "updated_at", "extra_notes", "active", "message_style")
|
||||||
serializer_class = SubscriptionSerializer
|
serializer_class = SubscriptionSerializer
|
||||||
@ -234,23 +232,23 @@ class ContentFilterBackend(BaseFilterBackend):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_MATCH_ANY_PARAM = "match_any"
|
_MATCH_ANY_PARAM = "match_any"
|
||||||
_PAGINATION_PARAMS = [
|
_IGNORE_PARAMS = [
|
||||||
DefaultPagination.page_query_param,
|
DefaultPagination.page_query_param,
|
||||||
DefaultPagination.page_size_query_param
|
DefaultPagination.page_size_query_param,
|
||||||
|
"search",
|
||||||
|
"subscription"
|
||||||
]
|
]
|
||||||
_SUB_PARAM = "subscription"
|
|
||||||
|
|
||||||
def filter_queryset(self, request, queryset, view):
|
def filter_queryset(self, request, queryset, view):
|
||||||
match_any = request.query_params.get(self._MATCH_ANY_PARAM) == "true"
|
|
||||||
filters = Q()
|
filters = Q()
|
||||||
|
|
||||||
for param, value in request.query_params.items():
|
for param, value in request.query_params.items():
|
||||||
if param == self._MATCH_ANY_PARAM or param in self._PAGINATION_PARAMS:
|
if param in self._IGNORE_PARAMS or param == self._MATCH_ANY_PARAM:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
query = Q(**{param: value})
|
query = Q(**{param: value})
|
||||||
|
|
||||||
if match_any and param != self._SUB_PARAM:
|
if param not in self._IGNORE_PARAMS:
|
||||||
filters |= query
|
filters |= query
|
||||||
else:
|
else:
|
||||||
filters &= query
|
filters &= query
|
||||||
@ -260,8 +258,6 @@ class ContentFilterBackend(BaseFilterBackend):
|
|||||||
|
|
||||||
class Content_ListView(ListCreateView):
|
class Content_ListView(ListCreateView):
|
||||||
search_fields = (
|
search_fields = (
|
||||||
"subscription",
|
|
||||||
"subscription__server",
|
|
||||||
"item_id",
|
"item_id",
|
||||||
"item_guid",
|
"item_guid",
|
||||||
"item_url",
|
"item_url",
|
||||||
@ -276,7 +272,7 @@ class Content_ListView(ListCreateView):
|
|||||||
"item_feed_title",
|
"item_feed_title",
|
||||||
"item_feed_url"
|
"item_feed_url"
|
||||||
)
|
)
|
||||||
filterset_fields = search_fields + ("id",)
|
filterset_fields = search_fields + ("id", "subscription", "subscription__server")
|
||||||
ordering_fields = filterset_fields
|
ordering_fields = filterset_fields
|
||||||
serializer_class = ContentSerializer
|
serializer_class = ContentSerializer
|
||||||
filter_backends = [
|
filter_backends = [
|
||||||
@ -306,22 +302,3 @@ class Content_DetailView(ChangableDetailView):
|
|||||||
servers = ServerMember.objects.filter(user=self.request.user).values_list("server", flat=True)
|
servers = ServerMember.objects.filter(user=self.request.user).values_list("server", flat=True)
|
||||||
subscriptions = Subscription.objects.filter(server__in=servers).values_list("id", flat=True)
|
subscriptions = Subscription.objects.filter(server__in=servers).values_list("id", flat=True)
|
||||||
return Content.objects.filter(subscription__in=subscriptions)
|
return Content.objects.filter(subscription__in=subscriptions)
|
||||||
|
|
||||||
|
|
||||||
# region Unique Rules
|
|
||||||
|
|
||||||
class UniqueContentRule_ListView(ListCreateView):
|
|
||||||
filterset_fields = ("id", "name", "value")
|
|
||||||
search_fields = ("name", "value")
|
|
||||||
ordering_fields = ("id", "name", "value")
|
|
||||||
serializer_class = UniqueContentRuleSerializer
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return UniqueContentRule.objects.all()
|
|
||||||
|
|
||||||
|
|
||||||
class UniqueContentRule_DetailView(ChangableDetailView):
|
|
||||||
serializer_class = UniqueContentRuleSerializer
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return UniqueContentRule.objects.all()
|
|
||||||
|
@ -9,8 +9,7 @@ from .models import (
|
|||||||
MessageStyle,
|
MessageStyle,
|
||||||
DiscordChannel,
|
DiscordChannel,
|
||||||
Subscription,
|
Subscription,
|
||||||
Content,
|
Content
|
||||||
UniqueContentRule
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -108,13 +107,3 @@ class ContentAdmin(admin.ModelAdmin):
|
|||||||
"item_title",
|
"item_title",
|
||||||
"item_content_hash"
|
"item_content_hash"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@admin.register(UniqueContentRule)
|
|
||||||
class UniqueContentRule(admin.ModelAdmin):
|
|
||||||
list_display = [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"value"
|
|
||||||
]
|
|
||||||
list_display_links = ["name"]
|
|
||||||
|
@ -185,28 +185,6 @@ def create_default_items(sender, instance, created, **kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# region Unique Content Rule
|
|
||||||
|
|
||||||
class UniqueContentRule(models.Model):
|
|
||||||
"""
|
|
||||||
Definitions for what content should be unique
|
|
||||||
Instances of this model are predefined via migrations.
|
|
||||||
Manual editing should be avoided at all costs!
|
|
||||||
"""
|
|
||||||
|
|
||||||
id = models.AutoField(primary_key=True)
|
|
||||||
name = models.CharField(max_length=64)
|
|
||||||
value = models.CharField(max_length=32)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = "unique content rule"
|
|
||||||
verbose_name_plural = "unique content rules"
|
|
||||||
get_latest_by = "id"
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
|
|
||||||
# region Discord Channel
|
# region Discord Channel
|
||||||
|
|
||||||
class DiscordChannel(models.Model):
|
class DiscordChannel(models.Model):
|
||||||
@ -247,7 +225,6 @@ class Subscription(models.Model):
|
|||||||
channels = models.ManyToManyField(to=DiscordChannel, related_name="subscriptions", blank=False)
|
channels = models.ManyToManyField(to=DiscordChannel, related_name="subscriptions", blank=False)
|
||||||
filters = models.ManyToManyField(to=ContentFilter, blank=True)
|
filters = models.ManyToManyField(to=ContentFilter, blank=True)
|
||||||
message_style = models.ForeignKey(to=MessageStyle, on_delete=models.SET_NULL, null=True, blank=False)
|
message_style = models.ForeignKey(to=MessageStyle, on_delete=models.SET_NULL, null=True, blank=False)
|
||||||
unique_rules = models.ManyToManyField(to=UniqueContentRule, blank=False)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "subscription"
|
verbose_name = "subscription"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user