Adds profile and user get started views

This commit is contained in:
Mouse Reeve 2021-03-31 14:53:00 -07:00
parent 59c54e0591
commit 13e153412e
9 changed files with 165 additions and 36 deletions

View file

@ -54,27 +54,7 @@
{# suggested users on the first page, two statuses down #}
<section class="block">
<h2 class="title is-5">{% trans "Who to follow" %}</h2>
<div class="columns is-mobile scroll-x mb-0">
{% for user in suggested_users %}
<div class="column is-flex">
<div class="box has-text-centered is-shadowless has-background-white-bis m-0">
<a href="{{ user.local_path }}" class="has-text-black">
{% include 'snippets/avatar.html' with user=user large=True %}
<span title="{{ user.display_name }}" class="is-block is-6 has-text-weight-bold">{{ user.display_name|truncatechars:10 }}</span>
<span title="@{{ user|username }}" class="is-block pb-3">@{{ user|username|truncatechars:8 }}</span>
</a>
{% include 'snippets/follow_button.html' with user=user minimal=True %}
{% if user.mutuals %}
<p class="help">
{% blocktrans with mutuals=user.mutuals|intcomma count counter=user.mutuals %}{{ mutuals }} follower you follow{% plural %}{{ mutuals }} followers you follow{% endblocktrans %}
</p>
{% elif user.shared_books %}
<p class="help">{% 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 %}</p>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% include 'feed/suggested_users.html' with suggested_users=suggested_users %}
<a class="help" href="{% url 'directory' %}">View directory <span class="icon icon-arrow-right"></a>
</section>
{% endif %}

View file

@ -0,0 +1,25 @@
{% load i18n %}
{% load bookwyrm_tags %}
{% load humanize %}
<div class="columns is-mobile scroll-x mb-0">
{% for user in suggested_users %}
<div class="column is-flex">
<div class="box has-text-centered is-shadowless has-background-white-bis m-0">
<a href="{{ user.local_path }}" class="has-text-black">
{% include 'snippets/avatar.html' with user=user large=True %}
<span title="{{ user.display_name }}" class="is-block is-6 has-text-weight-bold">{{ user.display_name|truncatechars:10 }}</span>
<span title="@{{ user|username }}" class="is-block pb-3">@{{ user|username|truncatechars:8 }}</span>
</a>
{% include 'snippets/follow_button.html' with user=user minimal=True %}
{% if user.mutuals %}
<p class="help">
{% blocktrans with mutuals=user.mutuals|intcomma count counter=user.mutuals %}{{ mutuals }} follower you follow{% plural %}{{ mutuals }} followers you follow{% endblocktrans %}
</p>
{% elif user.shared_books %}
<p class="help">{% 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 %}</p>
{% endif %}
</div>
</div>
{% endfor %}
</div>

View file

@ -4,7 +4,7 @@
{% block panel %}
<div class="block">
<h2 class="title is-4">{% trans "What are you reading?" %}</h2>
<form class="field has-addons" method="get" action="{% url 'get-started' %}">
<form class="field has-addons" method="get" action="{% url 'get-started-books' %}">
<div class="control">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a book' %}" aria-lable="{% trans 'Search for a book' %}">
{% if request.GET.query and not book_results %}

View file

@ -19,10 +19,12 @@
</section>
<footer class="modal-card-foot is-flex is-justify-content-flex-end">
<a href="{{ next }}" class="button">
{% if next %}
<a href="{% url next %}" class="button">
<span>{% trans "Skip this step" %}</span>
<span class="icon icon-arrow-right" aria-hidden="true"></span>
</a>
{% endif %}
</footer>
</div>
<a href="/" class="modal-close is-large" aria-label="close"></a>

View file

@ -0,0 +1,58 @@
{% extends 'get_started/layout.html' %}
{% load i18n %}
{% block panel %}
<div class="block">
<h2 class="title is-4">{% trans "A little bit about you" %}</h2>
{% if form.non_field_errors %}
<p class="notification is-danger">{{ form.non_field_errors }}</p>
{% endif %}
<form name="edit-profile" action="{% url 'get-started-profile' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="columns">
<div class="column is-two-thirds">
<div class="block">
<label class="label" for="id_name">{% trans "Display name:" %}</label>
<input type="text" name="name" maxlength="100" class="input" id="id_name" placeholder="{{ user.localname }}" value="{% if request.user.name %}{{ request.user.name }}{% endif %}">
{% for error in form.name.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div class="block">
<label class="label" for="id_summary">{% trans "Summary:" %}</label>
<textarea name="summary" cols="None" rows="None" class="textarea" id="id_summary" placeholder="{% trans 'A little bit about you' %}" value="{{ request.user.summary }}"></textarea>
{% for error in form.summary.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
</div>
<div class="column is-one-third">
<div class="block">
<label class="label" for="id_avatar">{% trans "Avatar:" %}</label>
{{ form.avatar }}
{% for error in form.avatar.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
</div>
</div>
<div class="block">
<label class="checkbox label" for="id_manually_approves_followers">
{% trans "Manually approve followers:" %}
{{ form.manually_approves_followers }}
</label>
</div>
<div class="block">
<label class="checkbox label" for="id_discoverable">
{% trans "Show this account in suggested users:" %}
<input type="checkbox" name="discoverable" class="checkbox" id="id_discoverable" checked>
</label>
{% url 'directory' as path %}
<p class="help">{% trans "Your account will show up in the directory, and may be recommended to other BookWyrm users." %}</p>
</div>
<div class="block"><button class="button is-primary" type="submit">{% trans "Save" %}</button></div>
</form>
</div>
{% endblock %}

View file

@ -0,0 +1,11 @@
{% extends 'get_started/layout.html' %}
{% load i18n %}
{% block panel %}
<div class="block">
<h2 class="title is-4">{% trans "Who to follow" %}</h2>
{% include 'feed/suggested_users.html' with suggested_users=suggested_users %}
</div>
{% endblock %}

View file

@ -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"^(?P<tab>home|local|federated)/?$", views.Feed.as_view()),
re_path(

View file

@ -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

View file

@ -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)