From 7483cb59192a216ff8951f2d18f361b39d314427 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 31 Mar 2021 13:56:26 -0700 Subject: [PATCH 01/16] Adds getting started find books view --- bookwyrm/static/css/format.css | 4 + bookwyrm/templates/get_started/books.html | 98 +++++++++++++++++++++++ bookwyrm/urls.py | 2 + bookwyrm/views/__init__.py | 1 + bookwyrm/views/get_started.py | 35 ++++++++ 5 files changed, 140 insertions(+) create mode 100644 bookwyrm/templates/get_started/books.html create mode 100644 bookwyrm/views/get_started.py diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 65fd56aba..e3ae1ce79 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -21,6 +21,10 @@ html { overflow-x: auto; } +.modal-card.is-fullwidth { + min-width: 75% !important; +} + /* --- SHELVING --- */ /** @todo Replace icons with SVG symbols. diff --git a/bookwyrm/templates/get_started/books.html b/bookwyrm/templates/get_started/books.html new file mode 100644 index 000000000..7ead07107 --- /dev/null +++ b/bookwyrm/templates/get_started/books.html @@ -0,0 +1,98 @@ +{% extends 'layout.html' %} +{% load i18n %} +{% load bookwyrm_tags %} +{% load humanize %} + +{% block title %}{% trans "Welcome" %}{% endblock %} + +{% block content %} +{% with site_name=site.name %} + +{% endwith %} +{% endblock %} + diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 27fb678fa..6d14beeb1 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -109,6 +109,8 @@ urlpatterns = [ re_path(r"^discover/?$", views.Discover.as_view()), re_path(r"^notifications/?$", views.Notifications.as_view()), re_path(r"^directory/?", views.Directory.as_view(), name="directory"), + # Get started + re_path(r"^get-started/?$", views.GetStarted.as_view(), name="get-started"), # feeds re_path(r"^(?Phome|local|federated)/?$", views.Feed.as_view()), re_path( diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index fead2a32b..9ea5ebebe 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -9,6 +9,7 @@ from .federation import Federation, FederatedServer from .feed import DirectMessage, Feed, Replies, Status from .follow import follow, unfollow from .follow import accept_follow_request, delete_follow_request +from .get_started import GetStarted from .goal import Goal, hide_goal from .import_data import Import, ImportStatus from .inbox import Inbox diff --git a/bookwyrm/views/get_started.py b/bookwyrm/views/get_started.py new file mode 100644 index 000000000..7db458068 --- /dev/null +++ b/bookwyrm/views/get_started.py @@ -0,0 +1,35 @@ +""" Helping new users figure out the lay of the land """ +from django.contrib.auth.decorators import login_required +from django.db.models import Count +from django.template.response import TemplateResponse +from django.utils.decorators import method_decorator +from django.views import View + +from bookwyrm import models +from bookwyrm.connectors import connector_manager + + +# pylint: disable= no-self-use +@method_decorator(login_required, name="dispatch") +class GetStarted(View): + """ a book! this is the stuff """ + + def get(self, request): + """ info about a book """ + query = request.GET.get('query') + book_results = [] + if query: + book_results = connector_manager.local_search(query, raw=True)[:5] + if len(book_results) < 5: + popular_books = models.Edition.objects.exclude( + parent_work__in=[b.parent_work for b in book_results], + ).annotate( + Count("shelfbook") + ).order_by("-shelfbook__count")[: 5 - len(book_results)] + + + data = { + "book_results": book_results, + "popular_books": popular_books, + } + return TemplateResponse(request, "get_started/books.html", data) From 59c54e05917fbe61490bd4fbab13e38501067658 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 31 Mar 2021 13:59:33 -0700 Subject: [PATCH 02/16] Creates get strated layout --- bookwyrm/templates/get_started/books.html | 151 +++++++++------------ bookwyrm/templates/get_started/layout.html | 33 +++++ 2 files changed, 95 insertions(+), 89 deletions(-) create mode 100644 bookwyrm/templates/get_started/layout.html diff --git a/bookwyrm/templates/get_started/books.html b/bookwyrm/templates/get_started/books.html index 7ead07107..cbb208f8e 100644 --- a/bookwyrm/templates/get_started/books.html +++ b/bookwyrm/templates/get_started/books.html @@ -1,98 +1,71 @@ -{% extends 'layout.html' %} +{% extends 'get_started/layout.html' %} {% load i18n %} -{% load bookwyrm_tags %} -{% load humanize %} -{% block title %}{% trans "Welcome" %}{% endblock %} +{% block panel %} +
+

{% trans "What are you reading?" %}

+
+
+ + {% if request.GET.query and not book_results %} +

{% blocktrans %}Sorry, books were found. You can add books when you start using {{ site_name }}{% endblocktrans %}

+ {% endif %} +
+
+ +
+
+
-{% block content %} -{% with site_name=site.name %} - + {% endif %} +
+

+ {% blocktrans %}Popular on {{ site_name }}{% endblocktrans %} +

+
+ {% for book in popular_books %} +
+ {% include 'snippets/book_cover.html' with book=book %} +
+ +
+
+ {% endfor %} +
+
- - -{% endwith %} + + {% endblock %} diff --git a/bookwyrm/templates/get_started/layout.html b/bookwyrm/templates/get_started/layout.html new file mode 100644 index 000000000..eeb01bbe8 --- /dev/null +++ b/bookwyrm/templates/get_started/layout.html @@ -0,0 +1,33 @@ +{% extends 'layout.html' %} +{% load i18n %} + +{% block title %}{% trans "Welcome" %}{% endblock %} + +{% block content %} +{% with site_name=site.name %} + +{% endwith %} +{% endblock %} + + From 13e153412e1afacfbd44fe8ee3911b048c388c19 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 31 Mar 2021 14:53:00 -0700 Subject: [PATCH 03/16] Adds profile and user get started views --- bookwyrm/templates/feed/feed.html | 22 +------ bookwyrm/templates/feed/suggested_users.html | 25 ++++++++ bookwyrm/templates/get_started/books.html | 2 +- bookwyrm/templates/get_started/layout.html | 4 +- bookwyrm/templates/get_started/profile.html | 58 +++++++++++++++++++ bookwyrm/templates/get_started/users.html | 11 ++++ bookwyrm/urls.py | 16 ++++- bookwyrm/views/__init__.py | 2 +- bookwyrm/views/get_started.py | 61 ++++++++++++++++---- 9 files changed, 165 insertions(+), 36 deletions(-) create mode 100644 bookwyrm/templates/feed/suggested_users.html create mode 100644 bookwyrm/templates/get_started/profile.html create mode 100644 bookwyrm/templates/get_started/users.html diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index 3f9d36f76..e49b4c138 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -54,27 +54,7 @@ {# suggested users on the first page, two statuses down #}

{% trans "Who to follow" %}

-
- {% for user in suggested_users %} -
-
- - {% include 'snippets/avatar.html' with user=user large=True %} - {{ user.display_name|truncatechars:10 }} - @{{ user|username|truncatechars:8 }} - - {% include 'snippets/follow_button.html' with user=user minimal=True %} - {% if user.mutuals %} -

- {% blocktrans with mutuals=user.mutuals|intcomma count counter=user.mutuals %}{{ mutuals }} follower you follow{% plural %}{{ mutuals }} followers you follow{% endblocktrans %} -

- {% elif user.shared_books %} -

{% blocktrans with shared_books=user.shared_books|intcomma count counter=user.shared_books %}{{ shared_books }} book on your shelves{% plural %}{{ shared_books }} books on your shelves{% endblocktrans %}

- {% endif %} -
-
- {% endfor %} -
+ {% include 'feed/suggested_users.html' with suggested_users=suggested_users %} View directory
{% endif %} diff --git a/bookwyrm/templates/feed/suggested_users.html b/bookwyrm/templates/feed/suggested_users.html new file mode 100644 index 000000000..f66662e87 --- /dev/null +++ b/bookwyrm/templates/feed/suggested_users.html @@ -0,0 +1,25 @@ +{% load i18n %} +{% load bookwyrm_tags %} +{% load humanize %} +
+ {% for user in suggested_users %} +
+
+ + {% include 'snippets/avatar.html' with user=user large=True %} + {{ user.display_name|truncatechars:10 }} + @{{ user|username|truncatechars:8 }} + + {% include 'snippets/follow_button.html' with user=user minimal=True %} + {% if user.mutuals %} +

+ {% blocktrans with mutuals=user.mutuals|intcomma count counter=user.mutuals %}{{ mutuals }} follower you follow{% plural %}{{ mutuals }} followers you follow{% endblocktrans %} +

+ {% elif user.shared_books %} +

{% blocktrans with shared_books=user.shared_books|intcomma count counter=user.shared_books %}{{ shared_books }} book on your shelves{% plural %}{{ shared_books }} books on your shelves{% endblocktrans %}

+ {% endif %} +
+
+ {% endfor %} +
+ diff --git a/bookwyrm/templates/get_started/books.html b/bookwyrm/templates/get_started/books.html index cbb208f8e..eb10f4edd 100644 --- a/bookwyrm/templates/get_started/books.html +++ b/bookwyrm/templates/get_started/books.html @@ -4,7 +4,7 @@ {% block panel %}

{% trans "What are you reading?" %}

-
+
{% if request.GET.query and not book_results %} diff --git a/bookwyrm/templates/get_started/layout.html b/bookwyrm/templates/get_started/layout.html index eeb01bbe8..b6d373fdf 100644 --- a/bookwyrm/templates/get_started/layout.html +++ b/bookwyrm/templates/get_started/layout.html @@ -19,10 +19,12 @@
diff --git a/bookwyrm/templates/get_started/profile.html b/bookwyrm/templates/get_started/profile.html new file mode 100644 index 000000000..7ee43c082 --- /dev/null +++ b/bookwyrm/templates/get_started/profile.html @@ -0,0 +1,58 @@ +{% extends 'get_started/layout.html' %} +{% load i18n %} + +{% block panel %} +
+

{% trans "A little bit about you" %}

+ {% if form.non_field_errors %} +

{{ form.non_field_errors }}

+ {% endif %} + + {% csrf_token %} +
+
+
+ + + {% for error in form.name.errors %} +

{{ error | escape }}

+ {% endfor %} +
+
+ + + {% for error in form.summary.errors %} +

{{ error | escape }}

+ {% endfor %} +
+
+ +
+
+ + {{ form.avatar }} + {% for error in form.avatar.errors %} +

{{ error | escape }}

+ {% endfor %} +
+
+
+
+ +
+
+ + {% url 'directory' as path %} +

{% trans "Your account will show up in the directory, and may be recommended to other BookWyrm users." %}

+
+
+ +
+{% endblock %} + diff --git a/bookwyrm/templates/get_started/users.html b/bookwyrm/templates/get_started/users.html new file mode 100644 index 000000000..14c04e634 --- /dev/null +++ b/bookwyrm/templates/get_started/users.html @@ -0,0 +1,11 @@ +{% extends 'get_started/layout.html' %} +{% load i18n %} + +{% block panel %} +
+

{% trans "Who to follow" %}

+ + {% include 'feed/suggested_users.html' with suggested_users=suggested_users %} +
+{% endblock %} + diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 6d14beeb1..ef8b32121 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -110,7 +110,21 @@ urlpatterns = [ re_path(r"^notifications/?$", views.Notifications.as_view()), re_path(r"^directory/?", views.Directory.as_view(), name="directory"), # Get started - re_path(r"^get-started/?$", views.GetStarted.as_view(), name="get-started"), + re_path( + r"^get-started/?$", + views.GetStartedProfile.as_view(), + name="get-started-profile", + ), + re_path( + r"^get-started/books/?$", + views.GetStartedBooks.as_view(), + name="get-started-books", + ), + re_path( + r"^get-started/users/?$", + views.GetStartedUsers.as_view(), + name="get-started-users", + ), # feeds re_path(r"^(?Phome|local|federated)/?$", views.Feed.as_view()), re_path( diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 9ea5ebebe..22e6071c7 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -9,7 +9,7 @@ from .federation import Federation, FederatedServer from .feed import DirectMessage, Feed, Replies, Status from .follow import follow, unfollow from .follow import accept_follow_request, delete_follow_request -from .get_started import GetStarted +from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers from .goal import Goal, hide_goal from .import_data import Import, ImportStatus from .inbox import Inbox diff --git a/bookwyrm/views/get_started.py b/bookwyrm/views/get_started.py index 7db458068..f133e3358 100644 --- a/bookwyrm/views/get_started.py +++ b/bookwyrm/views/get_started.py @@ -1,35 +1,74 @@ """ Helping new users figure out the lay of the land """ from django.contrib.auth.decorators import login_required -from django.db.models import Count +from django.db.models import Count, Q from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View -from bookwyrm import models +from bookwyrm import forms, models from bookwyrm.connectors import connector_manager +from .helpers import get_suggested_users # pylint: disable= no-self-use @method_decorator(login_required, name="dispatch") -class GetStarted(View): - """ a book! this is the stuff """ +class GetStartedProfile(View): + """ tell us about yourself """ + + def get(self, request): + """ basic profile info """ + data = { + "form": forms.EditUserForm(instance=request.user), + "next": "get-started-books", + } + return TemplateResponse(request, "get_started/profile.html", data) + + +@method_decorator(login_required, name="dispatch") +class GetStartedBooks(View): + """ name a book, any book, we gotta start somewhere """ def get(self, request): """ info about a book """ - query = request.GET.get('query') + query = request.GET.get("query") book_results = [] if query: book_results = connector_manager.local_search(query, raw=True)[:5] if len(book_results) < 5: - popular_books = models.Edition.objects.exclude( - parent_work__in=[b.parent_work for b in book_results], - ).annotate( - Count("shelfbook") - ).order_by("-shelfbook__count")[: 5 - len(book_results)] - + popular_books = ( + models.Edition.objects.exclude( + parent_work__in=[b.parent_work for b in book_results], + ) + .annotate(Count("shelfbook")) + .order_by("-shelfbook__count")[: 5 - len(book_results)] + ) data = { "book_results": book_results, "popular_books": popular_books, + "next": "get-started-users", } return TemplateResponse(request, "get_started/books.html", data) + + +@method_decorator(login_required, name="dispatch") +class GetStartedUsers(View): + """ find friends """ + + def get(self, request): + """ basic profile info """ + suggested_users = ( + get_suggested_users( + request.user, + ~Q(id=request.user.id), + ~Q(followers=request.user), + bookwyrm_user=True, + ) + .order_by("shared_books", "-mutuals", "-last_active_date") + .all()[:5] + ) + data = { + "suggested_users": suggested_users, + "next": "get-started-profile", + } + return TemplateResponse(request, "get_started/users.html", data) From 47204812193eb8e3efd891afb67dac419f03090e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 1 Apr 2021 08:02:42 -0700 Subject: [PATCH 04/16] Fixes accessibility bugs --- bookwyrm/templates/get_started/books.html | 28 ++++------------------ bookwyrm/templates/get_started/layout.html | 4 ++-- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/bookwyrm/templates/get_started/books.html b/bookwyrm/templates/get_started/books.html index eb10f4edd..110bced27 100644 --- a/bookwyrm/templates/get_started/books.html +++ b/bookwyrm/templates/get_started/books.html @@ -6,7 +6,7 @@

{% trans "What are you reading?" %}

- + {% if request.GET.query and not book_results %}

{% blocktrans %}Sorry, books were found. You can add books when you start using {{ site_name }}{% endblocktrans %}

{% endif %} @@ -21,7 +21,7 @@
-
+

{% trans "Suggested Books" %}

{% if book_results %} @@ -29,17 +29,7 @@

Search results

{% for book in book_results %} -
- {% include 'snippets/book_cover.html' with book=book %} -
- -
-
+ {% include 'get_started/book_preview.html' %} {% endfor %}
@@ -50,17 +40,7 @@

{% for book in popular_books %} -
- {% include 'snippets/book_cover.html' with book=book %} -
- -
-
+ {% include 'get_started/book_preview.html' %} {% endfor %}
diff --git a/bookwyrm/templates/get_started/layout.html b/bookwyrm/templates/get_started/layout.html index b6d373fdf..18da2fb36 100644 --- a/bookwyrm/templates/get_started/layout.html +++ b/bookwyrm/templates/get_started/layout.html @@ -5,11 +5,11 @@ {% block content %} {% with site_name=site.name %} - - + {% endblock %} diff --git a/bookwyrm/templates/get_started/layout.html b/bookwyrm/templates/get_started/layout.html index 18da2fb36..17fc5a9b0 100644 --- a/bookwyrm/templates/get_started/layout.html +++ b/bookwyrm/templates/get_started/layout.html @@ -12,7 +12,7 @@

{% trans "Getting Started" %}

- + -