claude-code-templates 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +7 -7
  2. package/bin/create-claude-config.js +17 -8
  3. package/package.json +2 -3
  4. package/src/analytics/core/AgentAnalyzer.js +17 -3
  5. package/src/analytics/core/ProcessDetector.js +23 -7
  6. package/src/analytics/core/StateCalculator.js +102 -33
  7. package/src/analytics/data/DataCache.js +7 -7
  8. package/src/analytics-web/chats_mobile.html +2590 -0
  9. package/src/analytics-web/components/App.js +10 -10
  10. package/src/analytics-web/components/SessionTimer.js +1 -1
  11. package/src/analytics-web/components/Sidebar.js +5 -14
  12. package/src/analytics-web/index.html +932 -78
  13. package/src/analytics.js +263 -5
  14. package/src/chats-mobile.js +682 -0
  15. package/src/claude-api-proxy.js +460 -0
  16. package/src/file-operations.js +239 -36
  17. package/src/health-check.js +310 -0
  18. package/src/index.js +1252 -56
  19. package/src/tracking-service.js +31 -34
  20. package/components/agents/api-security-audit.md +0 -92
  21. package/components/agents/database-optimization.md +0 -94
  22. package/components/agents/react-performance-optimization.md +0 -64
  23. package/components/commands/check-file.md +0 -53
  24. package/components/commands/generate-tests.md +0 -68
  25. package/components/mcps/deepgraph-nextjs.json +0 -12
  26. package/components/mcps/deepgraph-react.json +0 -12
  27. package/components/mcps/deepgraph-typescript.json +0 -12
  28. package/components/mcps/deepgraph-vue.json +0 -12
  29. package/components/mcps/filesystem-access.json +0 -12
  30. package/components/mcps/github-integration.json +0 -11
  31. package/components/mcps/memory-integration.json +0 -8
  32. package/components/mcps/mysql-integration.json +0 -11
  33. package/components/mcps/postgresql-integration.json +0 -11
  34. package/components/mcps/web-fetch.json +0 -8
  35. package/src/analytics-web/components/AgentsPage.js +0 -4761
  36. package/templates/common/.claude/commands/git-workflow.md +0 -239
  37. package/templates/common/.claude/commands/project-setup.md +0 -316
  38. package/templates/common/.mcp.json +0 -41
  39. package/templates/common/CLAUDE.md +0 -109
  40. package/templates/common/README.md +0 -96
  41. package/templates/go/.mcp.json +0 -78
  42. package/templates/go/README.md +0 -25
  43. package/templates/javascript-typescript/.claude/commands/api-endpoint.md +0 -51
  44. package/templates/javascript-typescript/.claude/commands/debug.md +0 -52
  45. package/templates/javascript-typescript/.claude/commands/lint.md +0 -48
  46. package/templates/javascript-typescript/.claude/commands/npm-scripts.md +0 -48
  47. package/templates/javascript-typescript/.claude/commands/refactor.md +0 -55
  48. package/templates/javascript-typescript/.claude/commands/test.md +0 -61
  49. package/templates/javascript-typescript/.claude/commands/typescript-migrate.md +0 -51
  50. package/templates/javascript-typescript/.claude/settings.json +0 -142
  51. package/templates/javascript-typescript/.mcp.json +0 -80
  52. package/templates/javascript-typescript/CLAUDE.md +0 -185
  53. package/templates/javascript-typescript/README.md +0 -259
  54. package/templates/javascript-typescript/examples/angular-app/.claude/commands/components.md +0 -63
  55. package/templates/javascript-typescript/examples/angular-app/.claude/commands/services.md +0 -62
  56. package/templates/javascript-typescript/examples/node-api/.claude/commands/api-endpoint.md +0 -46
  57. package/templates/javascript-typescript/examples/node-api/.claude/commands/database.md +0 -56
  58. package/templates/javascript-typescript/examples/node-api/.claude/commands/middleware.md +0 -61
  59. package/templates/javascript-typescript/examples/node-api/.claude/commands/route.md +0 -57
  60. package/templates/javascript-typescript/examples/node-api/CLAUDE.md +0 -102
  61. package/templates/javascript-typescript/examples/react-app/.claude/commands/component.md +0 -29
  62. package/templates/javascript-typescript/examples/react-app/.claude/commands/hooks.md +0 -44
  63. package/templates/javascript-typescript/examples/react-app/.claude/commands/state-management.md +0 -45
  64. package/templates/javascript-typescript/examples/react-app/CLAUDE.md +0 -81
  65. package/templates/javascript-typescript/examples/react-app/agents/react-performance-optimization.md +0 -530
  66. package/templates/javascript-typescript/examples/react-app/agents/react-state-management.md +0 -295
  67. package/templates/javascript-typescript/examples/vue-app/.claude/commands/components.md +0 -46
  68. package/templates/javascript-typescript/examples/vue-app/.claude/commands/composables.md +0 -51
  69. package/templates/python/.claude/commands/lint.md +0 -111
  70. package/templates/python/.claude/commands/test.md +0 -73
  71. package/templates/python/.claude/settings.json +0 -153
  72. package/templates/python/.mcp.json +0 -78
  73. package/templates/python/CLAUDE.md +0 -276
  74. package/templates/python/examples/django-app/.claude/commands/admin.md +0 -264
  75. package/templates/python/examples/django-app/.claude/commands/django-model.md +0 -124
  76. package/templates/python/examples/django-app/.claude/commands/views.md +0 -222
  77. package/templates/python/examples/django-app/CLAUDE.md +0 -313
  78. package/templates/python/examples/django-app/agents/django-api-security.md +0 -642
  79. package/templates/python/examples/django-app/agents/django-database-optimization.md +0 -752
  80. package/templates/python/examples/fastapi-app/.claude/commands/api-endpoints.md +0 -513
  81. package/templates/python/examples/fastapi-app/.claude/commands/auth.md +0 -775
  82. package/templates/python/examples/fastapi-app/.claude/commands/database.md +0 -657
  83. package/templates/python/examples/fastapi-app/.claude/commands/deployment.md +0 -160
  84. package/templates/python/examples/fastapi-app/.claude/commands/testing.md +0 -927
  85. package/templates/python/examples/fastapi-app/CLAUDE.md +0 -229
  86. package/templates/python/examples/flask-app/.claude/commands/app-factory.md +0 -384
  87. package/templates/python/examples/flask-app/.claude/commands/blueprint.md +0 -243
  88. package/templates/python/examples/flask-app/.claude/commands/database.md +0 -410
  89. package/templates/python/examples/flask-app/.claude/commands/deployment.md +0 -620
  90. package/templates/python/examples/flask-app/.claude/commands/flask-route.md +0 -217
  91. package/templates/python/examples/flask-app/.claude/commands/testing.md +0 -559
  92. package/templates/python/examples/flask-app/CLAUDE.md +0 -391
  93. package/templates/ruby/.claude/commands/model.md +0 -360
  94. package/templates/ruby/.claude/commands/test.md +0 -480
  95. package/templates/ruby/.claude/settings.json +0 -146
  96. package/templates/ruby/.mcp.json +0 -83
  97. package/templates/ruby/CLAUDE.md +0 -284
  98. package/templates/ruby/examples/rails-app/.claude/commands/authentication.md +0 -490
  99. package/templates/ruby/examples/rails-app/CLAUDE.md +0 -376
  100. package/templates/rust/.mcp.json +0 -78
  101. package/templates/rust/README.md +0 -26
@@ -1,264 +0,0 @@
1
- # Django Admin Configuration
2
-
3
- Configure Django admin interface with custom admin classes and functionality.
4
-
5
- ## Purpose
6
-
7
- This command helps you create comprehensive Django admin configurations with advanced features and customizations.
8
-
9
- ## Usage
10
-
11
- ```
12
- /admin
13
- ```
14
-
15
- ## What this command does
16
-
17
- 1. **Registers models** with custom admin classes
18
- 2. **Creates advanced admin interfaces** with filtering, search, and actions
19
- 3. **Adds inline editing** for related models
20
- 4. **Customizes list displays** and forms
21
- 5. **Implements admin actions** for bulk operations
22
-
23
- ## Example Output
24
-
25
- ```python
26
- # admin.py
27
- from django.contrib import admin
28
- from django.utils.html import format_html
29
- from django.urls import reverse
30
- from django.utils.safestring import mark_safe
31
- from .models import Post, Category, Tag, Comment
32
-
33
- @admin.register(Category)
34
- class CategoryAdmin(admin.ModelAdmin):
35
- """Admin configuration for Category model."""
36
- list_display = ['name', 'slug', 'post_count', 'created_at']
37
- list_filter = ['created_at']
38
- search_fields = ['name', 'description']
39
- prepopulated_fields = {'slug': ('name',)}
40
- readonly_fields = ['created_at', 'updated_at']
41
-
42
- def post_count(self, obj):
43
- """Display number of posts in this category."""
44
- count = obj.posts.count()
45
- url = reverse('admin:blog_post_changelist') + f'?category__id__exact={obj.id}'
46
- return format_html('<a href="{}">{} posts</a>', url, count)
47
- post_count.short_description = 'Posts'
48
-
49
- class CommentInline(admin.TabularInline):
50
- """Inline admin for comments."""
51
- model = Comment
52
- extra = 0
53
- readonly_fields = ['created_at', 'author']
54
- fields = ['author', 'content', 'is_approved', 'created_at']
55
-
56
- @admin.register(Post)
57
- class PostAdmin(admin.ModelAdmin):
58
- """Advanced admin configuration for Post model."""
59
- list_display = [
60
- 'title',
61
- 'author',
62
- 'category',
63
- 'status',
64
- 'view_count',
65
- 'created_at',
66
- 'post_preview'
67
- ]
68
- list_filter = [
69
- 'status',
70
- 'category',
71
- 'created_at',
72
- 'updated_at',
73
- ('author', admin.RelatedOnlyFieldListFilter)
74
- ]
75
- search_fields = ['title', 'content', 'author__username']
76
- prepopulated_fields = {'slug': ('title',)}
77
- readonly_fields = ['created_at', 'updated_at', 'view_count', 'post_preview']
78
-
79
- # Custom form layout
80
- fieldsets = (
81
- ('Content', {
82
- 'fields': ('title', 'slug', 'content', 'status')
83
- }),
84
- ('Metadata', {
85
- 'fields': ('author', 'category', 'tags'),
86
- 'classes': ('collapse',)
87
- }),
88
- ('SEO', {
89
- 'fields': ('meta_description', 'meta_keywords'),
90
- 'classes': ('collapse',)
91
- }),
92
- ('Timestamps', {
93
- 'fields': ('created_at', 'updated_at', 'view_count'),
94
- 'classes': ('collapse',)
95
- }),
96
- )
97
-
98
- # Many-to-many field display
99
- filter_horizontal = ['tags']
100
-
101
- # Inline models
102
- inlines = [CommentInline]
103
-
104
- # Custom list display methods
105
- def post_preview(self, obj):
106
- """Show thumbnail preview of post."""
107
- if obj.featured_image:
108
- return format_html(
109
- '<img src="{}" width="50" height="50" style="border-radius: 5px;" />',
110
- obj.featured_image.url
111
- )
112
- return "No image"
113
- post_preview.short_description = 'Preview'
114
-
115
- # Custom admin actions
116
- actions = ['make_published', 'make_draft', 'duplicate_posts']
117
-
118
- def make_published(self, request, queryset):
119
- """Bulk action to publish selected posts."""
120
- updated = queryset.update(status='published')
121
- self.message_user(
122
- request,
123
- f'{updated} posts were successfully marked as published.'
124
- )
125
- make_published.short_description = "Mark selected posts as published"
126
-
127
- def make_draft(self, request, queryset):
128
- """Bulk action to set selected posts as draft."""
129
- updated = queryset.update(status='draft')
130
- self.message_user(
131
- request,
132
- f'{updated} posts were successfully marked as draft.'
133
- )
134
- make_draft.short_description = "Mark selected posts as draft"
135
-
136
- def duplicate_posts(self, request, queryset):
137
- """Bulk action to duplicate selected posts."""
138
- count = 0
139
- for post in queryset:
140
- post.pk = None # Create new instance
141
- post.title = f"Copy of {post.title}"
142
- post.slug = f"copy-of-{post.slug}"
143
- post.status = 'draft'
144
- post.save()
145
- count += 1
146
-
147
- self.message_user(
148
- request,
149
- f'{count} posts were successfully duplicated.'
150
- )
151
- duplicate_posts.short_description = "Duplicate selected posts"
152
-
153
- @admin.register(Tag)
154
- class TagAdmin(admin.ModelAdmin):
155
- """Admin configuration for Tag model."""
156
- list_display = ['name', 'slug', 'post_count', 'color_preview']
157
- search_fields = ['name']
158
- prepopulated_fields = {'slug': ('name',)}
159
-
160
- def post_count(self, obj):
161
- """Display number of posts with this tag."""
162
- return obj.posts.count()
163
- post_count.short_description = 'Posts'
164
-
165
- def color_preview(self, obj):
166
- """Show color preview if tag has color field."""
167
- if hasattr(obj, 'color') and obj.color:
168
- return format_html(
169
- '<span style="background-color: {}; padding: 2px 8px; border-radius: 3px; color: white;">{}</span>',
170
- obj.color,
171
- obj.name
172
- )
173
- return obj.name
174
- color_preview.short_description = 'Preview'
175
-
176
- @admin.register(Comment)
177
- class CommentAdmin(admin.ModelAdmin):
178
- """Admin configuration for Comment model."""
179
- list_display = ['author', 'post', 'content_preview', 'is_approved', 'created_at']
180
- list_filter = ['is_approved', 'created_at', 'post__category']
181
- search_fields = ['content', 'author__username', 'post__title']
182
- readonly_fields = ['created_at', 'updated_at']
183
- actions = ['approve_comments', 'disapprove_comments']
184
-
185
- def content_preview(self, obj):
186
- """Show truncated content preview."""
187
- return obj.content[:50] + "..." if len(obj.content) > 50 else obj.content
188
- content_preview.short_description = 'Content'
189
-
190
- def approve_comments(self, request, queryset):
191
- """Bulk approve comments."""
192
- updated = queryset.update(is_approved=True)
193
- self.message_user(request, f'{updated} comments were approved.')
194
- approve_comments.short_description = "Approve selected comments"
195
-
196
- def disapprove_comments(self, request, queryset):
197
- """Bulk disapprove comments."""
198
- updated = queryset.update(is_approved=False)
199
- self.message_user(request, f'{updated} comments were disapproved.')
200
- disapprove_comments.short_description = "Disapprove selected comments"
201
-
202
- # Custom admin site configuration
203
- admin.site.site_header = "Blog Administration"
204
- admin.site.site_title = "Blog Admin Portal"
205
- admin.site.index_title = "Welcome to Blog Administration"
206
- ```
207
-
208
- ## Advanced Features
209
-
210
- ### Custom List Display
211
- - **Thumbnail previews** for images
212
- - **Related object counts** with links
213
- - **Status indicators** with colors
214
- - **Custom formatting** for data display
215
-
216
- ### Filtering and Search
217
- - **Advanced filters** including date ranges
218
- - **Related field filtering** for foreign keys
219
- - **Search across multiple fields** including relations
220
- - **Custom filter classes** for complex queries
221
-
222
- ### Inline Editing
223
- - **TabularInline** for compact editing
224
- - **StackedInline** for detailed forms
225
- - **Custom inline forms** with additional functionality
226
- - **Readonly fields** in inlines
227
-
228
- ### Bulk Actions
229
- - **Status changes** for multiple objects
230
- - **Data export** functionality
231
- - **Batch operations** for efficiency
232
- - **Custom business logic** in actions
233
-
234
- ### Form Customization
235
- - **Fieldsets** for organized layouts
236
- - **Collapsed sections** for advanced options
237
- - **Custom widgets** for better UX
238
- - **Validation** and error handling
239
-
240
- ## Security Considerations
241
-
242
- - **Permission checks** in custom methods
243
- - **Input sanitization** in admin actions
244
- - **CSRF protection** (automatic)
245
- - **User authentication** (built-in)
246
-
247
- ## Performance Optimization
248
-
249
- ```python
250
- # Optimize queries with select_related/prefetch_related
251
- class PostAdmin(admin.ModelAdmin):
252
- def get_queryset(self, request):
253
- queryset = super().get_queryset(request)
254
- return queryset.select_related('author', 'category').prefetch_related('tags')
255
- ```
256
-
257
- ## Custom Admin Templates
258
-
259
- ```python
260
- # Override admin templates
261
- class PostAdmin(admin.ModelAdmin):
262
- change_form_template = 'admin/blog/post/change_form.html'
263
- change_list_template = 'admin/blog/post/change_list.html'
264
- ```
@@ -1,124 +0,0 @@
1
- # Django Model Generator
2
-
3
- Create Django models with proper structure and relationships.
4
-
5
- ## Purpose
6
-
7
- This command helps you quickly create Django models with fields, relationships, and best practices.
8
-
9
- ## Usage
10
-
11
- ```
12
- /django-model
13
- ```
14
-
15
- ## What this command does
16
-
17
- 1. **Creates model classes** with proper field definitions
18
- 2. **Adds relationships** (ForeignKey, ManyToMany, OneToOne)
19
- 3. **Includes meta options** and model methods
20
- 4. **Generates migrations** automatically
21
- 5. **Follows Django conventions** and best practices
22
-
23
- ## Example Output
24
-
25
- ```python
26
- # models.py
27
- from django.db import models
28
- from django.contrib.auth.models import User
29
-
30
- class Category(models.Model):
31
- name = models.CharField(max_length=100, unique=True)
32
- slug = models.SlugField(unique=True)
33
- description = models.TextField(blank=True)
34
- created_at = models.DateTimeField(auto_now_add=True)
35
- updated_at = models.DateTimeField(auto_now=True)
36
-
37
- class Meta:
38
- verbose_name_plural = "categories"
39
- ordering = ['name']
40
-
41
- def __str__(self):
42
- return self.name
43
-
44
- class Post(models.Model):
45
- STATUS_CHOICES = [
46
- ('draft', 'Draft'),
47
- ('published', 'Published'),
48
- ('archived', 'Archived'),
49
- ]
50
-
51
- title = models.CharField(max_length=200)
52
- slug = models.SlugField(unique=True)
53
- content = models.TextField()
54
- status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='draft')
55
- author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')
56
- category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True)
57
- tags = models.ManyToManyField('Tag', blank=True)
58
- created_at = models.DateTimeField(auto_now_add=True)
59
- updated_at = models.DateTimeField(auto_now=True)
60
-
61
- class Meta:
62
- ordering = ['-created_at']
63
- verbose_name = 'blog post'
64
- verbose_name_plural = 'blog posts'
65
-
66
- def __str__(self):
67
- return self.title
68
-
69
- def get_absolute_url(self):
70
- return reverse('post_detail', kwargs={'slug': self.slug})
71
-
72
- class Tag(models.Model):
73
- name = models.CharField(max_length=50, unique=True)
74
- slug = models.SlugField(unique=True)
75
-
76
- def __str__(self):
77
- return self.name
78
- ```
79
-
80
- ## Field Types Supported
81
-
82
- - **CharField** - Text fields with max length
83
- - **TextField** - Large text fields
84
- - **IntegerField** - Integer numbers
85
- - **FloatField** - Floating point numbers
86
- - **BooleanField** - True/False values
87
- - **DateField** - Date only
88
- - **DateTimeField** - Date and time
89
- - **EmailField** - Email addresses
90
- - **URLField** - URLs
91
- - **ImageField** - Image uploads
92
- - **FileField** - File uploads
93
- - **JSONField** - JSON data (PostgreSQL)
94
-
95
- ## Relationships
96
-
97
- - **ForeignKey** - One-to-many relationships
98
- - **ManyToManyField** - Many-to-many relationships
99
- - **OneToOneField** - One-to-one relationships
100
-
101
- ## Best Practices Included
102
-
103
- - Proper field choices and defaults
104
- - Appropriate related_name attributes
105
- - __str__ methods for admin interface
106
- - Meta class with ordering and verbose names
107
- - get_absolute_url methods where appropriate
108
- - Proper use of null and blank parameters
109
- - Field validation and constraints
110
-
111
- ## After Creating Models
112
-
113
- ```bash
114
- # Create and apply migrations
115
- python manage.py makemigrations
116
- python manage.py migrate
117
-
118
- # Register in admin (optional)
119
- # Add to admin.py:
120
- from django.contrib import admin
121
- from .models import Post, Category, Tag
122
-
123
- admin.site.register([Post, Category, Tag])
124
- ```
@@ -1,222 +0,0 @@
1
- # Django Views Generator
2
-
3
- Create Django views with proper structure and best practices.
4
-
5
- ## Purpose
6
-
7
- This command helps you quickly create Django views (Function-Based Views and Class-Based Views) following Django conventions.
8
-
9
- ## Usage
10
-
11
- ```
12
- /views
13
- ```
14
-
15
- ## What this command does
16
-
17
- 1. **Creates view functions/classes** with proper structure
18
- 2. **Handles HTTP methods** (GET, POST, PUT, DELETE)
19
- 3. **Includes form handling** and validation
20
- 4. **Adds authentication/authorization** checks
21
- 5. **Follows Django best practices** and security guidelines
22
-
23
- ## Example Output
24
-
25
- ```python
26
- # views.py
27
- from django.shortcuts import render, get_object_or_404, redirect
28
- from django.contrib.auth.decorators import login_required
29
- from django.contrib import messages
30
- from django.http import JsonResponse
31
- from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
32
- from django.contrib.auth.mixins import LoginRequiredMixin
33
- from django.urls import reverse_lazy
34
- from .models import Post, Category
35
- from .forms import PostForm
36
-
37
- # Function-Based Views
38
- def post_list(request):
39
- """Display list of posts with pagination and filtering."""
40
- posts = Post.objects.filter(status='published').select_related('author', 'category')
41
-
42
- # Search functionality
43
- search_query = request.GET.get('search')
44
- if search_query:
45
- posts = posts.filter(title__icontains=search_query)
46
-
47
- # Category filtering
48
- category_id = request.GET.get('category')
49
- if category_id:
50
- posts = posts.filter(category_id=category_id)
51
-
52
- context = {
53
- 'posts': posts,
54
- 'categories': Category.objects.all(),
55
- 'search_query': search_query,
56
- }
57
- return render(request, 'blog/post_list.html', context)
58
-
59
- def post_detail(request, slug):
60
- """Display individual post details."""
61
- post = get_object_or_404(Post, slug=slug, status='published')
62
-
63
- context = {
64
- 'post': post,
65
- 'related_posts': Post.objects.filter(
66
- category=post.category,
67
- status='published'
68
- ).exclude(id=post.id)[:3]
69
- }
70
- return render(request, 'blog/post_detail.html', context)
71
-
72
- @login_required
73
- def post_create(request):
74
- """Create new post."""
75
- if request.method == 'POST':
76
- form = PostForm(request.POST, request.FILES)
77
- if form.is_valid():
78
- post = form.save(commit=False)
79
- post.author = request.user
80
- post.save()
81
- form.save_m2m() # Save many-to-many relationships
82
- messages.success(request, 'Post created successfully!')
83
- return redirect('post_detail', slug=post.slug)
84
- else:
85
- form = PostForm()
86
-
87
- return render(request, 'blog/post_form.html', {'form': form})
88
-
89
- @login_required
90
- def post_edit(request, slug):
91
- """Edit existing post."""
92
- post = get_object_or_404(Post, slug=slug, author=request.user)
93
-
94
- if request.method == 'POST':
95
- form = PostForm(request.POST, request.FILES, instance=post)
96
- if form.is_valid():
97
- form.save()
98
- messages.success(request, 'Post updated successfully!')
99
- return redirect('post_detail', slug=post.slug)
100
- else:
101
- form = PostForm(instance=post)
102
-
103
- return render(request, 'blog/post_form.html', {
104
- 'form': form,
105
- 'post': post
106
- })
107
-
108
- # Class-Based Views
109
- class PostListView(ListView):
110
- """List view for posts with pagination."""
111
- model = Post
112
- template_name = 'blog/post_list.html'
113
- context_object_name = 'posts'
114
- paginate_by = 10
115
-
116
- def get_queryset(self):
117
- return Post.objects.filter(status='published').select_related('author', 'category')
118
-
119
- def get_context_data(self, **kwargs):
120
- context = super().get_context_data(**kwargs)
121
- context['categories'] = Category.objects.all()
122
- return context
123
-
124
- class PostDetailView(DetailView):
125
- """Detail view for individual posts."""
126
- model = Post
127
- template_name = 'blog/post_detail.html'
128
- context_object_name = 'post'
129
-
130
- def get_queryset(self):
131
- return Post.objects.filter(status='published')
132
-
133
- class PostCreateView(LoginRequiredMixin, CreateView):
134
- """Create view for new posts."""
135
- model = Post
136
- form_class = PostForm
137
- template_name = 'blog/post_form.html'
138
-
139
- def form_valid(self, form):
140
- form.instance.author = self.request.user
141
- return super().form_valid(form)
142
-
143
- class PostUpdateView(LoginRequiredMixin, UpdateView):
144
- """Update view for existing posts."""
145
- model = Post
146
- form_class = PostForm
147
- template_name = 'blog/post_form.html'
148
-
149
- def get_queryset(self):
150
- return Post.objects.filter(author=self.request.user)
151
-
152
- class PostDeleteView(LoginRequiredMixin, DeleteView):
153
- """Delete view for posts."""
154
- model = Post
155
- template_name = 'blog/post_confirm_delete.html'
156
- success_url = reverse_lazy('post_list')
157
-
158
- def get_queryset(self):
159
- return Post.objects.filter(author=self.request.user)
160
-
161
- # API Views
162
- def api_post_list(request):
163
- """API endpoint for post list."""
164
- posts = Post.objects.filter(status='published').values(
165
- 'id', 'title', 'slug', 'created_at', 'author__username'
166
- )
167
- return JsonResponse(list(posts), safe=False)
168
- ```
169
-
170
- ## View Types Supported
171
-
172
- - **Function-Based Views (FBV)** - Simple, explicit control
173
- - **Class-Based Views (CBV)** - Reusable, inheritance-based
174
- - **Generic Views** - ListView, DetailView, CreateView, etc.
175
- - **API Views** - JSON responses for AJAX/API calls
176
-
177
- ## Features Included
178
-
179
- - **Authentication checks** with decorators/mixins
180
- - **Permission handling** for user authorization
181
- - **Form processing** with validation
182
- - **Error handling** and user feedback
183
- - **SEO-friendly URLs** with slugs
184
- - **Database optimization** with select_related/prefetch_related
185
- - **Pagination** for large datasets
186
- - **Search and filtering** functionality
187
-
188
- ## Security Best Practices
189
-
190
- - CSRF protection (automatic with forms)
191
- - User authentication and authorization
192
- - SQL injection prevention (ORM)
193
- - XSS protection with template escaping
194
- - Proper error handling
195
-
196
- ## URL Configuration
197
-
198
- ```python
199
- # urls.py
200
- from django.urls import path
201
- from . import views
202
-
203
- app_name = 'blog'
204
-
205
- urlpatterns = [
206
- # Function-based views
207
- path('', views.post_list, name='post_list'),
208
- path('post/<slug:slug>/', views.post_detail, name='post_detail'),
209
- path('create/', views.post_create, name='post_create'),
210
- path('edit/<slug:slug>/', views.post_edit, name='post_edit'),
211
-
212
- # Class-based views
213
- path('posts/', views.PostListView.as_view(), name='post_list_cbv'),
214
- path('posts/<slug:slug>/', views.PostDetailView.as_view(), name='post_detail_cbv'),
215
- path('posts/create/', views.PostCreateView.as_view(), name='post_create_cbv'),
216
- path('posts/<slug:slug>/edit/', views.PostUpdateView.as_view(), name='post_edit_cbv'),
217
- path('posts/<slug:slug>/delete/', views.PostDeleteView.as_view(), name='post_delete_cbv'),
218
-
219
- # API endpoints
220
- path('api/posts/', views.api_post_list, name='api_post_list'),
221
- ]
222
- ```