Update webhook page

This commit is contained in:
2024-07-06 23:29:39 +02:00
parent 9da33b402c
commit f37975d94a
15 changed files with 122 additions and 127 deletions

View File

@ -107,16 +107,16 @@
</div>
</div>
<script type="module">
const scrollSpy = new bootstrap.ScrollSpy(document.body, {
target: '.toc'
})
const scrollSpy = new bootstrap.ScrollSpy(document.body, {
target: '.toc'
})
document.body.addEventListener('activate.bs.scrollspy', function (event) {
const activeItem = document.querySelector('.toc .active');
if (activeItem) {
activeItem.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
}
});
document.body.addEventListener('activate.bs.scrollspy', function (event) {
const activeItem = document.querySelector('.toc .active');
if (activeItem) {
activeItem.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
}
});
</script>
</body>
{% endblock content %}

View File

@ -2,22 +2,27 @@
{% block content %}
<div class="container">
<h1 class="my-4">Add Discord Webhook</h1>
<form method="post" class="needs-validation" novalidate>
{% csrf_token %}
{{ form.non_field_errors }}
<div class="mb-3">
{{ form.webhook_url.errors }}
<label for="{{ form.webhook_url.id_for_label }}" class="form-label">{{ form.webhook_url.label }}</label>
<input type="url"
name="webhook_url"
required=""
class="form-control"
aria-describedby="id_webhook_url_helptext"
id="id_webhook_url">
<div class="form-text text-muted">{{ form.webhook_url.help_text }}</div>
</div>
<button type="submit" class="btn btn-primary">Add Webhook</button>
</form>
<div class="card card-body mb-3">
Webhooks will be saved in a cookie and will be sent to the server when you subscribe to a drop.
</div>
<div>
<form method="post" class="needs-validation" novalidate>
{% csrf_token %}
{{ form.non_field_errors }}
<div class="mb-3">
{{ form.webhook_url.errors }}
<label for="{{ form.webhook_url.id_for_label }}" class="form-label">{{ form.webhook_url.label }}</label>
<input type="url"
name="webhook_url"
required=""
class="form-control"
aria-describedby="id_webhook_url_helptext"
id="id_webhook_url">
<div class="form-text text-muted">{{ form.webhook_url.help_text }}</div>
</div>
<button type="submit" class="btn btn-primary">Add Webhook</button>
</form>
</div>
<h2 class="mt-5">Webhooks</h2>
{% if webhooks %}
<ul class="list-group mt-3">

View File

@ -8,13 +8,13 @@ if TYPE_CHECKING:
from django.http import HttpResponse
@pytest.fixture()
@pytest.fixture
def factory() -> RequestFactory:
"""Factory for creating requests."""
return RequestFactory()
@pytest.mark.django_db()
@pytest.mark.django_db
def test_index_view(client: Client) -> None:
"""Test index view."""
url: str = reverse(viewname="core:index")

View File

@ -6,7 +6,6 @@ from . import views
app_name: str = "core"
urlpatterns: list[URLPattern | URLResolver] = [
path(route="", view=views.index, name="index"),
path(

View File

@ -11,7 +11,6 @@ from django.contrib import messages
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.views.generic import FormView, ListView
from httpx._models import Response
from twitch_app.models import (
DropBenefit,
@ -33,7 +32,6 @@ if TYPE_CHECKING:
logger: logging.Logger = logging.getLogger(__name__)
cache_dir: Path = settings.DATA_DIR / "cache"
cache_dir.mkdir(exist_ok=True, parents=True)
storage = hishel.FileStorage(base_path=cache_dir)
@ -284,7 +282,7 @@ class WebhooksView(FormView):
webhooks.append(webhook)
response: HttpResponse = self.render_to_response(self.get_context_data(form=form))
response.set_cookie(key="webhooks", value=",".join(webhooks), max_age=60 * 60 * 24 * 365)
response.set_cookie(key="webhooks", value=",".join(webhooks), max_age=315360000) # 10 years
messages.success(self.request, "Webhook successfully added.")
return response