From fbee8cb64cb754502fe2f122fe36cb19cf5d46c5 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 22 Sep 2012 01:50:17 -0400 Subject: [PATCH] Use models to store the bootstrap setups --- apps/bootstrap/api.py | 22 +++++++++++----------- apps/bootstrap/models.py | 19 +++++++++++++++++++ apps/bootstrap/urls.py | 2 +- apps/bootstrap/views.py | 20 +++++++++++--------- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/apps/bootstrap/api.py b/apps/bootstrap/api.py index e66bda985b..382b88cb7b 100644 --- a/apps/bootstrap/api.py +++ b/apps/bootstrap/api.py @@ -4,17 +4,17 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext from django.contrib.auth.models import User, Group -from permissions.models import Role -from history.models import History -from django_gpg.runtime import gpg -from documents.models import DocumentType, DocumentTypeFilename, Document -from folders.models import Folder -from taggit.models import Tag -from tags.models import TagProperties -from metadata.models import MetadataType, MetadataSet -from sources.models import WebForm, StagingFolder -from document_indexing.models import Index, IndexTemplateNode -from dynamic_search.models import RecentSearch +#from permissions.models import Role +#from history.models import History +#from django_gpg.runtime import gpg +#from documents.models import DocumentType, DocumentTypeFilename, Document +#from folders.models import Folder +#from taggit.models import Tag +#from tags.models import TagProperties +#from metadata.models import MetadataType, MetadataSet +#from sources.models import WebForm, StagingFolder +#from document_indexing.models import Index, IndexTemplateNode +#from dynamic_search.models import RecentSearch # TODO: clear the job queues bootstrap_options = {} diff --git a/apps/bootstrap/models.py b/apps/bootstrap/models.py index 137941ffae..e86eafe888 100644 --- a/apps/bootstrap/models.py +++ b/apps/bootstrap/models.py @@ -1 +1,20 @@ +from __future__ import absolute_import + from django.db import models +from django.utils.translation import ugettext_lazy as _ + + +class BootstrapSetup(models.Model): + """ + Model to store the fixture for a pre configured setup + """ + name = models.CharField(max_length=128, verbose_name=_(u'name'), unique=True) + description = models.TextField(verbose_name=_(u'description'), blank=True) + fixture = models.TextField(verbose_name=_(u'fixture')) + + def __unicode__(self): + return self.name + + class Meta: + verbose_name = _(u'bootstrap setup') + verbose_name_plural = _(u'bootstrap setups') diff --git a/apps/bootstrap/urls.py b/apps/bootstrap/urls.py index fe6da57712..7e58ef303f 100644 --- a/apps/bootstrap/urls.py +++ b/apps/bootstrap/urls.py @@ -2,6 +2,6 @@ from django.conf.urls.defaults import patterns, url urlpatterns = patterns('bootstrap.views', url(r'^type/list/$', 'bootstrap_type_list', (), 'bootstrap_type_list'), - url(r'^(?P\w+)/execute/$', 'bootstrap_execute', (), 'bootstrap_execute'), + url(r'^(?P\d+)/execute/$', 'bootstrap_execute', (), 'bootstrap_execute'), url(r'^nuke/$', 'erase_database_view', (), 'erase_database_view'), ) diff --git a/apps/bootstrap/views.py b/apps/bootstrap/views.py index db64511a81..68d9423f6b 100644 --- a/apps/bootstrap/views.py +++ b/apps/bootstrap/views.py @@ -2,22 +2,24 @@ from __future__ import absolute_import from django.utils.translation import ugettext_lazy as _ from django.http import HttpResponseRedirect -from django.shortcuts import render_to_response +from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.contrib import messages from django.core.urlresolvers import reverse from permissions.models import Permission -from .api import bootstrap_options, nuke_database +from .models import BootstrapSetup +from .classes import Cleanup from .permissions import PERMISSION_BOOTSTRAP_EXECUTE, PERMISSION_NUKE_DATABASE +from .icons import icon_bootstrap_execute, icon_nuke_database def bootstrap_type_list(request): Permission.objects.check_permissions(request.user, [PERMISSION_BOOTSTRAP_EXECUTE]) context = { - 'object_list': bootstrap_options.values(), + 'object_list': BootstrapSetup.objects.all(), 'title': _(u'database bootstrap setups'), 'hide_link': True, 'extra_columns': [ @@ -29,9 +31,9 @@ def bootstrap_type_list(request): context_instance=RequestContext(request)) -def bootstrap_execute(request, bootstrap_name): +def bootstrap_execute(request, bootstrap_setup_pk): Permission.objects.check_permissions(request.user, [PERMISSION_BOOTSTRAP_EXECUTE]) - bootstrap = bootstrap_options[bootstrap_name] + bootstrap_setup = get_object_or_404(BootstrapSetup, pk=bootstrap_setup_pk) post_action_redirect = reverse('bootstrap_type_list') @@ -40,7 +42,7 @@ def bootstrap_execute(request, bootstrap_name): if request.method == 'POST': try: - bootstrap.execute() + bootstrap_setup.execute() except Exception, exc: messages.error(request, _(u'Error executing bootstrap setup; %s') % exc) else: @@ -52,7 +54,7 @@ def bootstrap_execute(request, bootstrap_name): 'delete_view': False, 'previous': previous, 'next': next, - 'form_icon': u'database_lightning.png', + 'form_icon': icon_bootstrap_execute, 'object': bootstrap, } @@ -72,7 +74,7 @@ def erase_database_view(request): if request.method == 'POST': try: - nuke_database() + Cleanup.execute_all() except Exception, exc: messages.error(request, _(u'Error erasing database; %s') % exc) else: @@ -83,7 +85,7 @@ def erase_database_view(request): 'delete_view': False, 'previous': previous, 'next': next, - 'form_icon': u'radioactivity.png', + 'form_icon': icon_nuke_database, } context['title'] = _(u'Are you sure you wish to erase the entire database and document storage?')