FossilRepo
Add error handling to ticket_comment view
Commit
a14edfaab9ae321655d4a754dc8f6ea90f905d113bb787f2616c336414738842
Parent
d50a555e5d654ba…
1 file changed
+13
-8
+13
-8
| --- fossil/views.py | ||
| +++ fossil/views.py | ||
| @@ -1439,18 +1439,23 @@ | ||
| 1439 | 1439 | project, fossil_repo, reader = _get_repo_and_reader(slug, request, "write") |
| 1440 | 1440 | |
| 1441 | 1441 | if request.method == "POST": |
| 1442 | 1442 | comment = request.POST.get("comment", "").strip() |
| 1443 | 1443 | if comment: |
| 1444 | - from fossil.cli import FossilCLI | |
| 1445 | - | |
| 1446 | - cli = FossilCLI() | |
| 1447 | - success = cli.ticket_change(fossil_repo.full_path, ticket_uuid, {"icomment": comment}) | |
| 1448 | - if success: | |
| 1449 | - from django.contrib import messages | |
| 1450 | - | |
| 1451 | - messages.success(request, "Comment added.") | |
| 1444 | + from django.contrib import messages | |
| 1445 | + | |
| 1446 | + try: | |
| 1447 | + from fossil.cli import FossilCLI | |
| 1448 | + | |
| 1449 | + cli = FossilCLI() | |
| 1450 | + success = cli.ticket_change(fossil_repo.full_path, ticket_uuid, {"icomment": comment}) | |
| 1451 | + if success: | |
| 1452 | + messages.success(request, "Comment added.") | |
| 1453 | + else: | |
| 1454 | + messages.error(request, "Failed to add comment.") | |
| 1455 | + except Exception: | |
| 1456 | + messages.error(request, "Failed to add comment.") | |
| 1452 | 1457 | from django.shortcuts import redirect |
| 1453 | 1458 | |
| 1454 | 1459 | return redirect("fossil:ticket_detail", slug=slug, ticket_uuid=ticket_uuid) |
| 1455 | 1460 | |
| 1456 | 1461 | |
| 1457 | 1462 |
| --- fossil/views.py | |
| +++ fossil/views.py | |
| @@ -1439,18 +1439,23 @@ | |
| 1439 | project, fossil_repo, reader = _get_repo_and_reader(slug, request, "write") |
| 1440 | |
| 1441 | if request.method == "POST": |
| 1442 | comment = request.POST.get("comment", "").strip() |
| 1443 | if comment: |
| 1444 | from fossil.cli import FossilCLI |
| 1445 | |
| 1446 | cli = FossilCLI() |
| 1447 | success = cli.ticket_change(fossil_repo.full_path, ticket_uuid, {"icomment": comment}) |
| 1448 | if success: |
| 1449 | from django.contrib import messages |
| 1450 | |
| 1451 | messages.success(request, "Comment added.") |
| 1452 | from django.shortcuts import redirect |
| 1453 | |
| 1454 | return redirect("fossil:ticket_detail", slug=slug, ticket_uuid=ticket_uuid) |
| 1455 | |
| 1456 | |
| 1457 |
| --- fossil/views.py | |
| +++ fossil/views.py | |
| @@ -1439,18 +1439,23 @@ | |
| 1439 | project, fossil_repo, reader = _get_repo_and_reader(slug, request, "write") |
| 1440 | |
| 1441 | if request.method == "POST": |
| 1442 | comment = request.POST.get("comment", "").strip() |
| 1443 | if comment: |
| 1444 | from django.contrib import messages |
| 1445 | |
| 1446 | try: |
| 1447 | from fossil.cli import FossilCLI |
| 1448 | |
| 1449 | cli = FossilCLI() |
| 1450 | success = cli.ticket_change(fossil_repo.full_path, ticket_uuid, {"icomment": comment}) |
| 1451 | if success: |
| 1452 | messages.success(request, "Comment added.") |
| 1453 | else: |
| 1454 | messages.error(request, "Failed to add comment.") |
| 1455 | except Exception: |
| 1456 | messages.error(request, "Failed to add comment.") |
| 1457 | from django.shortcuts import redirect |
| 1458 | |
| 1459 | return redirect("fossil:ticket_detail", slug=slug, ticket_uuid=ticket_uuid) |
| 1460 | |
| 1461 | |
| 1462 |