Initial commit from monorepo
This commit is contained in:
55
offers/admin.py
Normal file
55
offers/admin.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from django.contrib import admin, messages
|
||||
|
||||
from .models import Offer
|
||||
from .services import OfferService
|
||||
|
||||
|
||||
@admin.register(Offer)
|
||||
class OfferAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
'product_name',
|
||||
'status',
|
||||
'workflow_status',
|
||||
'team_uuid',
|
||||
'location_name',
|
||||
'location_country',
|
||||
'quantity',
|
||||
'price_per_unit',
|
||||
'created_at',
|
||||
]
|
||||
list_filter = ['status', 'workflow_status', 'created_at', 'category_name', 'location_country']
|
||||
search_fields = ['product_name', 'description', 'location_name', 'uuid']
|
||||
readonly_fields = ['uuid', 'workflow_status', 'workflow_error', 'created_at', 'updated_at']
|
||||
actions = ['sync_to_graph']
|
||||
|
||||
@admin.action(description="Синхронизировать в граф (запустить workflow)")
|
||||
def sync_to_graph(self, request, queryset):
|
||||
"""Запускает workflow для пересинхронизации выбранных офферов в ArangoDB граф"""
|
||||
success_count = 0
|
||||
error_count = 0
|
||||
|
||||
for offer in queryset:
|
||||
try:
|
||||
workflow_id, run_id = OfferService.resync_offer_via_workflow(offer)
|
||||
offer.workflow_status = 'pending'
|
||||
offer.workflow_error = ''
|
||||
offer.save(update_fields=['workflow_status', 'workflow_error'])
|
||||
success_count += 1
|
||||
except Exception as e:
|
||||
offer.workflow_status = 'error'
|
||||
offer.workflow_error = str(e)
|
||||
offer.save(update_fields=['workflow_status', 'workflow_error'])
|
||||
error_count += 1
|
||||
|
||||
if success_count:
|
||||
self.message_user(
|
||||
request,
|
||||
f"Запущен workflow для {success_count} офферов",
|
||||
messages.SUCCESS,
|
||||
)
|
||||
if error_count:
|
||||
self.message_user(
|
||||
request,
|
||||
f"Ошибка при запуске workflow для {error_count} офферов",
|
||||
messages.ERROR,
|
||||
)
|
||||
Reference in New Issue
Block a user