django phase2.3.4.
This commit is contained in:
@@ -33,7 +33,13 @@ class TasksAdmin(ExportMixin, SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
search_fields = ['title', 'description']
|
||||
ordering = ['-created_at']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
actions = ['bulk_set_status_draft', 'bulk_set_status_in_progress', 'bulk_set_status_completed']
|
||||
autocomplete_fields = ['cluster', 'site', 'sector']
|
||||
actions = [
|
||||
'bulk_set_status_draft',
|
||||
'bulk_set_status_in_progress',
|
||||
'bulk_set_status_completed',
|
||||
'bulk_assign_cluster',
|
||||
]
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
@@ -69,6 +75,47 @@ class TasksAdmin(ExportMixin, SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
self.message_user(request, f'{updated} task(s) set to completed.', messages.SUCCESS)
|
||||
bulk_set_status_completed.short_description = 'Set status to Completed'
|
||||
|
||||
def bulk_assign_cluster(self, request, queryset):
|
||||
"""Assign selected tasks to a cluster - requires form input"""
|
||||
from django import forms
|
||||
from igny8_core.modules.planner.models import Clusters
|
||||
|
||||
# If this is the POST request with cluster selection
|
||||
if 'apply' in request.POST:
|
||||
cluster_id = request.POST.get('cluster')
|
||||
if cluster_id:
|
||||
cluster = Clusters.objects.get(pk=cluster_id)
|
||||
updated = queryset.update(cluster=cluster)
|
||||
self.message_user(request, f'{updated} task(s) assigned to cluster: {cluster.name}', messages.SUCCESS)
|
||||
return
|
||||
|
||||
# Get first task's site/sector for filtering clusters
|
||||
first_task = queryset.first()
|
||||
if first_task:
|
||||
clusters = Clusters.objects.filter(site=first_task.site, sector=first_task.sector)
|
||||
else:
|
||||
clusters = Clusters.objects.all()
|
||||
|
||||
# Create form for cluster selection
|
||||
class ClusterForm(forms.Form):
|
||||
cluster = forms.ModelChoiceField(
|
||||
queryset=clusters,
|
||||
label="Select Cluster",
|
||||
help_text=f"Assign {queryset.count()} selected task(s) to:"
|
||||
)
|
||||
|
||||
if clusters.exists():
|
||||
from django.shortcuts import render
|
||||
return render(request, 'admin/bulk_action_form.html', {
|
||||
'title': 'Assign Tasks to Cluster',
|
||||
'queryset': queryset,
|
||||
'form': ClusterForm(),
|
||||
'action': 'bulk_assign_cluster',
|
||||
})
|
||||
else:
|
||||
self.message_user(request, 'No clusters available for the selected tasks.', messages.WARNING)
|
||||
bulk_assign_cluster.short_description = 'Assign to Cluster'
|
||||
|
||||
def get_site_display(self, obj):
|
||||
"""Safely get site name"""
|
||||
try:
|
||||
@@ -143,8 +190,13 @@ class ContentAdmin(ExportMixin, SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
search_fields = ['title', 'content_html', 'external_url']
|
||||
ordering = ['-created_at']
|
||||
readonly_fields = ['created_at', 'updated_at', 'word_count', 'get_tags_display', 'get_categories_display']
|
||||
autocomplete_fields = ['cluster', 'site', 'sector']
|
||||
inlines = [ContentTaxonomyInline]
|
||||
actions = ['bulk_set_status_published', 'bulk_set_status_draft']
|
||||
actions = [
|
||||
'bulk_set_status_published',
|
||||
'bulk_set_status_draft',
|
||||
'bulk_add_taxonomy',
|
||||
]
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
@@ -208,6 +260,55 @@ class ContentAdmin(ExportMixin, SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
self.message_user(request, f'{updated} content item(s) set to draft.', messages.SUCCESS)
|
||||
bulk_set_status_draft.short_description = 'Set status to Draft'
|
||||
|
||||
def bulk_add_taxonomy(self, request, queryset):
|
||||
"""Add taxonomy terms to selected content"""
|
||||
from django import forms
|
||||
from igny8_core.business.content.models import ContentTaxonomy, ContentTaxonomyRelation
|
||||
|
||||
# If this is the POST request with taxonomy selection
|
||||
if 'apply' in request.POST:
|
||||
taxonomy_ids = request.POST.getlist('taxonomies')
|
||||
if taxonomy_ids:
|
||||
count = 0
|
||||
for content in queryset:
|
||||
for tax_id in taxonomy_ids:
|
||||
taxonomy = ContentTaxonomy.objects.get(pk=tax_id)
|
||||
ContentTaxonomyRelation.objects.get_or_create(
|
||||
content=content,
|
||||
taxonomy=taxonomy
|
||||
)
|
||||
count += 1
|
||||
self.message_user(request, f'Added {count} taxonomy relation(s) to {queryset.count()} content item(s).', messages.SUCCESS)
|
||||
return
|
||||
|
||||
# Get first content's site/sector for filtering taxonomies
|
||||
first_content = queryset.first()
|
||||
if first_content:
|
||||
taxonomies = ContentTaxonomy.objects.filter(site=first_content.site, sector=first_content.sector)
|
||||
else:
|
||||
taxonomies = ContentTaxonomy.objects.all()
|
||||
|
||||
# Create form for taxonomy selection
|
||||
class TaxonomyForm(forms.Form):
|
||||
taxonomies = forms.ModelMultipleChoiceField(
|
||||
queryset=taxonomies,
|
||||
label="Select Taxonomies",
|
||||
help_text=f"Add taxonomy terms to {queryset.count()} selected content item(s)",
|
||||
widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
if taxonomies.exists():
|
||||
from django.shortcuts import render
|
||||
return render(request, 'admin/bulk_action_form.html', {
|
||||
'title': 'Add Taxonomies to Content',
|
||||
'queryset': queryset,
|
||||
'form': TaxonomyForm(),
|
||||
'action': 'bulk_add_taxonomy',
|
||||
})
|
||||
else:
|
||||
self.message_user(request, 'No taxonomies available for the selected content.', messages.WARNING)
|
||||
bulk_add_taxonomy.short_description = 'Add Taxonomy Terms'
|
||||
|
||||
def get_site_display(self, obj):
|
||||
"""Safely get site name"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user