Initial import of the database bootstrap app
This commit is contained in:
10
apps/bootstrap/__init__.py
Normal file
10
apps/bootstrap/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from project_setup.api import register_setup
|
||||||
|
from navigation.api import register_links#, register_sidebar_template
|
||||||
|
|
||||||
|
from .links import database_bootstrap, bootstrap_execute
|
||||||
|
from .api import BootstrapSimple
|
||||||
|
|
||||||
|
register_setup(database_bootstrap)
|
||||||
|
register_links(BootstrapSimple, [bootstrap_execute])
|
||||||
79
apps/bootstrap/api.py
Normal file
79
apps/bootstrap/api.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.utils.translation import ugettext
|
||||||
|
|
||||||
|
from metadata.models import MetadataType, MetadataSet
|
||||||
|
from document_indexing.models import Index, IndexTemplateNode
|
||||||
|
|
||||||
|
bootstrap_options = {}
|
||||||
|
|
||||||
|
|
||||||
|
class BootstrapBase(object):
|
||||||
|
name = None
|
||||||
|
label = ''
|
||||||
|
description = ''
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.label)
|
||||||
|
|
||||||
|
|
||||||
|
class BootstrapSimple(BootstrapBase):
|
||||||
|
name = 'simple'
|
||||||
|
label = _(u'Simple')
|
||||||
|
description = _(u'A simple setup providing an uploaded date metadata and index plus an alphabetic index based on document filenames.')
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
# Create metadata types
|
||||||
|
date = MetadataType.objects.create(name='upload_date', title=ugettext(u'Upload date'), default='current_date()')
|
||||||
|
|
||||||
|
# Create a segmented date index
|
||||||
|
index = Index.objects.create(name='date_tree', title=ugettext(u'Segmented date index'), enabled=True)
|
||||||
|
|
||||||
|
# Create index template
|
||||||
|
#node1 = IndexTemplateNode
|
||||||
|
|
||||||
|
|
||||||
|
for bootstrap in [BootstrapSimple()]:
|
||||||
|
bootstrap_options[bootstrap.name] = bootstrap
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Index(models.Model):
|
||||||
|
name = models.CharField(unique=True, max_length=64, verbose_name=_(u'name'), help_text=_(u'Internal name used to reference this index.'))
|
||||||
|
title = models.CharField(unique=True, max_length=128, verbose_name=_(u'title'), help_text=_(u'The name that will be visible to users.'))
|
||||||
|
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'), help_text=_(u'Causes this index to be visible and updated when document data changes.'))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def template_root(self):
|
||||||
|
return self.indextemplatenode_set.get(parent=None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def instance_root(self):
|
||||||
|
return self.template_root.indexinstancenode_set.get()
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
@models.permalink
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return ('index_instance_node_view', [self.instance_root.pk])
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
super(Index, self).save(*args, **kwargs)
|
||||||
|
index_template_node_root, created = IndexTemplateNode.objects.get_or_create(parent=None, index=self)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _(u'index')
|
||||||
|
verbose_name_plural = _(u'indexes')
|
||||||
|
|
||||||
|
|
||||||
|
class IndexTemplateNode(MPTTModel):
|
||||||
|
parent = TreeForeignKey('self', null=True, blank=True, related_name='index_template_node')
|
||||||
|
index = models.ForeignKey(Index, verbose_name=_(u'index'))
|
||||||
|
expression = models.CharField(max_length=128, verbose_name=_(u'indexing expression'), help_text=_(u'Enter a python string expression to be evaluated.'))
|
||||||
|
# % available_indexing_functions_string)
|
||||||
|
enabled = models.BooleanField(default=True, verbose_name=_(u'enabled'), help_text=_(u'Causes this node to be visible and updated when document data changes.'))
|
||||||
|
link_documents = models.BooleanField(default=False, verbose_name=_(u'link documents'), help_text=_(u'Check this option to have this node act as a container for documents and not as a parent for further nodes.'))
|
||||||
|
"""
|
||||||
|
|
||||||
9
apps/bootstrap/links.py
Normal file
9
apps/bootstrap/links.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
def is_superuser(context):
|
||||||
|
return context['request'].user.is_staff or context['request'].user.is_superuser
|
||||||
|
|
||||||
|
|
||||||
|
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']}
|
||||||
12
apps/bootstrap/models.py
Normal file
12
apps/bootstrap/models.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
#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/database_lightning.png
Executable file
BIN
apps/bootstrap/static/images/icons/database_lightning.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
6
apps/bootstrap/urls.py
Normal file
6
apps/bootstrap/urls.py
Normal file
@@ -0,0 +1,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<bootstrap_name>\w+)/execute/$', 'bootstrap_execute', (), 'bootstrap_execute'),
|
||||||
|
)
|
||||||
59
apps/bootstrap/views.py
Normal file
59
apps/bootstrap/views.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
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, get_object_or_404
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.contrib import messages
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
|
from .api import bootstrap_options
|
||||||
|
|
||||||
|
|
||||||
|
def bootstrap_type_list(request):
|
||||||
|
# TODO: Check for superadmin
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'object_list': bootstrap_options.values(),
|
||||||
|
'title': _(u'database bootstrap setups'),
|
||||||
|
'hide_link': True,
|
||||||
|
'extra_columns': [
|
||||||
|
{'name': _(u'description'), 'attribute': 'description'},
|
||||||
|
#{'name': _(u'label'), 'attribute': encapsulate(lambda document: document.checkout_info().expiration_datetime)},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
return render_to_response('generic_list.html', context,
|
||||||
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
def bootstrap_execute(request, bootstrap_name):
|
||||||
|
bootstrap = bootstrap_options[bootstrap_name]
|
||||||
|
|
||||||
|
post_action_redirect = reverse('bootstrap_type_list')
|
||||||
|
|
||||||
|
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:
|
||||||
|
bootstrap.execute()
|
||||||
|
except Exception, exc:
|
||||||
|
messages.error(request, _(u'Error executing bootstrap setup; %s') % exc)
|
||||||
|
else:
|
||||||
|
messages.success(request, _(u'Bootstrap setup "%s" executed successfully.') % bootstrap)
|
||||||
|
return HttpResponseRedirect(next)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'object_name': _(u'bootstrap setup'),
|
||||||
|
'delete_view': False,
|
||||||
|
'previous': previous,
|
||||||
|
'next': next,
|
||||||
|
#'form_icon': u'basket_remove.png',
|
||||||
|
'object': bootstrap,
|
||||||
|
}
|
||||||
|
|
||||||
|
context['title'] = _(u'Are you sure you wish to execute the database bootstrap named: %s?') % bootstrap.label
|
||||||
|
|
||||||
|
return render_to_response('generic_confirm.html', context,
|
||||||
|
context_instance=RequestContext(request))
|
||||||
@@ -168,6 +168,7 @@ INSTALLED_APPS = (
|
|||||||
'documents',
|
'documents',
|
||||||
'linking',
|
'linking',
|
||||||
'document_indexing',
|
'document_indexing',
|
||||||
|
'bootstrap',
|
||||||
'document_acls',
|
'document_acls',
|
||||||
'ocr',
|
'ocr',
|
||||||
'sources',
|
'sources',
|
||||||
|
|||||||
1
urls.py
1
urls.py
@@ -34,6 +34,7 @@ urlpatterns = patterns('',
|
|||||||
(r'^checkouts/', include('checkouts.urls')),
|
(r'^checkouts/', include('checkouts.urls')),
|
||||||
(r'^installation/', include('installation.urls')),
|
(r'^installation/', include('installation.urls')),
|
||||||
(r'^scheduler/', include('scheduler.urls')),
|
(r'^scheduler/', include('scheduler.urls')),
|
||||||
|
(r'^bootstrap/', include('bootstrap.urls')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user