Skip to content

Commit ef9839e

Browse files
authored
Added asciidoctor preview sandbox (#1928) (#1934)
1 parent c7571ae commit ef9839e

File tree

18 files changed

+364
-0
lines changed

18 files changed

+364
-0
lines changed

asciidoctor_sandbox/__init__.py

Whitespace-only changes.

asciidoctor_sandbox/admin.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from django.contrib import admin
2+
from django.contrib.auth import get_user_model
3+
4+
from core.admin_filters import StaffUserCreatedByFilter
5+
from .models import SandboxDocument
6+
7+
User = get_user_model()
8+
9+
10+
@admin.register(SandboxDocument)
11+
class SandboxDocumentAdmin(admin.ModelAdmin):
12+
list_display = ("title", "created_by", "created_at", "updated_at")
13+
list_filter = ("created_at", "updated_at", StaffUserCreatedByFilter)
14+
search_fields = ("title", "asciidoc_content")
15+
readonly_fields = ("created_at", "updated_at", "created_by")
16+
ordering = ("-updated_at",)
17+
change_form_template = "admin/asciidoctor_sandbox_doc_change_form.html"
18+
19+
fieldsets = (
20+
(None, {"fields": ("title", "asciidoc_content")}),
21+
(
22+
"Metadata",
23+
{
24+
"fields": ("created_by", "created_at", "updated_at"),
25+
"classes": ("collapse",),
26+
},
27+
),
28+
)
29+
30+
def save_model(self, request, obj, form, change):
31+
if not change:
32+
obj.created_by = request.user
33+
super().save_model(request, obj, form, change)

asciidoctor_sandbox/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AsciidoctorSandboxConfig(AppConfig):
5+
name = "asciidoctor_sandbox"
6+
verbose_name = "Asciidoctor Sandbox"

asciidoctor_sandbox/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Asciidoctor Sandbox Configuration
2+
3+
# Number of days after which sandbox documents are eligible for cleanup
4+
ASCIIDOCTOR_SANDBOX_DOCUMENT_RETENTION_DAYS = 365

asciidoctor_sandbox/management/__init__.py

Whitespace-only changes.

asciidoctor_sandbox/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import djclick as click
2+
3+
from asciidoctor_sandbox.tasks import cleanup_old_sandbox_documents
4+
5+
6+
@click.command()
7+
def command():
8+
"""Clean up old sandbox documents based on the configured retention period."""
9+
click.echo("Starting sandbox document cleanup...")
10+
11+
# Run the task synchronously
12+
cleanup_old_sandbox_documents()
13+
14+
click.echo(
15+
click.style("Sandbox document cleanup completed successfully.", fg="green")
16+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Generated by Django 4.2.24 on 2025-09-22 22:54
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
import django.utils.timezone
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name="SandboxDocument",
20+
fields=[
21+
(
22+
"id",
23+
models.AutoField(
24+
auto_created=True,
25+
primary_key=True,
26+
serialize=False,
27+
verbose_name="ID",
28+
),
29+
),
30+
("title", models.CharField(help_text="Document title", max_length=200)),
31+
(
32+
"asciidoc_content",
33+
models.TextField(blank=True, help_text="Asciidoc source content"),
34+
),
35+
("created_at", models.DateTimeField(default=django.utils.timezone.now)),
36+
("updated_at", models.DateTimeField(auto_now=True)),
37+
(
38+
"created_by",
39+
models.ForeignKey(
40+
help_text="User who created this document",
41+
on_delete=django.db.models.deletion.CASCADE,
42+
to=settings.AUTH_USER_MODEL,
43+
),
44+
),
45+
],
46+
options={
47+
"ordering": ["-updated_at"],
48+
},
49+
),
50+
]

asciidoctor_sandbox/migrations/__init__.py

Whitespace-only changes.

asciidoctor_sandbox/models.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from django.db import models
2+
from django.utils import timezone
3+
from django.conf import settings
4+
5+
6+
class SandboxDocument(models.Model):
7+
"""Model to store asciidoctor sandbox documents."""
8+
9+
title = models.CharField(max_length=200, help_text="Document title")
10+
asciidoc_content = models.TextField(blank=True, help_text="Asciidoc source content")
11+
created_by = models.ForeignKey(
12+
settings.AUTH_USER_MODEL,
13+
on_delete=models.CASCADE,
14+
help_text="User who created this document",
15+
)
16+
created_at = models.DateTimeField(default=timezone.now)
17+
updated_at = models.DateTimeField(auto_now=True)
18+
19+
class Meta:
20+
ordering = ["-updated_at"]
21+
22+
def __str__(self):
23+
return self.title
24+
25+
def __repr__(self):
26+
return f"<{self.__class__.__name__} object ({self.pk}): {self}>"

0 commit comments

Comments
 (0)