mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-26 18:10:36 +00:00
ui path to iniate blocks
This commit is contained in:
parent
d994d8d3c8
commit
ac2ab2981f
6 changed files with 69 additions and 16 deletions
11
bookwyrm/templates/snippets/block_button.html
Normal file
11
bookwyrm/templates/snippets/block_button.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{% if not user in request.user.blocks.all %}
|
||||||
|
<form name="blocks" method="post" action="/block/{{ user.id }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="button is-danger is-light is-small is-fullwidth" type="submit">Block</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<form name="unblocks" method="post" action="/unblock/{{ user.id }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="button is-small is-fullwidth" type="submit">Un-block</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
|
@ -17,14 +17,9 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
<li><hr class="navbar-divider"></li>
|
{% else %}
|
||||||
{% endif %}
|
|
||||||
<li role="menuitem">
|
<li role="menuitem">
|
||||||
<form class="dropdown-item pt-0 pb-0" name="delete-{{status.id}}" action="/delete-status/{{ status.id }}" method="post">
|
{% include 'snippets/block_button.html' with user=status.user %}
|
||||||
{% csrf_token %}
|
|
||||||
<button class="button is-danger is-light is-fullwidth is-small" type="submit">
|
|
||||||
Block @{{ status.user|username }}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -35,11 +35,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if not is_self %}
|
{% if not is_self %}
|
||||||
|
<div class="field has-addons">
|
||||||
|
<div class="control">
|
||||||
{% include 'snippets/follow_button.html' with user=user %}
|
{% include 'snippets/follow_button.html' with user=user %}
|
||||||
<form name="blocks" method="post" action="/block/{{ user.id }}">
|
</div>
|
||||||
{% csrf_token %}
|
<div class="control">
|
||||||
<button type="submit">Block</button>
|
{% include 'snippets/user_options.html' with user=user class="is-small" %}
|
||||||
</form>
|
</div>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if is_self and user.follower_requests.all %}
|
{% if is_self and user.follower_requests.all %}
|
||||||
|
|
14
bookwyrm/templates/snippets/user_options.html
Normal file
14
bookwyrm/templates/snippets/user_options.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends 'snippets/components/dropdown.html' %}
|
||||||
|
{% load bookwyrm_tags %}
|
||||||
|
|
||||||
|
{% block dropdown-trigger %}
|
||||||
|
<span class="icon icon-dots-three">
|
||||||
|
<span class="is-sr-only">More options</span>
|
||||||
|
</span>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block dropdown-list %}
|
||||||
|
<li role="menuitem">
|
||||||
|
{% include 'snippets/block_button.html' with user=user %}
|
||||||
|
</li>
|
||||||
|
{% endblock %}
|
29
bookwyrm/views/block.py
Normal file
29
bookwyrm/views/block.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
''' views for actions you can take in the application '''
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views import View
|
||||||
|
|
||||||
|
from bookwyrm import models
|
||||||
|
from bookwyrm.broadcast import broadcast
|
||||||
|
|
||||||
|
# pylint: disable= no-self-use
|
||||||
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
class Block(View):
|
||||||
|
''' blocking users '''
|
||||||
|
def get(self, request):
|
||||||
|
''' list of blocked users? '''
|
||||||
|
|
||||||
|
def post(self, request, user_id):
|
||||||
|
''' block a user '''
|
||||||
|
to_block = get_object_or_404(models.User, id=user_id)
|
||||||
|
block = models.UserBlocks.objects.create(
|
||||||
|
user_subject=request.user, user_object=to_block)
|
||||||
|
if not to_block.local:
|
||||||
|
broadcast(
|
||||||
|
request.user,
|
||||||
|
block.to_activity(),
|
||||||
|
privacy='direct',
|
||||||
|
direct_recipients=[to_block]
|
||||||
|
)
|
||||||
|
return redirect('/blocks')
|
|
@ -72,6 +72,7 @@ def get_activity_feed(
|
||||||
queryset = queryset.exclude(deleted=True).order_by('-published_date')
|
queryset = queryset.exclude(deleted=True).order_by('-published_date')
|
||||||
|
|
||||||
# exclude blocks from both directions
|
# exclude blocks from both directions
|
||||||
|
if not user.is_anonymous:
|
||||||
blocked = models.User.objects.filter(id__in=user.blocks.all()).all()
|
blocked = models.User.objects.filter(id__in=user.blocks.all()).all()
|
||||||
queryset = queryset.exclude(
|
queryset = queryset.exclude(
|
||||||
Q(user__in=blocked) | Q(user__blocks=user))
|
Q(user__in=blocked) | Q(user__blocks=user))
|
||||||
|
|
Loading…
Reference in a new issue