diff --git a/fedireads/migrations/0001_initial.py b/fedireads/migrations/0001_initial.py index 62e7d9248..13fbe6356 100644 --- a/fedireads/migrations/0001_initial.py +++ b/fedireads/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.2 on 2020-01-28 19:39 +# Generated by Django 3.0.2 on 2020-01-28 23:19 from django.conf import settings import django.contrib.auth.models diff --git a/fedireads/models.py b/fedireads/models.py index 1b89cff44..e77707e7e 100644 --- a/fedireads/models.py +++ b/fedireads/models.py @@ -1,5 +1,6 @@ ''' database schema for the whole dang thing ''' from django.db import models +from model_utils.managers import InheritanceManager from django.dispatch import receiver from django.contrib.auth.models import AbstractUser from django.contrib.postgres.fields import JSONField @@ -99,6 +100,7 @@ class Activity(models.Model): fedireads_type = models.CharField(max_length=255, blank=True, null=True) created_date = models.DateTimeField(auto_now_add=True) updated_date = models.DateTimeField(auto_now=True) + objects = InheritanceManager() class ShelveActivity(Activity): @@ -107,9 +109,8 @@ class ShelveActivity(Activity): shelf = models.ForeignKey('Shelf', on_delete=models.PROTECT) def save(self, *args, **kwargs): - if not self.activity_type: - self.activity_type = 'Add' - shelf.fedireads_type = 'Shelve' + self.activity_type = 'Add' + self.fedireads_type = 'Shelve' super().save(*args, **kwargs) @@ -122,8 +123,7 @@ class FollowActivity(Activity): ) def save(self, *args, **kwargs): - if not self.activity_type: - self.activity_type = 'Follow' + self.activity_type = 'Follow' super().save(*args, **kwargs) @@ -137,17 +137,15 @@ class Review(Activity): review_content = models.TextField() def save(self, *args, **kwargs): - if not self.activity_type: - self.activity_type = 'Article' - self.fedireads_type = 'Review' + self.activity_type = 'Article' + self.fedireads_type = 'Review' super().save(*args, **kwargs) class Note(Activity): ''' reply to a review, etc ''' def save(self, *args, **kwargs): - if not self.activity_type: - self.activity_type = 'Note' + self.activity_type = 'Note' super().save(*args, **kwargs) diff --git a/fedireads/outgoing.py b/fedireads/outgoing.py index 04458c98a..99c775404 100644 --- a/fedireads/outgoing.py +++ b/fedireads/outgoing.py @@ -101,7 +101,6 @@ def handle_shelve(user, book, shelf): uuid=uuid, user=user, content=activity, - activity_type='Add', shelf=shelf, book=book, ).save() diff --git a/fedireads/templates/feed.html b/fedireads/templates/feed.html index 55460b8a4..621ddcf54 100644 --- a/fedireads/templates/feed.html +++ b/fedireads/templates/feed.html @@ -1,34 +1,43 @@ {% extends 'layout.html' %} {% block content %}
+
+ {# a display of books in your local db, so you have somewhere to start #} {% for book in recent_books %}

{{ book.data.title }} + by + {# TODO: there should be a helper function for listing authors #} + {{ book.authors.first.data.name }}

-

by {{ book.authors.first.data.name }}

{% if not book.user_shelves %}
- +
{% endif %}
@@ -38,9 +47,50 @@
+ {# TODO: a helper function for displaying a username #} {% if activity.user.localname %}{{ activity.user.localname }}{% else %}{{ activity.user.username }}{% endif %} - did {{ activity.activity_type }} + {% if activity.fedireads_type == 'Shelve' %} + {# display a reading/shelving activity #} + {% if activity.shelf.shelf_type == 'to-read' %} + wants to read + {% elif activity.shelf.shelf_type == 'read' %} + finished reading + {% elif activity.shelf.shelf_type == 'reading' %} + started reading + {% else %} + shelved in "{{ activity.shelf.name }}" + {% endif %} + {# TODO: wouldn't it rule if this was a reusable piece of markup? #} + + {% elif activity.fedireads_type == 'Review' %} + {# display a review #} + reviewed {{ activity.book.data.title }} +
+ +

+ {{ activity.book.data.title }} + by + {{ activity.book.authors.first.data.name }} +

+ +

{{ activity.name }}

+

{{ activity.rating }} stars

+

{{ activity.review_content }}

+
+ {% elif activity.activity_type == 'Follow' %} + started following someone + {% else %} + {# generic handling for a misc activity, which perhaps should not be displayed at all #} + did {{ activity.activity_type }} + {% endif %}
{% endfor %} diff --git a/fedireads/views.py b/fedireads/views.py index a9ccb4aa5..d60b67a8f 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -32,8 +32,10 @@ def home(request): # TODO: handle post privacy activities = models.Activity.objects.filter( - user__in=following - ).order_by('-created_date')[:10] + user__in=following, + ).select_subclasses().order_by( + '-created_date' + )[:10] data = { 'user': request.user, @@ -135,6 +137,7 @@ def book_page(request, book_identifier): @login_required def shelve(request, shelf_id, book_id): ''' put a book on a user's shelf ''' + # TODO: handle "reshelving" book = models.Book.objects.get(id=book_id) shelf = models.Shelf.objects.get(identifier=shelf_id) api.handle_shelve(request.user, book, shelf) diff --git a/requirements.txt b/requirements.txt index 780229e30..0ab2527ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Django==3.0.2 +django-model-utils==4.0.0 Pillow==7.0.0 psycopg2==2.8.4 pycryptodome==3.9.4