Add initial database erase support
This commit is contained in:
@@ -3,9 +3,10 @@ from __future__ import absolute_import
|
|||||||
from project_setup.api import register_setup
|
from project_setup.api import register_setup
|
||||||
from navigation.api import register_links#, register_sidebar_template
|
from navigation.api import register_links#, register_sidebar_template
|
||||||
|
|
||||||
from .links import database_bootstrap, bootstrap_execute
|
from .links import database_bootstrap, bootstrap_execute, erase_database_link
|
||||||
from .api import BootstrapSimple, BootstrapPermit
|
from .api import BootstrapSimple, BootstrapPermit
|
||||||
|
|
||||||
register_setup(database_bootstrap)
|
register_setup(database_bootstrap)
|
||||||
|
register_setup(erase_database_link)
|
||||||
register_links(BootstrapSimple, [bootstrap_execute])
|
register_links(BootstrapSimple, [bootstrap_execute])
|
||||||
register_links(BootstrapPermit, [bootstrap_execute])
|
register_links(BootstrapPermit, [bootstrap_execute])
|
||||||
|
|||||||
@@ -2,14 +2,48 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
|
from django.contrib.auth.models import User, Group
|
||||||
|
|
||||||
from metadata.models import MetadataType, MetadataSet
|
from metadata.models import MetadataType, MetadataSet
|
||||||
from document_indexing.models import Index, IndexTemplateNode
|
from document_indexing.models import Index, IndexTemplateNode
|
||||||
from documents.models import DocumentType, DocumentTypeFilename
|
from documents.models import DocumentType, DocumentTypeFilename, Document
|
||||||
|
from permissions.models import Role
|
||||||
|
from metadata.api import save_metadata_list
|
||||||
|
#from sources.models import WebForm, StagingFolder
|
||||||
|
|
||||||
bootstrap_options = {}
|
bootstrap_options = {}
|
||||||
|
|
||||||
|
|
||||||
|
def nuke_database():
|
||||||
|
for obj in Document.objects.all():
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
for obj in MetadataType.objects.all():
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
for obj in MetadataSet.objects.all():
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
for obj in Index.objects.all():
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
for obj in DocumentType.objects.all():
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
#for obj in WebForm.objects.all():
|
||||||
|
# obj.delete()
|
||||||
|
|
||||||
|
#for obj in StagingFolder.objects.all():
|
||||||
|
# obj.delete()
|
||||||
|
|
||||||
|
for obj in Group.objects.all():
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
for obj in User.objects.all():
|
||||||
|
if not obj.is_superuser and not obj.is_staff:
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
|
|
||||||
class BootstrapBase(object):
|
class BootstrapBase(object):
|
||||||
name = None
|
name = None
|
||||||
label = ''
|
label = ''
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ def is_superuser(context):
|
|||||||
|
|
||||||
database_bootstrap = {'text': _(u'bootstrap database'), 'view': 'bootstrap_type_list', 'icon': 'database_lightning.png', 'condition': is_superuser}#, 'children_view_regex': [r'statistics']}
|
database_bootstrap = {'text': _(u'bootstrap database'), 'view': 'bootstrap_type_list', 'icon': 'database_lightning.png', 'condition': is_superuser}#, 'children_view_regex': [r'statistics']}
|
||||||
bootstrap_execute = {'text': _(u'execute'), 'view': 'bootstrap_execute', 'args': 'object.name', 'sprite': 'database_lightning.png', 'condition': is_superuser}#, 'children_view_regex': [r'statistics']}
|
bootstrap_execute = {'text': _(u'execute'), 'view': 'bootstrap_execute', 'args': 'object.name', 'sprite': 'database_lightning.png', 'condition': is_superuser}#, 'children_view_regex': [r'statistics']}
|
||||||
|
erase_database_link = {'text': _(u'erase database'), 'view': 'erase_database_view', 'icon': 'radioactivity.png', 'condition': is_superuser}#, 'children_view_regex': [r'statistics']}
|
||||||
|
|||||||
@@ -1,12 +1 @@
|
|||||||
from __future__ import absolute_import
|
from django.db import models
|
||||||
|
|
||||||
#import logging
|
|
||||||
|
|
||||||
#from django.db import models
|
|
||||||
#from django.utils.translation import ugettext_lazy as _
|
|
||||||
|
|
||||||
#logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
#class CompanyType(models.Model):
|
|
||||||
# name =
|
|
||||||
|
|||||||
BIN
apps/bootstrap/static/images/icons/radioactivity.png
Executable file
BIN
apps/bootstrap/static/images/icons/radioactivity.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -3,4 +3,5 @@ from django.conf.urls.defaults import patterns, url
|
|||||||
urlpatterns = patterns('bootstrap.views',
|
urlpatterns = patterns('bootstrap.views',
|
||||||
url(r'^type/list/$', 'bootstrap_type_list', (), 'bootstrap_type_list'),
|
url(r'^type/list/$', 'bootstrap_type_list', (), 'bootstrap_type_list'),
|
||||||
url(r'^(?P<bootstrap_name>\w+)/execute/$', 'bootstrap_execute', (), 'bootstrap_execute'),
|
url(r'^(?P<bootstrap_name>\w+)/execute/$', 'bootstrap_execute', (), 'bootstrap_execute'),
|
||||||
|
url(r'^nuke/$', 'erase_database_view', (), 'erase_database_view'),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from django.template import RequestContext
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from .api import bootstrap_options
|
from .api import bootstrap_options, nuke_database
|
||||||
|
|
||||||
|
|
||||||
def bootstrap_type_list(request):
|
def bootstrap_type_list(request):
|
||||||
@@ -49,7 +49,7 @@ def bootstrap_execute(request, bootstrap_name):
|
|||||||
'delete_view': False,
|
'delete_view': False,
|
||||||
'previous': previous,
|
'previous': previous,
|
||||||
'next': next,
|
'next': next,
|
||||||
#'form_icon': u'basket_remove.png',
|
'form_icon': u'database_lightning.png',
|
||||||
'object': bootstrap,
|
'object': bootstrap,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,3 +57,35 @@ def bootstrap_execute(request, bootstrap_name):
|
|||||||
|
|
||||||
return render_to_response('generic_confirm.html', context,
|
return render_to_response('generic_confirm.html', context,
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
def erase_database_view(request):
|
||||||
|
# TODO: check for permission
|
||||||
|
|
||||||
|
post_action_redirect = None
|
||||||
|
|
||||||
|
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))
|
||||||
|
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/')))
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
try:
|
||||||
|
nuke_database()
|
||||||
|
except Exception, exc:
|
||||||
|
messages.error(request, _(u'Error erasing database; %s') % exc)
|
||||||
|
else:
|
||||||
|
messages.success(request, _(u'Database erased successfully.'))
|
||||||
|
return HttpResponseRedirect(next)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
#'object_name': _(u'bootstrap setup'),
|
||||||
|
'delete_view': False,
|
||||||
|
'previous': previous,
|
||||||
|
'next': next,
|
||||||
|
'form_icon': u'radioactivity.png',
|
||||||
|
#'object': bootstrap,
|
||||||
|
}
|
||||||
|
|
||||||
|
context['title'] = _(u'Are you sure you wish to erase the entire database and document storage?')
|
||||||
|
|
||||||
|
return render_to_response('generic_confirm.html', context,
|
||||||
|
context_instance=RequestContext(request))
|
||||||
|
|||||||
Reference in New Issue
Block a user