Commit 17eb2798 authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos Committed by Christos Stavrakakis
Browse files

django: Add a RemoveCommand class

* Add a new class for snf-manage *-remove commands
parent caec4fa6
...@@ -39,6 +39,8 @@ from django.core.exceptions import FieldError ...@@ -39,6 +39,8 @@ from django.core.exceptions import FieldError
from snf_django.management import utils from snf_django.management import utils
from snf_django.lib.astakos import UserCache from snf_django.lib.astakos import UserCache
import distutils
class SynnefoCommand(BaseCommand): class SynnefoCommand(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
...@@ -328,3 +330,29 @@ class ListCommand(BaseCommand): ...@@ -328,3 +330,29 @@ class ListCommand(BaseCommand):
for field in self.object_class._meta.fields: for field in self.object_class._meta.fields:
table.append((field.name, field.verbose_name, field.help_text)) table.append((field.name, field.verbose_name, field.help_text))
utils.pprint_table(self.stdout, table, headers) utils.pprint_table(self.stdout, table, headers)
class RemoveCommand(BaseCommand):
help = "Generic remove command"
option_list = BaseCommand.option_list + (
make_option(
"-f", "--force",
dest="force",
action="store_true",
default=False,
help="Do not prompt for confirmation"),
)
def confirm_deletion(self, force, resource='', args=''):
if force is True:
return True
ids = ', '.join(args)
self.stdout.write("Are you sure you want to delete %s %s?"
" [Y/N]\n" % (resource, ids))
try:
answer = distutils.util.strtobool(raw_input())
if answer != 1:
raise CommandError("Aborting deletion")
except ValueError:
raise CommandError("Invalid Y/N value, aborting")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment