first commit
This commit is contained in:
commit
b71ea45681
898 changed files with 138202 additions and 0 deletions
107
processes/admin.py
Normal file
107
processes/admin.py
Normal file
|
@ -0,0 +1,107 @@
|
|||
from django.contrib import admin
|
||||
from simple_history.admin import SimpleHistoryAdmin
|
||||
from django.utils.html import format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
from .models import Process, ProcessStep, ProcessInstance, StepInstance, StepDependency, StepRejection, StepRevision
|
||||
|
||||
@admin.register(Process)
|
||||
class ProcessAdmin(SimpleHistoryAdmin):
|
||||
list_display = ['name', 'is_active', 'created_by', 'created', 'steps_count']
|
||||
list_filter = ['is_active', 'created']
|
||||
search_fields = ['name', 'description', 'created_by__username']
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
readonly_fields = ['deleted_at', 'created', 'updated']
|
||||
|
||||
def steps_count(self, obj):
|
||||
return obj.steps.count()
|
||||
steps_count.short_description = "تعداد مراحل"
|
||||
|
||||
@admin.register(ProcessStep)
|
||||
class ProcessStepAdmin(SimpleHistoryAdmin):
|
||||
list_display = ['name', 'process', 'order', 'is_required', 'dependencies_display', 'blocks_previous', 'can_go_back']
|
||||
list_filter = ['process', 'is_required', 'blocks_previous', 'can_go_back']
|
||||
search_fields = ['name', 'process__name', 'description']
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
readonly_fields = ['deleted_at']
|
||||
ordering = ['process', 'order']
|
||||
|
||||
def dependencies_display(self, obj):
|
||||
dependencies = obj.get_dependencies()
|
||||
if dependencies:
|
||||
dependency_names = ProcessStep.objects.filter(id__in=dependencies).values_list('name', flat=True)
|
||||
return ", ".join(dependency_names)
|
||||
return "بدون وابستگی"
|
||||
dependencies_display.short_description = "وابسته به"
|
||||
|
||||
@admin.register(StepDependency)
|
||||
class StepDependencyAdmin(admin.ModelAdmin):
|
||||
list_display = ['dependent_step', 'dependency_step', 'process_display', 'created_at']
|
||||
list_filter = ['dependent_step__process', 'created_at']
|
||||
search_fields = ['dependent_step__name', 'dependency_step__name']
|
||||
ordering = ['dependent_step__process', 'dependent_step__order']
|
||||
|
||||
def process_display(self, obj):
|
||||
return obj.dependent_step.process.name
|
||||
process_display.short_description = "فرآیند"
|
||||
|
||||
@admin.register(ProcessInstance)
|
||||
class ProcessInstanceAdmin(SimpleHistoryAdmin):
|
||||
list_display = ['name', 'process', 'requester', 'current_step', 'status', 'started_at', 'progress_display']
|
||||
list_filter = ['process', 'status', 'started_at']
|
||||
search_fields = ['name', 'process__name', 'requester__username', 'requester__first_name']
|
||||
readonly_fields = ['deleted_at', 'started_at', 'completed_at']
|
||||
ordering = ['-started_at']
|
||||
|
||||
def progress_display(self, obj):
|
||||
total_steps = obj.process.steps.count()
|
||||
completed_steps = obj.step_instances.filter(status='completed').count()
|
||||
percentage = (completed_steps / total_steps * 100) if total_steps > 0 else 0
|
||||
percentage_int = int(percentage)
|
||||
return format_html(
|
||||
'<div class="progress" style="width: 100px;"><div class="progress-bar" style="width: {}%">{}/{} ({}%)</div></div>',
|
||||
percentage_int, completed_steps, total_steps, percentage_int
|
||||
)
|
||||
progress_display.short_description = "پیشرفت"
|
||||
|
||||
@admin.register(StepInstance)
|
||||
class StepInstanceAdmin(SimpleHistoryAdmin):
|
||||
list_display = ['process_instance', 'step', 'assigned_to', 'status_display', 'rejection_count', 'started_at', 'completed_at']
|
||||
list_filter = ['status', 'step__process', 'started_at']
|
||||
search_fields = ['process_instance__name', 'step__name', 'assigned_to__username']
|
||||
readonly_fields = ['started_at', 'completed_at']
|
||||
ordering = ['process_instance', 'step__order']
|
||||
|
||||
def status_display(self, obj):
|
||||
return mark_safe(obj.get_status_display_with_color())
|
||||
status_display.short_description = "وضعیت"
|
||||
|
||||
def rejection_count(self, obj):
|
||||
count = obj.get_rejection_count()
|
||||
if count > 0:
|
||||
return format_html('<span class="badge bg-danger">{}</span>', count)
|
||||
return format_html('<span class="badge bg-success">0</span>')
|
||||
rejection_count.short_description = "تعداد رد شدنها"
|
||||
|
||||
@admin.register(StepRejection)
|
||||
class StepRejectionAdmin(SimpleHistoryAdmin):
|
||||
list_display = ['step_instance', 'rejected_by', 'reason_short', 'created_at']
|
||||
list_filter = ['rejected_by', 'created_at', 'step_instance__step__process']
|
||||
search_fields = ['step_instance__step__name', 'rejected_by__username', 'reason']
|
||||
readonly_fields = ['created_at']
|
||||
ordering = ['-created_at']
|
||||
|
||||
def reason_short(self, obj):
|
||||
return obj.reason[:50] + "..." if len(obj.reason) > 50 else obj.reason
|
||||
reason_short.short_description = "دلیل رد شدن"
|
||||
|
||||
@admin.register(StepRevision)
|
||||
class StepRevisionAdmin(SimpleHistoryAdmin):
|
||||
list_display = ['step_instance', 'rejection', 'revised_by', 'changes_short', 'created_at']
|
||||
list_filter = ['revised_by', 'created_at', 'step_instance__step__process']
|
||||
search_fields = ['step_instance__step__name', 'revised_by__username', 'changes_description']
|
||||
readonly_fields = ['created_at']
|
||||
ordering = ['-created_at']
|
||||
|
||||
def changes_short(self, obj):
|
||||
return obj.changes_description[:50] + "..." if len(obj.changes_description) > 50 else obj.changes_description
|
||||
changes_short.short_description = "تغییرات"
|
Loading…
Add table
Add a link
Reference in a new issue