mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 13:01:08 +00:00
activity feed
This commit is contained in:
parent
cb9cb7f42d
commit
b554280481
6 changed files with 69 additions and 18 deletions
|
@ -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
|
from django.conf import settings
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
''' database schema for the whole dang thing '''
|
''' database schema for the whole dang thing '''
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from model_utils.managers import InheritanceManager
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from django.contrib.postgres.fields import JSONField
|
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)
|
fedireads_type = models.CharField(max_length=255, blank=True, null=True)
|
||||||
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)
|
||||||
|
objects = InheritanceManager()
|
||||||
|
|
||||||
|
|
||||||
class ShelveActivity(Activity):
|
class ShelveActivity(Activity):
|
||||||
|
@ -107,9 +109,8 @@ class ShelveActivity(Activity):
|
||||||
shelf = models.ForeignKey('Shelf', on_delete=models.PROTECT)
|
shelf = models.ForeignKey('Shelf', on_delete=models.PROTECT)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.activity_type:
|
|
||||||
self.activity_type = 'Add'
|
self.activity_type = 'Add'
|
||||||
shelf.fedireads_type = 'Shelve'
|
self.fedireads_type = 'Shelve'
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,7 +123,6 @@ class FollowActivity(Activity):
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.activity_type:
|
|
||||||
self.activity_type = 'Follow'
|
self.activity_type = 'Follow'
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -137,7 +137,6 @@ class Review(Activity):
|
||||||
review_content = models.TextField()
|
review_content = models.TextField()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.activity_type:
|
|
||||||
self.activity_type = 'Article'
|
self.activity_type = 'Article'
|
||||||
self.fedireads_type = 'Review'
|
self.fedireads_type = 'Review'
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
@ -146,7 +145,6 @@ class Review(Activity):
|
||||||
class Note(Activity):
|
class Note(Activity):
|
||||||
''' reply to a review, etc '''
|
''' reply to a review, etc '''
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.activity_type:
|
|
||||||
self.activity_type = 'Note'
|
self.activity_type = 'Note'
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,6 @@ def handle_shelve(user, book, shelf):
|
||||||
uuid=uuid,
|
uuid=uuid,
|
||||||
user=user,
|
user=user,
|
||||||
content=activity,
|
content=activity,
|
||||||
activity_type='Add',
|
|
||||||
shelf=shelf,
|
shelf=shelf,
|
||||||
book=book,
|
book=book,
|
||||||
).save()
|
).save()
|
||||||
|
|
|
@ -1,34 +1,43 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
|
{# listing books currently on user's shelves #}
|
||||||
|
{# TODO: this should only show currently reading probably #}
|
||||||
{% for shelf in shelves %}
|
{% for shelf in shelves %}
|
||||||
<h1>{{ shelf.name }}</h1>
|
{% if shelf.books.all %}
|
||||||
|
<h2>{{ shelf.name }}</h2>
|
||||||
{% for book in shelf.books.all %}
|
{% for book in shelf.books.all %}
|
||||||
<div class="book-preview">
|
<div class="book-preview">
|
||||||
<img class="cover" src="static/images/small.jpg">
|
<img class="cover" src="static/images/small.jpg">
|
||||||
<p class="title"><a href="{{ book.openlibrary_key }}">{{ book.data.title }}</a></p>
|
<p class="title"><a href="{{ book.openlibrary_key }}">{{ book.data.title }}</a></p>
|
||||||
<p>by <a href="" class="author">{{ book.authors.first.data.name }}</a></p>
|
<p>by <a href="" class="author">{{ book.authors.first.data.name }}</a></p>
|
||||||
{% if shelf.type == 'reading' %}
|
{% if shelf.type == 'reading' %}
|
||||||
|
{# TODO: re-shelve a book #}
|
||||||
<button>done reading</button>
|
<button>done reading</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
|
||||||
<div class="carosel">
|
<div class="carosel">
|
||||||
|
{# a display of books in your local db, so you have somewhere to start #}
|
||||||
{% for book in recent_books %}
|
{% for book in recent_books %}
|
||||||
<div class="book-preview">
|
<div class="book-preview">
|
||||||
<img class="cover" src="static/images/small.jpg">
|
<img class="cover" src="static/images/small.jpg">
|
||||||
<p class="title">
|
<p class="title">
|
||||||
<a href="{{ book.openlibrary_key }}">{{ book.data.title }}</a>
|
<a href="{{ book.openlibrary_key }}">{{ book.data.title }}</a>
|
||||||
|
by
|
||||||
|
{# TODO: there should be a helper function for listing authors #}
|
||||||
|
<a href="" class="author">{{ book.authors.first.data.name }}</a>
|
||||||
</p>
|
</p>
|
||||||
<p>by <a href="" class="author">{{ book.authors.first.data.name }}</a></p>
|
|
||||||
{% if not book.user_shelves %}
|
{% if not book.user_shelves %}
|
||||||
<form name="shelve" action="/shelve/{{ request.user.localname }}_to-read/{{ book.id }}" method="post">
|
<form name="shelve" action="/shelve/{{ request.user.localname }}_to-read/{{ book.id }}" method="post">
|
||||||
<input type="hidden" name="book" value="book.id"></input>
|
<input type="hidden" name="book" value="book.id"></input>
|
||||||
<input type="submit" value="want to read"></input>
|
<button type="submit">Want to read</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,9 +47,50 @@
|
||||||
<div class="update">
|
<div class="update">
|
||||||
<div class="user-preview">
|
<div class="user-preview">
|
||||||
<img class="user-pic" src="static/images/profile.jpg">
|
<img class="user-pic" src="static/images/profile.jpg">
|
||||||
|
{# TODO: a helper function for displaying a username #}
|
||||||
<span><a href="/user/{% if activity.user.localname %}{{ activity.user.localname }}{% else %}{{ activity.user.username }}{% endif %}" class="user">
|
<span><a href="/user/{% if activity.user.localname %}{{ activity.user.localname }}{% else %}{{ activity.user.username }}{% endif %}" class="user">
|
||||||
{% if activity.user.localname %}{{ activity.user.localname }}{% else %}{{ activity.user.username }}{% endif %}</a>
|
{% if activity.user.localname %}{{ activity.user.localname }}{% else %}{{ activity.user.username }}{% endif %}</a>
|
||||||
|
{% 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? #}
|
||||||
|
<div class="book-preview">
|
||||||
|
<img class="cover" src="static/images/med.jpg">
|
||||||
|
<p class="title">
|
||||||
|
<a href="{{ activity.book.openlibrary_key }}">{{ activity.book.data.title }}</a>
|
||||||
|
by
|
||||||
|
<a href="" class="author">{{ activity.book.authors.first.data.name }}</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{% elif activity.fedireads_type == 'Review' %}
|
||||||
|
{# display a review #}
|
||||||
|
reviewed {{ activity.book.data.title }}
|
||||||
|
<div class="book-preview review">
|
||||||
|
<img class="cover" src="static/images/med.jpg">
|
||||||
|
<p class="title">
|
||||||
|
<a href="{{ activity.book.openlibrary_key }}">{{ activity.book.data.title }}</a>
|
||||||
|
by
|
||||||
|
<a href="" class="author">{{ activity.book.authors.first.data.name }}</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>{{ activity.name }}</h3>
|
||||||
|
<p>{{ activity.rating }} stars</p>
|
||||||
|
<p>{{ activity.review_content }}</p>
|
||||||
|
</div>
|
||||||
|
{% 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 }}</span>
|
did {{ activity.activity_type }}</span>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -32,8 +32,10 @@ def home(request):
|
||||||
|
|
||||||
# TODO: handle post privacy
|
# TODO: handle post privacy
|
||||||
activities = models.Activity.objects.filter(
|
activities = models.Activity.objects.filter(
|
||||||
user__in=following
|
user__in=following,
|
||||||
).order_by('-created_date')[:10]
|
).select_subclasses().order_by(
|
||||||
|
'-created_date'
|
||||||
|
)[:10]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'user': request.user,
|
'user': request.user,
|
||||||
|
@ -135,6 +137,7 @@ def book_page(request, book_identifier):
|
||||||
@login_required
|
@login_required
|
||||||
def shelve(request, shelf_id, book_id):
|
def shelve(request, shelf_id, book_id):
|
||||||
''' put a book on a user's shelf '''
|
''' put a book on a user's shelf '''
|
||||||
|
# TODO: handle "reshelving"
|
||||||
book = models.Book.objects.get(id=book_id)
|
book = models.Book.objects.get(id=book_id)
|
||||||
shelf = models.Shelf.objects.get(identifier=shelf_id)
|
shelf = models.Shelf.objects.get(identifier=shelf_id)
|
||||||
api.handle_shelve(request.user, book, shelf)
|
api.handle_shelve(request.user, book, shelf)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Django==3.0.2
|
Django==3.0.2
|
||||||
|
django-model-utils==4.0.0
|
||||||
Pillow==7.0.0
|
Pillow==7.0.0
|
||||||
psycopg2==2.8.4
|
psycopg2==2.8.4
|
||||||
pycryptodome==3.9.4
|
pycryptodome==3.9.4
|
||||||
|
|
Loading…
Reference in a new issue