Permalink
Browse files

Added some error handling to the commands

  • Loading branch information...
1 parent 09cae91 commit ce5dad003f174e636c28fe1755a65ddaafa47f84 @zerok committed Mar 27, 2009
@@ -1,4 +1,5 @@
from django.core.management import BaseCommand, CommandError
+from django.db import IntegrityError
from flatblocks.models import FlatBlock
@@ -13,4 +14,7 @@ def handle(self, *args, **options):
slug = args[0]
block = FlatBlock(header="[%s]"%slug, content="Empty flatblock",
slug=slug)
- block.save()
+ try:
+ block.save()
+ except IntegrityError, e:
+ raise CommandError, "A flatblock with this name already exists"
@@ -11,5 +11,8 @@ def handle(self, *args, **options):
raise CommandError, "This command requires the slug of the " \
"flatblock as its first argument"
slug = args[0]
- FlatBlock.objects.get(slug=slug).delete()
+ try:
+ FlatBlock.objects.get(slug=slug).delete()
+ except FlatBlock.DoesNotExist, e:
+ raise CommandError, "The requested flatblock doesn't exist"

0 comments on commit ce5dad0

Please sign in to comment.