Move timelines to published date all around
This commit is contained in:
parent
35102fbdd4
commit
90c7b615fd
|
@ -137,7 +137,7 @@ class PostAdmin(admin.ModelAdmin):
|
|||
|
||||
@admin.register(TimelineEvent)
|
||||
class TimelineEventAdmin(admin.ModelAdmin):
|
||||
list_display = ["id", "identity", "created", "type"]
|
||||
list_display = ["id", "identity", "published", "type"]
|
||||
list_filter = (IdentityLocalFilter, "type")
|
||||
readonly_fields = ["created"]
|
||||
raw_id_fields = [
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
# Generated by Django 4.1.4 on 2022-12-16 02:52
|
||||
import datetime
|
||||
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
import activities.models.post_types
|
||||
|
||||
def timeline_event_populate(apps, schema_editor):
|
||||
|
||||
def timelineevent_populate_published(apps, schema_editor):
|
||||
"""
|
||||
Populates all timeline events with a published date before 2001
|
||||
with their created date instead
|
||||
Populates all timeline events' published date with their created date
|
||||
"""
|
||||
TimelineEvent = apps.get_model("activities", "timelineevent")
|
||||
TimelineEvent.objects.filter(
|
||||
published__lt=datetime.datetime(2001, 1, 1, tzinfo=datetime.timezone.utc)
|
||||
).update(published=models.F("created"))
|
||||
TimelineEvent.objects.update(published=models.F("created"))
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -48,12 +46,7 @@ class Migration(migrations.Migration):
|
|||
migrations.AddField(
|
||||
model_name="timelineevent",
|
||||
name="published",
|
||||
field=models.DateTimeField(
|
||||
default=datetime.datetime(
|
||||
2000, 1, 1, 0, 0, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
),
|
||||
preserve_default=False,
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="timelineevent",
|
||||
|
@ -71,6 +64,8 @@ class Migration(migrations.Migration):
|
|||
field=models.JSONField(
|
||||
blank=True,
|
||||
null=True,
|
||||
decoder=activities.models.post_types.PostTypeDataDecoder,
|
||||
encoder=activities.models.post_types.PostTypeDataEncoder,
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
|
@ -79,7 +74,7 @@ class Migration(migrations.Migration):
|
|||
field=models.CharField(blank=True, max_length=2048, null=True),
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=timeline_event_populate,
|
||||
code=timelineevent_populate_published,
|
||||
reverse_code=lambda a, s: None,
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from core.ld import format_ld_date
|
||||
|
||||
|
@ -51,7 +52,7 @@ class TimelineEvent(models.Model):
|
|||
related_name="timeline_events_about_us",
|
||||
)
|
||||
|
||||
published = models.DateTimeField()
|
||||
published = models.DateTimeField(default=timezone.now)
|
||||
seen = models.BooleanField(default=False)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -85,6 +86,7 @@ class TimelineEvent(models.Model):
|
|||
identity=identity,
|
||||
type=cls.Types.post,
|
||||
subject_post=post,
|
||||
defaults={"published": post.published or post.created},
|
||||
)[0]
|
||||
|
||||
@classmethod
|
||||
|
@ -97,6 +99,7 @@ class TimelineEvent(models.Model):
|
|||
type=cls.Types.mentioned,
|
||||
subject_post=post,
|
||||
subject_identity=post.author,
|
||||
defaults={"published": post.published or post.created},
|
||||
)[0]
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.defaultfilters import linebreaks_filter
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import FormView, ListView
|
||||
from django.views.generic import ListView, TemplateView
|
||||
|
||||
from activities.models import Hashtag, Post, PostInteraction, TimelineEvent
|
||||
from core.decorators import cache_page
|
||||
|
@ -13,7 +12,7 @@ from .compose import Compose
|
|||
|
||||
|
||||
@method_decorator(identity_required, name="dispatch")
|
||||
class Home(FormView):
|
||||
class Home(TemplateView):
|
||||
|
||||
template_name = "activities/home.html"
|
||||
|
||||
|
@ -23,7 +22,6 @@ class Home(FormView):
|
|||
return self.form_class(request=self.request, **self.get_form_kwargs())
|
||||
|
||||
def get_context_data(self):
|
||||
context = super().get_context_data()
|
||||
events = (
|
||||
TimelineEvent.objects.filter(
|
||||
identity=self.request.identity,
|
||||
|
@ -31,27 +29,22 @@ class Home(FormView):
|
|||
)
|
||||
.select_related("subject_post", "subject_post__author")
|
||||
.prefetch_related("subject_post__attachments", "subject_post__mentions")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
context["interactions"] = PostInteraction.get_event_interactions(
|
||||
events, self.request.identity
|
||||
)
|
||||
context["current_page"] = "home"
|
||||
context["allows_refresh"] = True
|
||||
paginator = Paginator(events, 50)
|
||||
page_number = self.request.GET.get("page")
|
||||
context["page_obj"] = paginator.get_page(page_number)
|
||||
context = {
|
||||
"interactions": PostInteraction.get_event_interactions(
|
||||
events,
|
||||
self.request.identity,
|
||||
),
|
||||
"current_page": "home",
|
||||
"allows_refresh": True,
|
||||
"page_obj": paginator.get_page(page_number),
|
||||
"form": self.form_class(request=self.request),
|
||||
}
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
Post.create_local(
|
||||
author=self.request.identity,
|
||||
content=linebreaks_filter(form.cleaned_data["text"]),
|
||||
summary=form.cleaned_data.get("content_warning"),
|
||||
visibility=self.request.identity.config_identity.default_post_visibility,
|
||||
)
|
||||
return redirect(".")
|
||||
|
||||
|
||||
@method_decorator(
|
||||
cache_page("cache_timeout_page_timeline", public_only=True), name="dispatch"
|
||||
|
@ -80,7 +73,7 @@ class Tag(ListView):
|
|||
.tagged_with(self.hashtag)
|
||||
.select_related("author")
|
||||
.prefetch_related("attachments", "mentions")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
|
||||
def get_context_data(self):
|
||||
|
@ -110,7 +103,7 @@ class Local(ListView):
|
|||
.filter(author__restriction=Identity.Restriction.none)
|
||||
.select_related("author", "author__domain")
|
||||
.prefetch_related("attachments", "mentions", "emojis")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
|
||||
def get_context_data(self):
|
||||
|
@ -139,7 +132,7 @@ class Federated(ListView):
|
|||
.filter(author__restriction=Identity.Restriction.none)
|
||||
.select_related("author", "author__domain")
|
||||
.prefetch_related("attachments", "mentions", "emojis")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
|
||||
def get_context_data(self):
|
||||
|
@ -183,7 +176,7 @@ class Notifications(ListView):
|
|||
types.append(type)
|
||||
return (
|
||||
TimelineEvent.objects.filter(identity=self.request.identity, type__in=types)
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
.select_related(
|
||||
"subject_post",
|
||||
"subject_post__author",
|
||||
|
|
|
@ -33,7 +33,7 @@ def notifications(
|
|||
identity=request.identity,
|
||||
type__in=[base_types[r] for r in requested_types],
|
||||
)
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
.select_related("subject_post", "subject_post__author", "subject_identity")
|
||||
)
|
||||
paginator = MastodonPaginator(TimelineEvent)
|
||||
|
|
|
@ -23,7 +23,7 @@ def home(
|
|||
)
|
||||
.select_related("subject_post", "subject_post__author")
|
||||
.prefetch_related("subject_post__attachments")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
events = paginator.paginate(
|
||||
queryset,
|
||||
|
@ -56,7 +56,7 @@ def public(
|
|||
.filter(author__restriction=Identity.Restriction.none)
|
||||
.select_related("author")
|
||||
.prefetch_related("attachments")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
if local:
|
||||
queryset = queryset.filter(local=True)
|
||||
|
@ -96,7 +96,7 @@ def hashtag(
|
|||
.tagged_with(hashtag)
|
||||
.select_related("author")
|
||||
.prefetch_related("attachments")
|
||||
.order_by("-created")
|
||||
.order_by("-published")
|
||||
)
|
||||
if local:
|
||||
queryset = queryset.filter(local=True)
|
||||
|
|
Loading…
Reference in New Issue