summaryrefslogtreecommitdiffstats
path: root/activities
diff options
context:
space:
mode:
Diffstat (limited to 'activities')
-rw-r--r--activities/models/post.py8
-rw-r--r--activities/templatetags/__init__.py0
-rw-r--r--activities/templatetags/activity_tags.py33
-rw-r--r--activities/views/home.py42
-rw-r--r--activities/views/timelines.py70
5 files changed, 109 insertions, 44 deletions
diff --git a/activities/models/post.py b/activities/models/post.py
index ec5e629..75a4388 100644
--- a/activities/models/post.py
+++ b/activities/models/post.py
@@ -1,4 +1,4 @@
-from typing import Dict
+from typing import Dict, Optional
import urlman
from django.db import models
@@ -126,10 +126,14 @@ class Post(StatorModel):
### Local creation ###
@classmethod
- def create_local(cls, author: Identity, content: str) -> "Post":
+ def create_local(
+ cls, author: Identity, content: str, summary: Optional[str] = None
+ ) -> "Post":
post = cls.objects.create(
author=author,
content=content,
+ summary=summary or None,
+ sensitive=bool(summary),
local=True,
)
post.object_uri = post.author.actor_uri + f"posts/{post.id}/"
diff --git a/activities/templatetags/__init__.py b/activities/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/activities/templatetags/__init__.py
diff --git a/activities/templatetags/activity_tags.py b/activities/templatetags/activity_tags.py
new file mode 100644
index 0000000..cbbae57
--- /dev/null
+++ b/activities/templatetags/activity_tags.py
@@ -0,0 +1,33 @@
+import datetime
+
+from django import template
+from django.utils import timezone
+
+register = template.Library()
+
+
+@register.filter
+def timedeltashort(value: datetime.datetime):
+ """
+ A more compact version of timesince
+ """
+ if not value:
+ return ""
+ # TODO: Handle things in the future properly
+ delta = timezone.now() - value
+ seconds = int(delta.total_seconds())
+ days = delta.days
+ if seconds < 60:
+ text = f"{seconds:0n}s"
+ elif seconds < 60 * 60:
+ minutes = seconds // 60
+ text = f"{minutes:0n}m"
+ elif seconds < 60 * 60 * 24:
+ hours = seconds // (60 * 60)
+ text = f"{hours:0n}h"
+ elif days < 365:
+ text = f"{days:0n}h"
+ else:
+ years = days // 365.25
+ text = f"{years:0n}y"
+ return text
diff --git a/activities/views/home.py b/activities/views/home.py
deleted file mode 100644
index 867856d..0000000
--- a/activities/views/home.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from django import forms
-from django.shortcuts import redirect
-from django.template.defaultfilters import linebreaks_filter
-from django.utils.decorators import method_decorator
-from django.views.generic import FormView
-
-from activities.models import Post, TimelineEvent
-from core.forms import FormHelper
-from users.decorators import identity_required
-
-
-@method_decorator(identity_required, name="dispatch")
-class Home(FormView):
-
- template_name = "activities/home.html"
-
- class form_class(forms.Form):
- text = forms.CharField()
-
- helper = FormHelper(submit_text="Post")
-
- def get_context_data(self):
- context = super().get_context_data()
- context.update(
- {
- "timeline_posts": [
- te.subject_post
- for te in TimelineEvent.objects.filter(
- identity=self.request.identity,
- type=TimelineEvent.Types.post,
- ).order_by("-created")[:100]
- ],
- }
- )
- return context
-
- def form_valid(self, form):
- Post.create_local(
- author=self.request.identity,
- content=linebreaks_filter(form.cleaned_data["text"]),
- )
- return redirect(".")
diff --git a/activities/views/timelines.py b/activities/views/timelines.py
new file mode 100644
index 0000000..76cf018
--- /dev/null
+++ b/activities/views/timelines.py
@@ -0,0 +1,70 @@
+from django import forms
+from django.shortcuts import redirect
+from django.template.defaultfilters import linebreaks_filter
+from django.utils.decorators import method_decorator
+from django.views.generic import FormView, TemplateView
+
+from activities.models import Post, TimelineEvent
+from users.decorators import identity_required
+
+
+@method_decorator(identity_required, name="dispatch")
+class Home(FormView):
+
+ template_name = "activities/home.html"
+
+ class form_class(forms.Form):
+ text = forms.CharField(
+ widget=forms.Textarea(
+ attrs={
+ "placeholder": "What's on your mind?",
+ },
+ )
+ )
+ content_warning = forms.CharField(
+ required=False,
+ widget=forms.TextInput(
+ attrs={
+ "placeholder": "Content Warning",
+ "class": "hidden",
+ },
+ ),
+ )
+
+ def get_context_data(self):
+ context = super().get_context_data()
+ context["timeline_posts"] = [
+ te.subject_post
+ for te in TimelineEvent.objects.filter(
+ identity=self.request.identity,
+ type=TimelineEvent.Types.post,
+ )
+ .select_related("subject_post", "subject_post__author")
+ .order_by("-created")[:100]
+ ]
+ context["current_page"] = "home"
+ 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"),
+ )
+ return redirect(".")
+
+
+@method_decorator(identity_required, name="dispatch")
+class Federated(TemplateView):
+
+ template_name = "activities/federated.html"
+
+ def get_context_data(self):
+ context = super().get_context_data()
+ context["timeline_posts"] = (
+ Post.objects.filter(visibility=Post.Visibilities.public)
+ .select_related("author")
+ .order_by("-created")[:100]
+ )
+ context["current_page"] = "federated"
+ return context