collection: inline comment edit

This commit is contained in:
Your Name 2022-01-16 19:20:22 -05:00
parent 85eb79be7f
commit 651384ee77
6 changed files with 37 additions and 2 deletions

View file

@ -306,7 +306,6 @@ def create_update_mark(request):
return HttpResponseServerError("integrity error")
if form.cleaned_data['share_to_mastodon']:
print(form.cleaned_data)
if form.cleaned_data['visibility'] == 2:
visibility = TootVisibilityEnum.DIRECT
elif form.cleaned_data['visibility'] == 1:

View file

@ -0,0 +1,5 @@
<form hx-post="{% url 'collection:update_item_comment' collection.id item.id %}">
<input name="comment" value="{{ item.comment }}">
<input type="submit" style="width:unset;" value="修改">
<button style="width:unset;" hx-get="{% url 'collection:show_item_comment' collection.id item.id %}">取消</button>
</form>

View file

@ -50,7 +50,9 @@
<div class="entity-marks" style="margin-bottom: 0;">
<ul class="entity-marks__mark-list">
<li class="entity-marks__mark">
<p class="entity-marks__mark-content">{{ item.comment }}</p>
<p class="entity-marks__mark-content" hx-target="this" hx-swap="innerHTML">
{% include "show_item_comment.html" %}
</p>
</li>
</ul>
</div>

View file

@ -0,0 +1,4 @@
{{ item.comment }}
{% if editable %}
<a hx-get="{% url 'collection:update_item_comment' collection.id item.id %}"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="cursor:pointer;fill:#ccc;height:12px;vertical-align:text-bottom;"><g><path d="M19,20H5a1,1,0,0,0,0,2H19a1,1,0,0,0,0-2Z"/><path d="M5,18h.09l4.17-.38a2,2,0,0,0,1.21-.57l9-9a1.92,1.92,0,0,0-.07-2.71h0L16.66,2.6A2,2,0,0,0,14,2.53l-9,9a2,2,0,0,0-.57,1.21L4,16.91a1,1,0,0,0,.29.8A1,1,0,0,0,5,18ZM15.27,4,18,6.73,16,8.68,13.32,6Zm-8.9,8.91L12,7.32l2.7,2.7-5.6,5.6-3,.28Z"/></g></svg></a>
{% endif %}

View file

@ -16,6 +16,8 @@ urlpatterns = [
path('<int:id>/delete_item/<int:item_id>', delete_item, name='delete_item'),
path('<int:id>/move_up_item/<int:item_id>', move_up_item, name='move_up_item'),
path('<int:id>/move_down_item/<int:item_id>', move_down_item, name='move_down_item'),
path('<int:id>/update_item_comment/<int:item_id>', update_item_comment, name='update_item_comment'),
path('<int:id>/show_item_comment/<int:item_id>', show_item_comment, name='show_item_comment'),
path('with/<str:type>/<int:id>/', list_with, name='list_with'),
path('add_to_list/<str:type>/<int:id>/', add_to_list, name='add_to_list'),

View file

@ -340,6 +340,29 @@ def move_down_item(request, id, item_id):
return HttpResponseBadRequest()
def show_item_comment(request, id, item_id):
collection = get_object_or_404(Collection, pk=id)
item = CollectionItem.objects.get(id=item_id)
editable = collection.is_editable_by(request.user)
return render(request, 'show_item_comment.html', {'collection': collection, 'item': item, 'editable': editable})
@login_required
def update_item_comment(request, id, item_id):
collection = get_object_or_404(Collection, pk=id)
if collection.is_editable_by(request.user):
# item_id = int(request.POST.get('item_id'))
item = CollectionItem.objects.get(id=item_id)
if item is not None and item.collection == collection:
if request.method == 'POST':
item.comment = request.POST.get('comment', default='')
item.save()
return render(request, 'show_item_comment.html', {'collection': collection, 'item': item, 'editable': True})
else:
return render(request, 'edit_item_comment.html', {'collection': collection, 'item': item})
return retrieve_entity_list(request, id)
return HttpResponseBadRequest()
@login_required
def list_with(request, type, id):
pass