Add qoute step.
This commit is contained in:
		
							parent
							
								
									b71ea45681
								
							
						
					
					
						commit
						6ff4740d04
					
				
					 30 changed files with 3362 additions and 376 deletions
				
			
		| 
						 | 
				
			
			@ -46,21 +46,95 @@ class StepDependencyAdmin(admin.ModelAdmin):
 | 
			
		|||
 | 
			
		||||
@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']
 | 
			
		||||
    verbose_name = "درخواست"
 | 
			
		||||
    verbose_name_plural = "درخواستها"
 | 
			
		||||
    list_display = [
 | 
			
		||||
        'code',
 | 
			
		||||
        'slug', 
 | 
			
		||||
        'well_display', 
 | 
			
		||||
        'representative', 
 | 
			
		||||
        'requester', 
 | 
			
		||||
        'process', 
 | 
			
		||||
        'status_display', 
 | 
			
		||||
        'priority_display', 
 | 
			
		||||
        'created', 
 | 
			
		||||
        'progress_display'
 | 
			
		||||
    ]
 | 
			
		||||
    list_filter = [
 | 
			
		||||
        'process', 
 | 
			
		||||
        'status', 
 | 
			
		||||
        'priority',
 | 
			
		||||
        'created',
 | 
			
		||||
        'well__representative'
 | 
			
		||||
    ]
 | 
			
		||||
    search_fields = [
 | 
			
		||||
        'code',
 | 
			
		||||
        'slug', 
 | 
			
		||||
        'process__name', 
 | 
			
		||||
        'requester__username', 
 | 
			
		||||
        'requester__first_name',
 | 
			
		||||
        'well__water_subscription_number',
 | 
			
		||||
        'representative__username'
 | 
			
		||||
    ]
 | 
			
		||||
    readonly_fields = [
 | 
			
		||||
        'deleted_at', 
 | 
			
		||||
        'created', 
 | 
			
		||||
        'updated',
 | 
			
		||||
        'completed_at'
 | 
			
		||||
    ]
 | 
			
		||||
    autocomplete_fields = [
 | 
			
		||||
        'well', 
 | 
			
		||||
        'representative', 
 | 
			
		||||
        'requester', 
 | 
			
		||||
        'process', 
 | 
			
		||||
        'current_step'
 | 
			
		||||
    ]
 | 
			
		||||
    ordering = ['-created']
 | 
			
		||||
    
 | 
			
		||||
    fieldsets = (
 | 
			
		||||
        ('اطلاعات اصلی', {
 | 
			
		||||
            'fields': ('code', 'slug', 'description', 'process')
 | 
			
		||||
        }),
 | 
			
		||||
        ('اطلاعات چاه', {
 | 
			
		||||
            'fields': ('well', 'representative')
 | 
			
		||||
        }),
 | 
			
		||||
        ('اطلاعات درخواست', {
 | 
			
		||||
            'fields': ('requester', 'priority')
 | 
			
		||||
        }),
 | 
			
		||||
        ('وضعیت و پیشرفت', {
 | 
			
		||||
            'fields': ('status', 'current_step')
 | 
			
		||||
        }),
 | 
			
		||||
        ('تاریخها', {
 | 
			
		||||
            'fields': ('created', 'updated', 'completed_at'),
 | 
			
		||||
            'classes': ('collapse',)
 | 
			
		||||
        }),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def well_display(self, obj):
 | 
			
		||||
        if obj.well:
 | 
			
		||||
            return f"{obj.well.water_subscription_number}"
 | 
			
		||||
        return "-"
 | 
			
		||||
    well_display.short_description = "چاه"
 | 
			
		||||
 | 
			
		||||
    def status_display(self, obj):
 | 
			
		||||
        return mark_safe(obj.get_status_display_with_color())
 | 
			
		||||
    status_display.short_description = "وضعیت"
 | 
			
		||||
 | 
			
		||||
    def priority_display(self, obj):
 | 
			
		||||
        return mark_safe(obj.get_priority_display_with_color())
 | 
			
		||||
    priority_display.short_description = "اولویت"
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        )
 | 
			
		||||
        if obj.process:
 | 
			
		||||
            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
 | 
			
		||||
            )
 | 
			
		||||
        return "-"
 | 
			
		||||
    progress_display.short_description = "پیشرفت"
 | 
			
		||||
 | 
			
		||||
@admin.register(StepInstance)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue