Fixes create status forms

This commit is contained in:
Mouse Reeve 2020-10-27 11:32:15 -07:00
parent 39b9fe8f4a
commit b7061c0f4d
5 changed files with 38 additions and 57 deletions

View file

@ -52,47 +52,31 @@ class RegisterForm(CustomForm):
class RatingForm(CustomForm):
class Meta:
model = models.Review
fields = ['rating']
fields = ['user', 'book', 'content', 'rating', 'privacy']
class ReviewForm(CustomForm):
class Meta:
model = models.Review
fields = ['name', 'content']
help_texts = {f: None for f in fields}
labels = {
'name': 'Title',
'content': 'Review',
}
fields = ['user', 'book', 'name', 'content', 'rating', 'privacy']
class CommentForm(CustomForm):
class Meta:
model = models.Comment
fields = ['content']
help_texts = {f: None for f in fields}
labels = {
'content': 'Comment',
}
fields = ['user', 'book', 'content', 'privacy']
class QuotationForm(CustomForm):
class Meta:
model = models.Quotation
fields = ['quote', 'content']
help_texts = {f: None for f in fields}
labels = {
'quote': 'Quote',
'content': 'Comment',
}
fields = ['user', 'book', 'quote', 'content', 'privacy']
class ReplyForm(CustomForm):
class Meta:
model = models.Status
fields = ['content']
help_texts = {f: None for f in fields}
labels = {'content': 'Comment'}
fields = ['user', 'content', 'reply_parent', 'privacy']
class EditUserForm(CustomForm):

View file

@ -9,7 +9,6 @@ import requests
from bookwyrm import activitypub
from bookwyrm import models
from bookwyrm.broadcast import broadcast
from bookwyrm.status import create_status
from bookwyrm.status import create_tag, create_notification
from bookwyrm.status import create_generated_note
from bookwyrm.status import delete_status
@ -214,12 +213,21 @@ def handle_status(user, form):
''' generic handler for statuses '''
status = form.save()
# notify reply parent or (TODO) tagged users
if status.reply_parent and status.reply_parent.user.local:
create_notification(
status.reply_parent.user,
'REPLY',
related_user=user,
related_status=status
)
broadcast(user, status.to_create_activity(user), software='bookwyrm')
# re-format the activity for non-bookwyrm servers
remote_activity = status.to_create_activity(user, pure=True)
broadcast(user, remote_activity, software='other')
if hasattr(status, 'pure_activity_serializer'):
remote_activity = status.to_create_activity(user, pure=True)
broadcast(user, remote_activity, software='other')
def handle_tag(user, book, name):
@ -238,21 +246,6 @@ def handle_untag(user, book, name):
broadcast(user, tag_activity)
def handle_reply(user, review, content):
''' respond to a review or status '''
# validated and saves the comment in the database so it has an id
reply = create_status(user, content, reply_parent=review)
if reply.reply_parent:
create_notification(
reply.reply_parent.user,
'REPLY',
related_user=user,
related_status=reply,
)
broadcast(user, reply.to_create_activity(user))
def handle_favorite(user, status):
''' a user likes a status '''
try:

View file

@ -22,6 +22,8 @@
<form class="toggle-content hidden tab-option-{{ book.id }}" name="review" action="/review/" method="post" id="tab-review-{{ book.id }}">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="privacy" value="public">
<div class="control">
<label class="label" for="id_name_{{ book.id }}_review">Title:</label>
<input type="text" name="name" maxlength="255" class="input" required="" id="id_name_{{ book.id }}_review" placeholder="My review of '{{ book.title }}'">
@ -51,6 +53,9 @@
<form class="toggle-content hidden tab-option-{{ book.id }}" name="comment" action="/comment/" method="post" id="tab-comment-{{ book.id }}">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="privacy" value="public">
<div class="control">
<label class="label" for="id_content_{{ book.id }}_comment">Comment:</label>
<textarea name="content" class="textarea" id="id_content_{{ book.id }}_comment" placeholder="Some thoughts on '{{ book.title }}'"></textarea>
@ -64,6 +69,9 @@
<form class="toggle-content hidden tab-option-{{ book.id }}" name="quotation" action="/quotate/" method="post" id="tab-quotation-{{ book.id }}">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="privacy" value="public">
<div class="control">
<label class="label" for="id_quote_{{ book.id }}_quote">Quote:</label>
<textarea name="quote" class="textarea" required="" id="id_quote_{{ book.id }}_quote" placeholder="An except from '{{ book.title }}'"></textarea>

View file

@ -4,7 +4,9 @@
<form name="reply" action="/reply" method="post" onsubmit="return reply(event)">
<div class="field is-grouped">
{% csrf_token %}
<input type="hidden" name="parent" value="{{ activity.id }}">
<input type="hidden" name="reply_parent" value="{{ activity.id }}">
<input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="privacy" value="public">
<textarea name="content" placeholder="Leave a comment..." id="id_content_{{ activity.id }}" required="true"></textarea>
<button class="button" type="submit">
<span class="icon icon-comment">

View file

@ -320,14 +320,21 @@ def comment(request):
return handle_status(request, form)
@login_required
def reply(request):
''' respond to a book review '''
form = forms.ReplyForm(request.POST)
return handle_status(request, form)
def handle_status(request, form):
''' all the review/comment/quote etc functions are the same '''
''' all the "create a status" functions are the same '''
book_id = request.POST.get('book')
if not form.is_valid():
return redirect('/book/%s' % book_id)
return redirect(request.headers.get('Referer', '/'))
outgoing.handle_status(request.user, form)
return redirect('/book/%s' % book_id)
return redirect(request.headers.get('Referer', '/'))
@login_required
@ -353,19 +360,6 @@ def untag(request):
return redirect('/book/%s' % book_id)
@login_required
def reply(request):
''' respond to a book review '''
form = forms.ReplyForm(request.POST)
# this is a bit of a formality, the form is just one text field
if not form.is_valid():
return redirect('/')
parent_id = request.POST['parent']
parent = models.Status.objects.get(id=parent_id)
outgoing.handle_reply(request.user, parent, form.data['content'])
return redirect('/')
@login_required
def favorite(request, status_id):
''' like a status '''