mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-02 06:21:09 +00:00
create group form
adds a group creation form to user dashboard
This commit is contained in:
parent
e07a25e288
commit
4e93b09067
7 changed files with 49 additions and 21 deletions
|
@ -295,6 +295,10 @@ class ListForm(CustomForm):
|
|||
model = models.List
|
||||
fields = ["user", "name", "description", "curation", "privacy"]
|
||||
|
||||
class GroupForm(CustomForm):
|
||||
class Meta:
|
||||
model = models.Group
|
||||
fields = ["name", "description", "privacy"]
|
||||
|
||||
class ReportForm(CustomForm):
|
||||
class Meta:
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block form %}
|
||||
<form name="create-group" method="post" action="{% url 'user-groups' %}">
|
||||
<form name="create-list" method="post" action="{% url 'lists' %}">
|
||||
{% include 'group/form.html' %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
<div class="columns">
|
||||
<div class="column is-two-thirds">
|
||||
<div class="field">
|
||||
<label class="label" for="id_name">{% trans "Name:" %}</label>
|
||||
<label class="label" for="id_name">{% trans "Group Name:" %}</label>
|
||||
{{ group_form.name }}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="id_description">{% trans "Description:" %}</label>
|
||||
<label class="label" for="id_description">{% trans "Group Description:" %}</label>
|
||||
{{ group_form.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="columns is-mobile">
|
||||
<!-- <div class="columns is-mobile">
|
||||
<div class="column">
|
||||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
|
@ -31,4 +31,4 @@
|
|||
{% include 'snippets/toggle/toggle_button.html' with class="is-danger" text=button_text icon_with_text="x" controls_text="delete_group" controls_uid=group.id focus="modal_title_delete_group" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div> -->
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
{% include 'groups/form.html' %}
|
||||
</form>
|
||||
|
||||
<!-- {% include 'lists/list_items.html' with lists=lists %} -->
|
||||
{% include 'groups/group_items.html' with groups=groups %}
|
||||
</section>
|
||||
<div>
|
||||
<!-- {% include 'snippets/pagination.html' with page=user_groups path=path %} -->
|
||||
{% include 'snippets/pagination.html' with page=user_groups path=path %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -254,8 +254,9 @@ urlpatterns = [
|
|||
# lists
|
||||
re_path(rf"{USER_PATH}/lists/?$", views.UserLists.as_view(), name="user-lists"),
|
||||
re_path(rf"{USER_PATH}/groups/?$", views.UserGroups.as_view(), name="user-groups"),
|
||||
re_path(r"^group/?$", views.UserGroups.as_view(), name="groups"),
|
||||
# re_path(r"^save-group/(?P<group_id>\d+)/?$", views.save_group, name="group-save"),
|
||||
re_path(r"^groups/?$", views.UserGroups.as_view(), name="groups"),
|
||||
# re_path(r"^group/?$", views.Group.as_view(), name="group"),
|
||||
re_path(r"^create-shelf/?$", views.create_shelf, name="group-create"),
|
||||
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
|
||||
re_path(r"^list/saved/?$", views.SavedLists.as_view(), name="saved-lists"),
|
||||
re_path(r"^list/(?P<list_id>\d+)(.json)?/?$", views.List.as_view(), name="list"),
|
||||
|
|
|
@ -32,7 +32,7 @@ from .follow import follow, unfollow
|
|||
from .follow import accept_follow_request, delete_follow_request
|
||||
from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers
|
||||
from .goal import Goal, hide_goal
|
||||
from .group import UserGroups
|
||||
from .group import Group, UserGroups
|
||||
from .import_data import Import, ImportStatus
|
||||
from .inbox import Inbox
|
||||
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
||||
|
|
|
@ -19,9 +19,39 @@ from django.views.decorators.http import require_POST
|
|||
from bookwyrm import forms, models
|
||||
from bookwyrm.connectors import connector_manager
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
from .helpers import is_api_request, privacy_filter
|
||||
from .helpers import privacy_filter
|
||||
from .helpers import get_user_from_username
|
||||
|
||||
class Group(View):
|
||||
"""group page"""
|
||||
|
||||
def get(self, request):
|
||||
"""display a group"""
|
||||
|
||||
groups = models.Group.objects.query(members__contains=request.user)
|
||||
groups = privacy_filter(
|
||||
request.user, groups, privacy_levels=["public", "followers"]
|
||||
)
|
||||
|
||||
paginated = Paginator(groups, 12)
|
||||
data = {
|
||||
"lists": paginated.get_page(request.GET.get("page")),
|
||||
"list_form": forms.GroupForm(),
|
||||
"path": "/group",
|
||||
}
|
||||
return TemplateResponse(request, "groups/group.html", data)
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
# pylint: disable=unused-argument
|
||||
def post(self, request):
|
||||
"""create a book_list"""
|
||||
form = forms.ListForm(request.POST)
|
||||
if not form.is_valid():
|
||||
return redirect("lists")
|
||||
book_list = form.save()
|
||||
|
||||
return redirect(book_list.local_path)
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
class UserGroups(View):
|
||||
"""a user's groups page"""
|
||||
|
@ -30,22 +60,14 @@ class UserGroups(View):
|
|||
"""display a group"""
|
||||
user = get_user_from_username(request.user, username)
|
||||
groups = models.GroupMember.objects.filter(user=user)
|
||||
# groups = privacy_filter(request.user, groups)
|
||||
groups = privacy_filter(request.user, groups)
|
||||
paginated = Paginator(groups, 12)
|
||||
|
||||
data = {
|
||||
"user": user,
|
||||
"is_self": request.user.id == user.id,
|
||||
"groups": paginated.get_page(request.GET.get("page")),
|
||||
"group_form": forms.GroupsForm(),
|
||||
"group_form": forms.GroupForm(),
|
||||
"path": user.local_path + "/groups",
|
||||
}
|
||||
return TemplateResponse(request, "user/groups.html", data)
|
||||
|
||||
# @require_POST
|
||||
# @login_required
|
||||
# def save_list(request, group_id):
|
||||
# """save a group"""
|
||||
# group = get_object_or_404(models.Group, id=group_id)
|
||||
# request.user.saved_group.add(group)
|
||||
# return redirect("user", request.user.id) # TODO: change this to group page
|
Loading…
Reference in a new issue