Adds compose view

This commit is contained in:
Mouse Reeve 2021-04-03 14:32:34 -07:00
parent dae31459e4
commit 4cf9bca5aa
3 changed files with 45 additions and 6 deletions

View file

@ -0,0 +1,30 @@
{% extends 'layout.html' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% block title %}{% trans "Compose status" %}{% endblock %}
{% block content %}
<header class="block content">
<h1>{% trans "Compose status" %}</h1>
</header>
<div class="box columns">
{% if book %}
<div class="column is-one-third">
<div class="block">
<a href="{{ book.local_path }}">{% include 'snippets/book_cover.html' with book=book %}</a>
</div>
<h3 class="title is-6">{% include 'snippets/book_titleby.html' with book=book %}</h3>
</div>
{% endif %}
<div class="column is-two-thirds">
{% if not form %}
{% include 'snippets/create_status.html' %}
{% else %}
{% include 'snippets/create_status_form.html' %}
{% endif %}
</div>
</div>
{% endblock %}

View file

@ -202,6 +202,11 @@ urlpatterns = [
re_path(
r"%s/replies(.json)?/?$" % status_path, views.Replies.as_view(), name="replies"
),
re_path(
r"^post/?$",
views.CreateStatus.as_view(),
name="create-status",
),
re_path(
r"^post/(?P<status_type>\w+)/?$",
views.CreateStatus.as_view(),

View file

@ -12,7 +12,6 @@ from bookwyrm import forms, models
from bookwyrm.sanitize_html import InputHtmlParser
from bookwyrm.settings import DOMAIN
from bookwyrm.utils import regex
from .feed import feed_page_data
from .helpers import handle_remote_webfinger
from .reading import edit_readthrough
@ -22,6 +21,12 @@ from .reading import edit_readthrough
class CreateStatus(View):
""" the view for *posting* """
def get(self, request):
""" compose view (used for delete-and-redraft """
book = get_object_or_404(models.Edition, id=request.GET.get("book"))
data = {"book": book}
return TemplateResponse(request, "compose.html", data)
def post(self, request, status_type):
""" create status of whatever type """
status_type = status_type[0].upper() + status_type[1:]
@ -103,14 +108,13 @@ class DeleteAndRedraft(View):
return HttpResponseBadRequest()
# TODO: get the correct form (maybe a generic form)
redraft_form = forms.StatusForm(instance=status)
data = {"form": forms.StatusForm(instance=status)}
if hasattr(status, "book"):
data["book"] = status.book
# perform deletion
status.delete()
data = feed_page_data(request.user)
# TODO: set up the correct edit state
data["redraft_form"] = redraft_form
return TemplateResponse(request, "feed/feed.html")
return TemplateResponse(request, "compose.html", data)
def find_mentions(content):