-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-setup.sh
More file actions
executable file
Β·1241 lines (1093 loc) Β· 41.2 KB
/
dev-setup.sh
File metadata and controls
executable file
Β·1241 lines (1093 loc) Β· 41.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Development setup script for django-blocknote
set -e # Exit on any error
echo "π Setting up django-blocknote development environment..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}π¦ $1${NC}"
}
print_success() {
echo -e "${GREEN}β
$1${NC}"
}
print_warning() {
echo -e "${YELLOW}β οΈ $1${NC}"
}
print_error() {
echo -e "${RED}β $1${NC}"
}
# Check if we're in a virtual environment
if [[ "$VIRTUAL_ENV" == "" ]]; then
print_warning "Not in a virtual environment. Use the command below to Create and Activate or\n\tjust Activate an existing venv, then run setup again:"
echo "python3.13 -m venv venv && pip install --upgrade pip && source venv/bin/activate"
exit 1
fi
# Install Python dependencies in development mode
print_status "Installing Python dependencies..."
pip install -e . || {
print_error "Failed to install Python dependencies"
exit 1
}
# Install Node.js dependencies
print_status "Installing Node.js dependencies..."
cd frontend
npm install || {
print_error "Failed to install Node.js dependencies"
exit 1
}
cd ..
# Create demo project
print_status "Creating demo Django project..."
# Remove existing demo project if it exists
if [ -d "examples/demo_project" ]; then
print_warning "Removing existing demo project..."
rm -rf examples/demo_project
fi
# Create directory structure
mkdir -p examples/demo_project
cd examples/demo_project
# Create manage.py
cat > manage.py << 'MANAGE_EOF'
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
MANAGE_EOF
chmod +x manage.py
# Create demo project settings
mkdir -p demo
cat > demo/__init__.py << 'DEMO_INIT_EOF'
DEMO_INIT_EOF
cat > demo/settings.py << 'SETTINGS_EOF'
"""
Django settings for demo project.
This is for development of django-blocknote library.
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-demo-key-for-development-only'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# The batch size for image deletion from the database
DJ_BN_BULK_DELETE_BATCH_SIZE=2
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Our library (installed in development mode)
'django_blocknote',
# Demo app
'blog',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'demo.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'demo.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Internationalization
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
# Static files configuration for development
STATICFILES_DIRS = [
BASE_DIR / 'static', # Local demo static files
BASE_DIR.parent.parent / 'django_blocknote' / 'static', # Package static files
]
# Media files (for uploads)
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Django BlockNote Configuration
DJ_BN_MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
DJ_BN_UPLOAD_PATH = 'blocknote_uploads' # Directory within MEDIA_ROOT
# Allowed image types for upload
DJ_BN_ALLOWED_FILE_TYPES = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp'
]
# Allowed document types (for file uploads)
DJ_BN_ALLOWED_DOCUMENT_TYPES = [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'text/plain'
]
DJ_BN_IMAGE_UPLOAD_CONFIG = {
"uploadUrl": "/django-blocknote/upload-image/",
"maxFileSize": 10 * 1024 * 1024, # 10MB
"allowedTypes": ["image/*"],
"showProgress": False,
"maxConcurrent": 3,
"timeout": 30000,
"chunkSize": 1024 * 1024,
"retryAttempts": 3,
"retryDelay": 1000,
"img_model": "", # Optional: Django model for custom image handling
}
DJ_BN_IMAGE_REMOVAL_CONFIG = {
"removalUrl": "/django-blocknote/remove-image/",
"retryAttempts": 3,
"retryDelay": 1000,
"timeout": 30000,
"maxConcurrent": 1,
}
# Widget configuration
DJANGO_BLOCKNOTE = {
'DEFAULT_CONFIG': {
'placeholder': 'Start writing your amazing content...',
'theme': 'light',
'animations': True,
},
'WIDGET_CONFIG': {
'css_class': 'demo-blocknote-widget',
'include_css': True,
'include_js': True,
},
}
# Logging configuration for development
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'root': {
'handlers': ['console'],
'level': 'INFO',
},
'loggers': {
'django_blocknote': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
},
}
SETTINGS_EOF
cat > demo/urls.py << 'URLS_EOF'
"""demo URL Configuration"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
# BlockNote upload URLs
path('django-blocknote/', include('django_blocknote.urls')),
]
# Serve static and media files during development
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
URLS_EOF
cat > demo/wsgi.py << 'WSGI_EOF'
"""
WSGI config for demo project.
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings')
application = get_wsgi_application()
WSGI_EOF
# Create blog app
mkdir -p blog
mkdir -p blog/migrations
cat > blog/__init__.py << 'BLOG_INIT_EOF'
BLOG_INIT_EOF
cat > blog/migrations/__init__.py << 'MIGRATIONS_INIT_EOF'
MIGRATIONS_INIT_EOF
cat > blog/apps.py << 'APPS_EOF'
from django.apps import AppConfig
class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
APPS_EOF
cat > blog/models.py << 'MODELS_EOF'
from django.db import models
from django_blocknote.models.fields import BlockNoteField
class BlogPost(models.Model):
title = models.CharField(max_length=200)
content = BlockNoteField(
help_text="Main content of the blog post",
blank=True,
editor_config={
'placeholder': 'Write your blog post content here...',
'theme': 'light',
'animations': True,
},
image_upload_config={
'img_model': 'blog:BlogPost', # app:model format
'maxFileSize': 10 * 1024 * 1024, # 10MB
'allowedTypes': ['image/*']
},
image_removal_config={
'removalUrl': '/django-blocknote/remove-image/',
'retryAttempts': 3,
},
menu_type='admin',
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.title
class Comment(models.Model):
post = models.ForeignKey(BlogPost, on_delete=models.CASCADE, related_name='comments')
author = models.CharField(max_length=100)
content = BlockNoteField(
help_text="Comment content",
editor_config={
'placeholder': 'Write your comment...',
'theme': 'light',
},
image_upload_config={
'img_model': 'blog:Comment', # app:model format
'maxFileSize': 2 * 1024 * 1024, # 2MB for comments
'allowedTypes': ['image/jpeg', 'image/png', 'image/gif']
},
# menu_type='_default',
)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f'Comment by {self.author} on {self.post.title}'
MODELS_EOF
cat >> blog/models.py << 'TEST_MODELS_EOF'
# Test models for different upload configurations
class RestrictiveUploadTest(models.Model):
"""Model for testing restrictive upload settings"""
content = BlockNoteField(
editor_config={
'placeholder': 'Restrictive upload settings...',
'theme': 'light'
},
image_upload_config={
'img_model': 'blog:RestrictiveUploadTest',
'maxFileSize': 1 * 1024 * 1024, # 1MB only
'allowedTypes': ['image/jpeg'], # JPEG only
'showProgress': True,
'maxConcurrent': 1
}
)
class PermissiveUploadTest(models.Model):
"""Model for testing permissive upload settings"""
content = BlockNoteField(
editor_config={
'placeholder': 'Permissive upload settings...',
'theme': 'dark'
},
image_upload_config={
'img_model': 'blog:PermissiveUploadTest',
'maxFileSize': 20 * 1024 * 1024, # 20MB
'allowedTypes': ['image/*'], # All image types
'showProgress': True,
'maxConcurrent': 3
}
)
class NoUploadTest(models.Model):
"""Model for testing no upload configuration"""
content = BlockNoteField(
editor_config={
'placeholder': 'No uploads allowed in this editor...',
'theme': 'light'
},
image_upload_config={
'allowedTypes': [] # No uploads
}
)
TEST_MODELS_EOF
cat > blog/forms.py << 'FORMS_EOF'
from django import forms
from django_blocknote.forms.mixins import BlockNoteFormMixin, BlockNoteModelFormMixin
from .models import BlogPost, Comment
class BlogPostForm(BlockNoteModelFormMixin):
class Meta:
model = BlogPost
fields = ['title', 'content']
# No widget overrides - configuration comes from the model field
class CommentForm(BlockNoteModelFormMixin):
class Meta:
model = Comment
fields = ['author', 'content']
# No widget overrides - configuration comes from the model field
# Testing form with explicit widget configurations for various scenarios
class UploadTestForm(BlockNoteFormMixin):
"""Comprehensive form to test all upload configurations and edge cases"""
# Standard configuration
standard_editor = forms.CharField(
widget=forms.Textarea(), # Will be replaced by field formfield() method
label="Standard Editor (5MB, JPEG/PNG/WebP, Progress)",
help_text="Standard upload configuration with common image types",
required=False
)
# For testing, we can create custom fields or use explicit widget configs
# These would normally use custom BlockNoteField instances with different configs
# Multiple editors to test form validation
editor_1 = forms.CharField(
widget=forms.Textarea(),
label="Multi-Editor Test 1",
help_text="First editor in multi-editor form",
required=False
)
editor_2 = forms.CharField(
widget=forms.Textarea(),
label="Multi-Editor Test 2",
help_text="Second editor in multi-editor form",
required=False
)
editor_3 = forms.CharField(
widget=forms.Textarea(),
label="Multi-Editor Test 3",
help_text="Third editor in multi-editor form",
required=False
)
FORMS_EOF
cat > blog/views.py << 'VIEWS_EOF'
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib import messages
from django.views.generic import CreateView, UpdateView
from django_blocknote.views.mixins import BlockNoteViewMixin
from .models import BlogPost, Comment
from .forms import BlogPostForm, CommentForm, UploadTestForm
def post_list(request):
posts = BlogPost.objects.all()
return render(request, 'blog/post_list.html', {'posts': posts})
def post_detail(request, pk):
post = get_object_or_404(BlogPost, pk=pk)
comments = post.comments.all()
if request.method == 'POST':
comment_form = CommentForm(request.POST, user=request.user)
if comment_form.is_valid():
comment = comment_form.save(commit=False)
comment.post = post
comment.save()
messages.success(request, 'Comment added successfully!')
return redirect('post_detail', pk=pk)
else:
comment_form = CommentForm(user=request.user)
return render(request, 'blog/post_detail.html', {
'post': post,
'comments': comments,
'comment_form': comment_form,
})
# Class-based views using the mixin
class PostCreateView(BlockNoteViewMixin, CreateView):
model = BlogPost
form_class = BlogPostForm
template_name = 'blog/post_form.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Create New Post'
return context
def form_valid(self, form):
messages.success(self.request, 'Blog post created successfully!')
return super().form_valid(form)
def get_success_url(self):
return f'/post/{self.object.pk}/'
class PostUpdateView(BlockNoteViewMixin, UpdateView):
model = BlogPost
form_class = BlogPostForm
template_name = 'blog/post_form.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'Edit Post'
return context
def form_valid(self, form):
messages.success(self.request, 'Blog post updated successfully!')
return super().form_valid(form)
def get_success_url(self):
return f'/post/{self.object.pk}/'
# Function-based view for backwards compatibility
def post_create(request):
if request.method == 'POST':
form = BlogPostForm(request.POST, user=request.user)
if form.is_valid():
post = form.save()
messages.success(request, 'Blog post created successfully!')
return redirect('post_detail', pk=post.pk)
else:
form = BlogPostForm(user=request.user)
return render(request, 'blog/post_form.html', {
'form': form,
'title': 'Create New Post'
})
def post_edit(request, pk):
post = get_object_or_404(BlogPost, pk=pk)
if request.method == 'POST':
form = BlogPostForm(request.POST, instance=post, user=request.user)
if form.is_valid():
form.save()
messages.success(request, 'Blog post updated successfully!')
return redirect('post_detail', pk=pk)
else:
form = BlogPostForm(instance=post, user=request.user)
return render(request, 'blog/post_form.html', {
'form': form,
'post': post,
'title': 'Edit Post'
})
def upload_test(request):
"""Comprehensive test page for upload configurations and edge cases"""
if request.method == 'POST':
form = UploadTestForm(request.POST, user=request.user)
if form.is_valid():
messages.success(request, 'Upload test form submitted successfully! All editors passed validation.')
# In a real app, you'd process the form data here
return redirect('upload_test')
else:
form = UploadTestForm(user=request.user)
return render(request, 'blog/upload_test.html', {
'form': form,
'title': 'Upload Configuration Testing'
})
VIEWS_EOF
cat > blog/urls.py << 'BLOG_URLS_EOF'
from django.urls import path
from . import views
urlpatterns = [
path('', views.post_list, name='post_list'),
path('post/<int:pk>/', views.post_detail, name='post_detail'),
# Use class-based views with mixins
path('post/new/', views.PostCreateView.as_view(), name='post_create'),
path('post/<int:pk>/edit/', views.PostUpdateView.as_view(), name='post_edit'),
# Keep function-based versions for testing
path('post/new-func/', views.post_create, name='post_create_func'),
path('post/<int:pk>/edit-func/', views.post_edit, name='post_edit_func'),
path('upload-test/', views.upload_test, name='upload_test'),
]
BLOG_URLS_EOF
cat > blog/admin.py << 'ADMIN_EOF'
from django.contrib import admin
from .models import BlogPost, Comment
@admin.register(BlogPost)
class BlogPostAdmin(admin.ModelAdmin):
list_display = ['title', 'created_at', 'updated_at']
search_fields = ['title']
list_filter = ['created_at', 'updated_at']
@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ['author', 'post', 'created_at']
list_filter = ['created_at']
search_fields = ['author', 'content']
ADMIN_EOF
# Create templates
mkdir -p templates/blog
# Updated base template with integrated validation
cat > templates/base.html << 'BASE_TEMPLATE_EOF'
{% load blocknote_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Django BlockNote Demo{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.demo-blocknote-widget {
border: 2px dashed #007cba !important;
}
.navbar-brand {
font-weight: bold;
}
.upload-info {
font-size: 0.875rem;
color: #6c757d;
margin-top: 0.25rem;
}
.feature-badge {
display: inline-block;
padding: 0.25rem 0.5rem;
margin: 0.125rem;
background: #e3f2fd;
color: #1565c0;
border-radius: 0.25rem;
font-size: 0.75rem;
font-weight: 500;
}
</style>
{% blocknote_full %}
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="{% url 'post_list' %}">Django BlockNote Demo</a>
<div class="navbar-nav ms-auto">
<a class="nav-link" href="{% url 'post_create' %}">New Post</a>
<a class="nav-link" href="{% url 'upload_test' %}">Upload Testing</a>
<a class="nav-link" href="/admin/">Admin</a>
</div>
</div>
</nav>
<div class="container mt-4">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
{% block content %}
{% endblock %}
</div>
{% blocknote_asset_debug %}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
BASE_TEMPLATE_EOF
# Simple post list template
cat > templates/blog/post_list.html << 'POST_LIST_EOF'
{% extends 'base.html' %}
{% load blocknote_tags %}
{% block title %}Blog Posts - Django BlockNote Demo{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Blog Posts</h1>
<a href="{% url 'post_create' %}" class="btn btn-primary">New Post</a>
</div>
<div class="row">
{% for post in posts %}
<div class="col-md-6 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ post.title }}</h5>
{% if post.content %}
<div class="card-text">
{% blocknote_viewer post.content %}
</div>
{% endif %}
<p class="text-muted small">{{ post.created_at|date:"F d, Y" }}</p>
<div class="d-flex gap-2">
<a href="{% url 'post_detail' post.pk %}" class="btn btn-outline-primary btn-sm">View</a>
<a href="{% url 'post_edit' post.pk %}" class="btn btn-outline-secondary btn-sm">Edit</a>
</div>
</div>
</div>
</div>
{% empty %}
<div class="col-12">
<div class="alert alert-info">
<h4>Welcome to Django BlockNote! π</h4>
<p>Start by <a href="{% url 'post_create' %}">creating your first blog post</a> to see the BlockNote editor in action.</p>
<p>Or explore the <a href="{% url 'upload_test' %}">upload testing page</a> to see different configuration options.</p>
</div>
</div>
{% endfor %}
</div>
{% endblock %}
POST_LIST_EOF
# Simple post detail template
cat > templates/blog/post_detail.html << 'POST_DETAIL_EOF'
{% extends 'base.html' %}
{% load blocknote_tags %}
{% block title %}{{ post.title }} - Django BlockNote Demo{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-8">
<article>
<h1>{{ post.title }}</h1>
<p class="text-muted">{{ post.created_at|date:"F d, Y" }}</p>
<div class="mt-4">
{% blocknote_viewer post.content %}
</div>
<div class="mt-4">
<a href="{% url 'post_edit' post.pk %}" class="btn btn-outline-primary">Edit Post</a>
<a href="{% url 'post_list' %}" class="btn btn-outline-secondary">Back to List</a>
</div>
</article>
<hr class="my-5">
<section>
<h3>Comments</h3>
<form method="post" class="mb-4">
{% csrf_token %}
<div class="mb-3">
<label for="{{ comment_form.author.id_for_label }}" class="form-label">Name</label>
{{ comment_form.author }}
</div>
<div class="mb-3">
<label for="{{ comment_form.content.id_for_label }}" class="form-label">Comment</label>
<div class="upload-info">π‘ You can upload images (max 2MB, JPEG/PNG/GIF)</div>
{{ comment_form.content }}
</div>
<button type="submit" class="btn btn-primary">Add Comment</button>
</form>
<div class="comments">
{% for comment in comments %}
<div class="card mb-3">
<div class="card-body">
<h6 class="card-title">{{ comment.author }}</h6>
<p class="text-muted small">{{ comment.created_at|date:"F d, Y g:i A" }}</p>
<div>{% blocknote_viewer comment.content %}</div>
</div>
</div>
{% empty %}
<p class="text-muted">No comments yet. Be the first to comment!</p>
{% endfor %}
</div>
</section>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h5>About This Demo</h5>
</div>
<div class="card-body">
<p><strong>This demo shows:</strong></p>
<ul class="small">
<li>π Simple blog post creation</li>
<li>ποΈ Read-only content viewing</li>
<li>π¬ Comment system with uploads</li>
<li>π Form validation (multi-editor)</li>
</ul>
<div class="mt-3">
<a href="{% url 'upload_test' %}" class="btn btn-sm btn-outline-primary">
Advanced Upload Testing
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
POST_DETAIL_EOF
# Simple post form template
cat > templates/blog/post_form.html << 'POST_FORM_EOF'
{% extends 'base.html' %}
{% block title %}{{ title }} - Django BlockNote Demo{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-8">
<h1>{{ title }}</h1>
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label for="{{ form.title.id_for_label }}" class="form-label">Title</label>
{{ form.title }}
{% if form.title.errors %}
<div class="text-danger small">{{ form.title.errors }}</div>
{% endif %}
</div>
<div class="mb-3">
<label for="{{ form.content.id_for_label }}" class="form-label">Content</label>
<div class="form-text">{{ form.content.help_text }}</div>
<div class="upload-info">π‘ Upload: max 10MB, all image types supported</div>
{{ form.content }}
{% if form.content.errors %}
<div class="text-danger small">{{ form.content.errors }}</div>
{% endif %}
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary">Save Post</button>
<a href="{% url 'post_list' %}" class="btn btn-outline-secondary">Cancel</a>
</div>
</form>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h5>Simple Post Creation</h5>
</div>
<div class="card-body">
<p>This is a clean, simple blog post form with:</p>
<ul class="small">
<li>π Rich text editing</li>
<li>πΈ Image uploads (10MB limit)</li>
<li>β
Automatic form validation</li>
<li>ποΈ Read-only viewing after save</li>
</ul>
<div class="mt-3">
<p class="small text-muted">
For advanced upload testing and multiple editor configurations,
visit the <a href="{% url 'upload_test' %}">Upload Testing page</a>.
</p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
POST_FORM_EOF
# Comprehensive upload test template with all the bells and whistles
cat > templates/blog/upload_test.html << 'UPLOAD_TEST_EOF'
{% extends 'base.html' %}
{% block title %}{{ title }} - Django BlockNote Demo{% endblock %}
{% block content %}
<div class="row">
<div class="col-12">
<h1>{{ title }}</h1>
<p class="lead">Comprehensive testing of upload configurations, validation, and edge cases.</p>
<div class="alert alert-info">
<h5>π§ͺ What This Page Tests</h5>
<div class="row">
<div class="col-md-6">
<span class="feature-badge">Multi-Editor Forms</span>
<span class="feature-badge">JSON Validation</span>
<span class="feature-badge">Theme Variations</span>
<span class="feature-badge">Error Handling</span>
</div>
</div>
</div>
<form method="post">
{% csrf_token %}
<!-- Standard Editor -->
<div class="card mb-4">
<div class="card-header">
<h5>π Standard Configuration</h5>
</div>
<div class="card-body">
<label for="{{ form.standard_editor.id_for_label }}" class="form-label">
{{ form.standard_editor.label }}
</label>
<div class="upload-info">{{ form.standard_editor.help_text }}</div>
{{ form.standard_editor }}
</div>
</div>
<!-- Restrictive Editor -->
<div class="card mb-4">
<div class="card-header">
<h5>π Restrictive Configuration</h5>
</div>
<div class="card-body">
<label for="{{ form.restrictive_editor.id_for_label }}" class="form-label">
{{ form.restrictive_editor.label }}
</label>
<div class="upload-info">{{ form.restrictive_editor.help_text }}</div>
{{ form.restrictive_editor }}
</div>
</div>
<!-- Permissive Editor -->
<div class="card mb-4">
<div class="card-header">
<h5>π Permissive Configuration</h5>
</div>
<div class="card-body">
<label for="{{ form.permissive_editor.id_for_label }}" class="form-label">
{{ form.permissive_editor.label }}
</label>
<div class="upload-info">{{ form.permissive_editor.help_text }}</div>
{{ form.permissive_editor }}
</div>
</div>
<!-- No Upload Editor -->
<div class="card mb-4">
<div class="card-header">
<h5>π« No Upload Configuration</h5>
</div>
<div class="card-body">
<label for="{{ form.no_upload_editor.id_for_label }}" class="form-label">
{{ form.no_upload_editor.label }}
</label>
<div class="upload-info">{{ form.no_upload_editor.help_text }}</div>
{{ form.no_upload_editor }}
</div>
</div>
<!-- Multi-Editor Validation Test -->
<div class="card mb-4">
<div class="card-header">
<h5>π Multi-Editor Form Validation Test</h5>
</div>
<div class="card-body">
<p class="text-muted mb-3">Test the automatic JSON validation with multiple editors. Try editing only one and submitting the form.</p>
<div class="row">
<div class="col-md-4 mb-3">
<label for="{{ form.editor_1.id_for_label }}" class="form-label">
{{ form.editor_1.label }}
</label>
<div class="upload-info">{{ form.editor_1.help_text }}</div>
{{ form.editor_1 }}
</div>
<div class="col-md-4 mb-3">
<label for="{{ form.editor_2.id_for_label }}" class="form-label">
{{ form.editor_2.label }}
</label>
<div class="upload-info">{{ form.editor_2.help_text }}</div>
{{ form.editor_2 }}
</div>
<div class="col-md-4 mb-3">
<label for="{{ form.editor_3.id_for_label }}" class="form-label">
{{ form.editor_3.label }}
</label>
<div class="upload-info">{{ form.editor_3.help_text }}</div>
{{ form.editor_3 }}
</div>
</div>