Adds published date separate from created date

This commit is contained in:
Mouse Reeve 2020-03-06 16:35:56 -08:00
parent 984c04a374
commit e45b04f22e
7 changed files with 29 additions and 7 deletions

View file

@ -34,7 +34,7 @@ def get_status(status):
'id': uri, 'id': uri,
'url': uri, 'url': uri,
'inReplyTo': reply_parent_id, 'inReplyTo': reply_parent_id,
'published': status.created_date.isoformat(), 'published': status.published_date.isoformat(),
'attributedTo': user.actor, 'attributedTo': user.actor,
# TODO: assuming all posts are public -- should check privacy db field # TODO: assuming all posts are public -- should check privacy db field
'to': ['https://www.w3.org/ns/activitystreams#Public'], 'to': ['https://www.w3.org/ns/activitystreams#Public'],

View file

@ -260,12 +260,13 @@ def handle_incoming_create(activity):
book = book.split('/')[-1] book = book.split('/')[-1]
name = activity['object'].get('name') name = activity['object'].get('name')
rating = activity['object'].get('rating') rating = activity['object'].get('rating')
published = activity['object'].get('published')
if user.local: if user.local:
review_id = activity['object']['id'].split('/')[-1] review_id = activity['object']['id'].split('/')[-1]
models.Review.objects.get(id=review_id) models.Review.objects.get(id=review_id)
else: else:
try: try:
create_review(user, book, name, content, rating) create_review(user, book, name, content, rating, published)
except ValueError: except ValueError:
return HttpResponseBadRequest() return HttpResponseBadRequest()
elif not user.local: elif not user.local:

View file

@ -0,0 +1,19 @@
# Generated by Django 3.0.3 on 2020-03-07 00:28
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fedireads', '0008_auto_20200224_1504'),
]
operations = [
migrations.AddField(
model_name='status',
name='published_date',
field=models.DateTimeField(default=datetime.datetime.now),
),
]

View file

@ -1,4 +1,5 @@
''' models for storing different kinds of Activities ''' ''' models for storing different kinds of Activities '''
from datetime import datetime
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.dispatch import receiver from django.dispatch import receiver
@ -7,8 +8,6 @@ import re
from fedireads.utils.models import FedireadsModel from fedireads.utils.models import FedireadsModel
# TODO: quote, comment, poll, recommendation, content warning, image
class Status(FedireadsModel): class Status(FedireadsModel):
''' any post, like a reply to a review, etc ''' ''' any post, like a reply to a review, etc '''
@ -21,6 +20,8 @@ class Status(FedireadsModel):
local = models.BooleanField(default=True) local = models.BooleanField(default=True)
privacy = models.CharField(max_length=255, default='public') privacy = models.CharField(max_length=255, default='public')
sensitive = models.BooleanField(default=False) sensitive = models.BooleanField(default=False)
# the created date can't double as this, because of receiving federated posts
published_date = models.DateTimeField(default=datetime.now)
favorites = models.ManyToManyField( favorites = models.ManyToManyField(
'User', 'User',
symmetrical=False, symmetrical=False,

View file

@ -5,7 +5,7 @@ from fedireads.sanitize_html import InputHtmlParser
from django.db import IntegrityError from django.db import IntegrityError
def create_review(user, possible_book, name, content, rating): def create_review(user, possible_book, name, content, rating, published):
''' a book review has been added ''' ''' a book review has been added '''
# throws a value error if the book is not found # throws a value error if the book is not found
book = get_or_create_book(possible_book) book = get_or_create_book(possible_book)
@ -21,6 +21,7 @@ def create_review(user, possible_book, name, content, rating):
name=name, name=name,
rating=rating, rating=rating,
content=content, content=content,
published_date=published,
) )

View file

@ -4,7 +4,7 @@
{% include 'snippets/username.html' with user=activity.user %} {% include 'snippets/username.html' with user=activity.user %}
{{ content | safe }} {{ content | safe }}
<span class="time-ago"> <span class="time-ago">
{{ activity.created_date | naturaltime }} {{ activity.published_date | naturaltime }}
</span> </span>
</h2> </h2>

View file

@ -2,7 +2,7 @@ from django.db import models
from fedireads.settings import DOMAIN from fedireads.settings import DOMAIN
# TODO maybe this should be in /models?
class FedireadsModel(models.Model): class FedireadsModel(models.Model):
created_date = models.DateTimeField(auto_now_add=True) created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True) updated_date = models.DateTimeField(auto_now=True)