Buckets:
| from django.shortcuts import render, get_object_or_404, redirect | |
| from django.http import JsonResponse | |
| from .models import SimulationMethod, SimulationRun | |
| from .tasks import run_simulation | |
| import json | |
| def home(request): | |
| methods = SimulationMethod.objects.filter(is_active=True) | |
| recent_runs = SimulationRun.objects.all()[:5] | |
| return render(request, 'simulations/home.html', { | |
| 'methods': methods, | |
| 'recent_runs': recent_runs, | |
| }) | |
| def method_list(request): | |
| methods = SimulationMethod.objects.filter(is_active=True) | |
| return render(request, 'simulations/method_list.html', { | |
| 'methods': methods, | |
| }) | |
| def method_detail(request, slug): | |
| method = get_object_or_404(SimulationMethod, slug=slug, is_active=True) | |
| return render(request, 'simulations/method_detail.html', { | |
| 'method': method, | |
| }) | |
| def run_create(request, method_slug=None): | |
| methods = SimulationMethod.objects.filter(is_active=True) | |
| if method_slug: | |
| selected_method = get_object_or_404( | |
| SimulationMethod, slug=method_slug, is_active=True | |
| ) | |
| else: | |
| selected_method = None | |
| if request.method == 'POST': | |
| method_id = request.POST.get('method') | |
| parameters = json.loads(request.POST.get('parameters', '{}')) | |
| name = request.POST.get('name', '') | |
| method = get_object_or_404(SimulationMethod, pk=method_id) | |
| run = SimulationRun.objects.create( | |
| method=method, | |
| name=name, | |
| parameters=parameters, | |
| ) | |
| run_simulation.delay(run.id) | |
| return redirect('run_detail', run_id=run.id) | |
| return render(request, 'simulations/run_create.html', { | |
| 'methods': methods, | |
| 'selected_method': selected_method, | |
| }) | |
| def run_detail(request, run_id): | |
| run = get_object_or_404(SimulationRun, pk=run_id) | |
| return render(request, 'simulations/run_detail.html', { | |
| 'run': run, | |
| }) | |
| def run_list(request): | |
| runs = SimulationRun.objects.all() | |
| status_filter = request.GET.get('status') | |
| if status_filter: | |
| runs = runs.filter(status=status_filter) | |
| return render(request, 'simulations/run_list.html', { | |
| 'runs': runs, | |
| 'status_filter': status_filter, | |
| }) | |
| def run_status(request, run_id): | |
| run = get_object_or_404(SimulationRun, pk=run_id) | |
| return JsonResponse({ | |
| 'id': run.id, | |
| 'status': run.status, | |
| 'progress': run.progress, | |
| 'error_message': run.error_message, | |
| 'started_at': run.started_at.strftime('%Y-%m-%d %H:%M:%S') if run.started_at else None, | |
| 'completed_at': run.completed_at.strftime('%Y-%m-%d %H:%M:%S') if run.completed_at else None, | |
| }) | |
| def run_cancel(request, run_id): | |
| run = get_object_or_404(SimulationRun, pk=run_id) | |
| if run.status in ['PENDING', 'RUNNING']: | |
| run.status = 'CANCELLED' | |
| run.save(update_fields=['status']) | |
| return redirect('run_detail', run_id=run.id) | |
| def run_retry(request, run_id): | |
| run = get_object_or_404(SimulationRun, pk=run_id) | |
| run.set_pending() | |
| run_simulation.delay(run.id) | |
| return redirect('run_detail', run_id=run.id) | |
Xet Storage Details
- Size:
- 3.2 kB
- Xet hash:
- 22020ebc7b680b07ecac18fe37e6323bf1edaedc4c7cd67de93b19cdacf5ff38
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.