mirror of
https://github.com/jointakahe/takahe.git
synced 2024-12-23 05:56:29 +00:00
Hashtag admin simplification
This commit is contained in:
parent
39013e0bb5
commit
e28294c81a
10 changed files with 36 additions and 136 deletions
|
@ -116,10 +116,8 @@ class Hashtag(StatorModel):
|
|||
objects = HashtagManager()
|
||||
|
||||
class urls(urlman.Urls):
|
||||
root = "/admin/hashtags/"
|
||||
create = "/admin/hashtags/create/"
|
||||
edit = "/admin/hashtags/{self.hashtag}/"
|
||||
delete = "{edit}delete/"
|
||||
admin = "/admin/hashtags/"
|
||||
admin_edit = "{admin}{self.hashtag}/"
|
||||
timeline = "/tags/{self.hashtag}/"
|
||||
|
||||
hashtag_regex = re.compile(r"\B#([a-zA-Z0-9(_)]+\b)(?!;)")
|
||||
|
|
|
@ -145,19 +145,10 @@ urlpatterns = [
|
|||
admin.Hashtags.as_view(),
|
||||
name="admin_hashtags",
|
||||
),
|
||||
path(
|
||||
"admin/hashtags/create/",
|
||||
admin.HashtagCreate.as_view(),
|
||||
name="admin_hashtags_create",
|
||||
),
|
||||
path(
|
||||
"admin/hashtags/<hashtag>/",
|
||||
admin.HashtagEdit.as_view(),
|
||||
),
|
||||
path(
|
||||
"admin/hashtags/<hashtag>/delete/",
|
||||
admin.HashtagDelete.as_view(),
|
||||
),
|
||||
path(
|
||||
"admin/stator/",
|
||||
admin.Stator.as_view(),
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
{% extends "settings/base.html" %}
|
||||
|
||||
{% block title %}Add hashtag - Admin{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="." method="POST">
|
||||
<h1>Add A hashtag</h1>
|
||||
<p>
|
||||
Use this form to add a hashtag.
|
||||
</p>
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<legend>hashtag Details</legend>
|
||||
{% include "forms/_field.html" with field=form.hashtag %}
|
||||
{% include "forms/_field.html" with field=form.name_override %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Access Control</legend>
|
||||
{% include "forms/_field.html" with field=form.public %}
|
||||
</fieldset>
|
||||
<div class="buttons">
|
||||
<a href="{% url "admin_hashtags" %}" class="button secondary left">Back</a>
|
||||
<button>Create</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -1,17 +0,0 @@
|
|||
{% extends "settings/base.html" %}
|
||||
|
||||
{% block title %}Delete <i class="fa-solid fa-hashtag"></i>{{ hashtag.hashtag }} - Admin{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="." method="POST">
|
||||
{% csrf_token %}
|
||||
|
||||
<h1>Deleting <i class="fa-solid fa-hashtag"></i>{{ hashtag.hashtag }}</h1>
|
||||
|
||||
<p>Please confirm deletion of this hashtag.</p>
|
||||
<div class="buttons">
|
||||
<a class="button" href="{{ hashtag.urls.edit }}">Cancel</a>
|
||||
<button class="delete">Confirm Deletion</button>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -38,8 +38,8 @@
|
|||
</div>
|
||||
</fieldset>
|
||||
<div class="buttons">
|
||||
<a href="{{ hashtag.urls.root }}" class="button secondary left">Back</a>
|
||||
<a href="{{ hashtag.urls.delete }}" class="button delete">Delete</a>
|
||||
<a href="{{ hashtag.urls.admin }}" class="button secondary left">Back</a>
|
||||
<a href="{{ hashtag.urls.timeline }}" class="button secondary">View Posts</a>
|
||||
<button>Save</button>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
{% block content %}
|
||||
<section class="icon-menu">
|
||||
{% for hashtag in hashtags %}
|
||||
<a class="option" href="{{ hashtag.urls.edit }}">
|
||||
{% for hashtag in page_obj %}
|
||||
<a class="option" href="{{ hashtag.urls.admin_edit }}">
|
||||
<i class="fa-solid fa-hashtag"></i>
|
||||
<span class="handle">
|
||||
{{ hashtag.display_name }}
|
||||
|
@ -31,10 +31,15 @@
|
|||
|
||||
</a>
|
||||
{% empty %}
|
||||
<p class="option empty">You have no hashtags set up.</p>
|
||||
<p class="option empty">There are no hashtags yet.</p>
|
||||
{% endfor %}
|
||||
<a href="{% url "admin_hashtags_create" %}" class="option new">
|
||||
<i class="fa-solid fa-plus"></i> Add a hashtag
|
||||
</a>
|
||||
<div class="load-more">
|
||||
{% if page_obj.has_previous %}
|
||||
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||
{% endif %}
|
||||
{% if page_obj.has_next %}
|
||||
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
<a href="{% url "admin_reports" %}" {% if section == "reports" %}class="selected"{% endif %} title="Reports">
|
||||
<i class="fa-solid fa-flag"></i> Reports
|
||||
</a>
|
||||
<a href="{% url "admin_federation" %}" {% if section == "federation" %}class="selected"{% endif %} title="Federation">
|
||||
<i class="fa-solid fa-diagram-project"></i> Federation
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if request.user.admin %}
|
||||
<h3>Administration</h3>
|
||||
|
@ -42,6 +39,9 @@
|
|||
<a href="{% url "admin_domains" %}" {% if section == "domains" %}class="selected"{% endif %} title="Domains">
|
||||
<i class="fa-solid fa-globe"></i> Domains
|
||||
</a>
|
||||
<a href="{% url "admin_federation" %}" {% if section == "federation" %}class="selected"{% endif %} title="Federation">
|
||||
<i class="fa-solid fa-diagram-project"></i> Federation
|
||||
</a>
|
||||
<a href="{% url "admin_users" %}" {% if section == "users" %}class="selected"{% endif %} title="Users">
|
||||
<i class="fa-solid fa-users"></i> Users
|
||||
</a>
|
||||
|
|
|
@ -9,12 +9,7 @@ from users.views.admin.domains import ( # noqa
|
|||
Domains,
|
||||
)
|
||||
from users.views.admin.federation import FederationEdit, FederationRoot # noqa
|
||||
from users.views.admin.hashtags import ( # noqa
|
||||
HashtagCreate,
|
||||
HashtagDelete,
|
||||
HashtagEdit,
|
||||
Hashtags,
|
||||
)
|
||||
from users.views.admin.hashtags import HashtagEdit, Hashtags # noqa
|
||||
from users.views.admin.identities import IdentitiesRoot, IdentityEdit # noqa
|
||||
from users.views.admin.invites import InviteCreate, InvitesRoot, InviteView # noqa
|
||||
from users.views.admin.reports import ReportsRoot, ReportView # noqa
|
||||
|
|
|
@ -4,11 +4,11 @@ from django.shortcuts import get_object_or_404, redirect
|
|||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import FormView, ListView
|
||||
|
||||
from users.decorators import moderator_required
|
||||
from users.decorators import admin_required
|
||||
from users.models import Domain
|
||||
|
||||
|
||||
@method_decorator(moderator_required, name="dispatch")
|
||||
@method_decorator(admin_required, name="dispatch")
|
||||
class FederationRoot(ListView):
|
||||
|
||||
template_name = "admin/federation.html"
|
||||
|
@ -33,7 +33,7 @@ class FederationRoot(ListView):
|
|||
return domains
|
||||
|
||||
|
||||
@method_decorator(moderator_required, name="dispatch")
|
||||
@method_decorator(admin_required, name="dispatch")
|
||||
class FederationEdit(FormView):
|
||||
|
||||
template_name = "admin/federation_edit.html"
|
||||
|
|
|
@ -1,33 +1,38 @@
|
|||
from django import forms
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import FormView, TemplateView
|
||||
from django.views.generic import FormView, ListView
|
||||
|
||||
from activities.models import Hashtag, HashtagStates
|
||||
from users.decorators import moderator_required
|
||||
|
||||
|
||||
@method_decorator(moderator_required, name="dispatch")
|
||||
class Hashtags(TemplateView):
|
||||
class Hashtags(ListView):
|
||||
|
||||
template_name = "admin/hashtags.html"
|
||||
paginate_by = 30
|
||||
|
||||
def get_context_data(self):
|
||||
return {
|
||||
"hashtags": Hashtag.objects.filter().order_by("hashtag"),
|
||||
"section": "hashtag",
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.extra_context = {
|
||||
"section": "hashtags",
|
||||
}
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
return Hashtag.objects.filter().order_by("hashtag")
|
||||
|
||||
|
||||
@method_decorator(moderator_required, name="dispatch")
|
||||
class HashtagCreate(FormView):
|
||||
class HashtagEdit(FormView):
|
||||
|
||||
template_name = "admin/hashtag_create.html"
|
||||
template_name = "admin/hashtag_edit.html"
|
||||
extra_context = {"section": "hashtags"}
|
||||
|
||||
class form_class(forms.Form):
|
||||
hashtag = forms.SlugField(
|
||||
help_text="The hashtag without the '#'",
|
||||
disabled=True,
|
||||
)
|
||||
name_override = forms.CharField(
|
||||
help_text="Optional - a more human readable hashtag.",
|
||||
|
@ -41,14 +46,6 @@ class HashtagCreate(FormView):
|
|||
required=False,
|
||||
)
|
||||
|
||||
def clean_hashtag(self):
|
||||
hashtag = self.cleaned_data["hashtag"].lstrip("#").lower()
|
||||
if not Hashtag.hashtag_regex.match("#" + hashtag):
|
||||
raise forms.ValidationError("This does not look like a hashtag name")
|
||||
if Hashtag.objects.filter(hashtag=hashtag):
|
||||
raise forms.ValidationError("This hashtag name is already in use")
|
||||
return hashtag
|
||||
|
||||
def clean_name_override(self):
|
||||
name_override = self.cleaned_data["name_override"]
|
||||
if not name_override:
|
||||
|
@ -59,29 +56,6 @@ class HashtagCreate(FormView):
|
|||
)
|
||||
return self.cleaned_data["name_override"]
|
||||
|
||||
def form_valid(self, form):
|
||||
Hashtag.objects.create(
|
||||
hashtag=form.cleaned_data["hashtag"],
|
||||
name_override=form.cleaned_data["name_override"] or None,
|
||||
public=form.cleaned_data["public"],
|
||||
)
|
||||
return redirect(Hashtag.urls.root)
|
||||
|
||||
|
||||
@method_decorator(moderator_required, name="dispatch")
|
||||
class HashtagEdit(FormView):
|
||||
|
||||
template_name = "admin/hashtag_edit.html"
|
||||
extra_context = {"section": "hashtags"}
|
||||
|
||||
class form_class(HashtagCreate.form_class):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["hashtag"].disabled = True
|
||||
|
||||
def clean_hashtag(self):
|
||||
return self.cleaned_data["hashtag"]
|
||||
|
||||
def dispatch(self, request, hashtag):
|
||||
self.hashtag = get_object_or_404(Hashtag.objects, hashtag=hashtag)
|
||||
return super().dispatch(request)
|
||||
|
@ -96,7 +70,7 @@ class HashtagEdit(FormView):
|
|||
self.hashtag.name_override = form.cleaned_data["name_override"]
|
||||
self.hashtag.save()
|
||||
Hashtag.transition_perform(self.hashtag, HashtagStates.outdated)
|
||||
return redirect(Hashtag.urls.root)
|
||||
return redirect(Hashtag.urls.admin)
|
||||
|
||||
def get_initial(self):
|
||||
return {
|
||||
|
@ -104,23 +78,3 @@ class HashtagEdit(FormView):
|
|||
"name_override": self.hashtag.name_override,
|
||||
"public": self.hashtag.public,
|
||||
}
|
||||
|
||||
|
||||
@method_decorator(moderator_required, name="dispatch")
|
||||
class HashtagDelete(TemplateView):
|
||||
|
||||
template_name = "admin/hashtag_delete.html"
|
||||
|
||||
def dispatch(self, request, hashtag):
|
||||
self.hashtag = get_object_or_404(Hashtag.objects, hashtag=hashtag)
|
||||
return super().dispatch(request)
|
||||
|
||||
def get_context_data(self):
|
||||
return {
|
||||
"hashtag": self.hashtag,
|
||||
"section": "hashtags",
|
||||
}
|
||||
|
||||
def post(self, request):
|
||||
self.hashtag.delete()
|
||||
return redirect("admin_hashtags")
|
||||
|
|
Loading…
Reference in a new issue