Added state list, create, edit, delete views

This commit is contained in:
Roberto Rosario
2012-03-16 01:55:21 -04:00
parent ffb5fc8286
commit 89aeb8ad7c
6 changed files with 153 additions and 13 deletions

View File

@@ -7,8 +7,10 @@ from project_setup.api import register_setup
from .permissions import (PERMISSION_WORKFLOW_SETUP_VIEW, from .permissions import (PERMISSION_WORKFLOW_SETUP_VIEW,
PERMISSION_WORKFLOW_SETUP_CREATE, PERMISSION_WORKFLOW_SETUP_EDIT, PERMISSION_WORKFLOW_SETUP_CREATE, PERMISSION_WORKFLOW_SETUP_EDIT,
PERMISSION_WORKFLOW_SETUP_DELETE) PERMISSION_WORKFLOW_SETUP_DELETE, PERMISSION_STATE_SETUP_VIEW,
from .models import Workflow PERMISSION_STATE_SETUP_CREATE, PERMISSION_STATE_SETUP_EDIT,
PERMISSION_STATE_SETUP_DELETE)
from .models import Workflow, State, Transition
setup_workflow_link = {'text': _(u'workflows'), 'view': 'setup_workflow_list', 'icon': 'chart_organisation.png', 'permissions': [PERMISSION_WORKFLOW_SETUP_VIEW]} setup_workflow_link = {'text': _(u'workflows'), 'view': 'setup_workflow_list', 'icon': 'chart_organisation.png', 'permissions': [PERMISSION_WORKFLOW_SETUP_VIEW]}
@@ -17,9 +19,18 @@ setup_workflow_create_link = {'text': _(u'create new'), 'view': 'setup_workflow_
setup_workflow_edit_link = {'text': _(u'edit'), 'view': 'setup_workflow_edit', 'args': 'object.pk', 'famfam': 'chart_organisation', 'permissions': [PERMISSION_WORKFLOW_SETUP_EDIT]} setup_workflow_edit_link = {'text': _(u'edit'), 'view': 'setup_workflow_edit', 'args': 'object.pk', 'famfam': 'chart_organisation', 'permissions': [PERMISSION_WORKFLOW_SETUP_EDIT]}
setup_workflow_delete_link = {'text': _(u'delete'), 'view': 'setup_workflow_delete', 'args': 'object.pk', 'famfam': 'chart_organisation_delete', 'permissions': [PERMISSION_WORKFLOW_SETUP_DELETE]} setup_workflow_delete_link = {'text': _(u'delete'), 'view': 'setup_workflow_delete', 'args': 'object.pk', 'famfam': 'chart_organisation_delete', 'permissions': [PERMISSION_WORKFLOW_SETUP_DELETE]}
setup_state_list_link = {'text': _(u'state list'), 'view': 'setup_state_list', 'famfam': 'transmit', 'permissions': [PERMISSION_STATE_SETUP_VIEW]}
setup_state_create_link = {'text': _(u'create new'), 'view': 'setup_state_create', 'famfam': 'transmit_add', 'permissions': [PERMISSION_STATE_SETUP_CREATE]}
setup_state_edit_link = {'text': _(u'edit'), 'view': 'setup_state_edit', 'args': 'object.pk', 'famfam': 'transmit_edit', 'permissions': [PERMISSION_STATE_SETUP_EDIT]}
setup_state_delete_link = {'text': _(u'delete'), 'view': 'setup_state_delete', 'args': 'object.pk', 'famfam': 'transmit_delete', 'permissions': [PERMISSION_STATE_SETUP_DELETE]}
register_links(Workflow, [setup_workflow_edit_link, setup_workflow_delete_link]) register_links(Workflow, [setup_workflow_edit_link, setup_workflow_delete_link])
register_links([Workflow, 'setup_workflow_list', 'setup_workflow_create'], [setup_workflow_list_link], menu_name=u'form_header') register_links([Workflow, State, 'setup_workflow_list', 'setup_workflow_create', 'setup_state_list'], [setup_workflow_list_link], menu_name=u'form_header')
register_links([Workflow, 'setup_workflow_list', 'setup_workflow_create'], [setup_workflow_create_link], menu_name=u'secondary_menu') register_links([Workflow, 'setup_workflow_list', 'setup_workflow_create'], [setup_workflow_create_link], menu_name=u'secondary_menu')
#register_multi_item_links(['user_list'], [user_multiple_set_password, user_multiple_delete])
register_links(State, [setup_state_edit_link, setup_state_delete_link])
register_links([State, Workflow, 'setup_state_list', 'setup_workflow_list', 'setup_workflow_create'], [setup_state_list_link], menu_name=u'form_header')
register_links([State, 'setup_state_list', 'setup_state_create'], [setup_state_create_link], menu_name=u'secondary_menu')
register_setup(setup_workflow_link) register_setup(setup_workflow_link)

View File

@@ -3,9 +3,14 @@ from __future__ import absolute_import
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from .models import Workflow from .models import Workflow, State, Transition
class WorkflowSetupForm(forms.ModelForm): class WorkflowSetupForm(forms.ModelForm):
class Meta: class Meta:
model = Workflow model = Workflow
class StateSetupForm(forms.ModelForm):
class Meta:
model = State

View File

@@ -4,9 +4,15 @@ from django.utils.translation import ugettext_lazy as _
from permissions.models import PermissionNamespace, Permission from permissions.models import PermissionNamespace, Permission
user_management_namespace = PermissionNamespace('workflows', _(u'Workflows')) namespace = PermissionNamespace('workflows', _(u'Workflows'))
PERMISSION_WORKFLOW_SETUP_VIEW = Permission.objects.register(namespace, 'workflow_setup_view', _(u'View existing workflow templates'))
PERMISSION_WORKFLOW_SETUP_CREATE = Permission.objects.register(namespace, 'workflow_setup_create', _(u'Create new workflow templates'))
PERMISSION_WORKFLOW_SETUP_EDIT = Permission.objects.register(namespace, 'workflow_setup_edit', _(u'Edit existing workflow templates'))
PERMISSION_WORKFLOW_SETUP_DELETE = Permission.objects.register(namespace, 'workflow_setup_delete', _(u'Delete existing workflow templates'))
PERMISSION_STATE_SETUP_VIEW = Permission.objects.register(namespace, 'state_setup_view', _(u'View existing states'))
PERMISSION_STATE_SETUP_CREATE = Permission.objects.register(namespace, 'state_setup_create', _(u'Create new state templates'))
PERMISSION_STATE_SETUP_EDIT = Permission.objects.register(namespace, 'state_setup_edit', _(u'Edit existing state templates'))
PERMISSION_STATE_SETUP_DELETE = Permission.objects.register(namespace, 'state_setup_delete', _(u'Delete existing state templates'))
PERMISSION_WORKFLOW_SETUP_VIEW = Permission.objects.register(user_management_namespace, 'workflow_setup_view', _(u'View existing workflow templates'))
PERMISSION_WORKFLOW_SETUP_CREATE = Permission.objects.register(user_management_namespace, 'workflow_setup_create', _(u'Create new workflow templates'))
PERMISSION_WORKFLOW_SETUP_EDIT = Permission.objects.register(user_management_namespace, 'workflow_setup_edit', _(u'Edit existing workflow templates'))
PERMISSION_WORKFLOW_SETUP_DELETE = Permission.objects.register(user_management_namespace, 'workflow_setup_delete', _(u'Delete existing workflow templates'))

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -5,4 +5,9 @@ urlpatterns = patterns('workflows.views',
url(r'^setup/workflow/create/$', 'setup_workflow_create', (), 'setup_workflow_create'), url(r'^setup/workflow/create/$', 'setup_workflow_create', (), 'setup_workflow_create'),
url(r'^setup/workflow/(?P<workflow_pk>\d+)/edit/$', 'setup_workflow_edit', (), 'setup_workflow_edit'), url(r'^setup/workflow/(?P<workflow_pk>\d+)/edit/$', 'setup_workflow_edit', (), 'setup_workflow_edit'),
url(r'^setup/workflow/(?P<workflow_pk>\d+)/delete/$', 'setup_workflow_delete', (), 'setup_workflow_delete'), url(r'^setup/workflow/(?P<workflow_pk>\d+)/delete/$', 'setup_workflow_delete', (), 'setup_workflow_delete'),
url(r'^setup/state/list/$', 'setup_state_list', (), 'setup_state_list'),
url(r'^setup/state/create/$', 'setup_state_create', (), 'setup_state_create'),
url(r'^setup/state/(?P<state_pk>\d+)/edit/$', 'setup_state_edit', (), 'setup_state_edit'),
url(r'^setup/state/(?P<state_pk>\d+)/delete/$', 'setup_state_delete', (), 'setup_state_delete'),
) )

View File

@@ -18,11 +18,13 @@ from common.utils import encapsulate
#from common.widgets import two_state_template #from common.widgets import two_state_template
#from acls.models import AccessEntry #from acls.models import AccessEntry
from .models import Workflow from .models import Workflow, State, Transition
from .forms import WorkflowSetupForm from .forms import WorkflowSetupForm, StateSetupForm
from .permissions import (PERMISSION_WORKFLOW_SETUP_VIEW, from .permissions import (PERMISSION_WORKFLOW_SETUP_VIEW,
PERMISSION_WORKFLOW_SETUP_CREATE, PERMISSION_WORKFLOW_SETUP_EDIT, PERMISSION_WORKFLOW_SETUP_CREATE, PERMISSION_WORKFLOW_SETUP_EDIT,
PERMISSION_WORKFLOW_SETUP_DELETE) PERMISSION_WORKFLOW_SETUP_DELETE, PERMISSION_STATE_SETUP_VIEW,
PERMISSION_STATE_SETUP_CREATE, PERMISSION_STATE_SETUP_EDIT,
PERMISSION_STATE_SETUP_DELETE)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -139,3 +141,114 @@ def setup_workflow_delete(request, workflow_pk=None, workflow_pk_list=None):
return render_to_response('generic_confirm.html', context, return render_to_response('generic_confirm.html', context,
context_instance=RequestContext(request)) context_instance=RequestContext(request))
# States
def setup_state_list(request):
Permission.objects.check_permissions(request.user, [PERMISSION_STATE_SETUP_VIEW])
context = {
'object_list': State.objects.all(),
'title': _(u'states'),
'hide_link': True,
#'list_object_variable_name': 'source',
#'source_type': source_type,
#'extra_columns': [
# {'name': _(u'Initial state'), 'attribute': encapsulate(lambda workflow: workflow.initial_state or _(u'None'))},
#],
}
return render_to_response('generic_list.html', context,
context_instance=RequestContext(request))
def setup_state_create(request):
Permission.objects.check_permissions(request.user, [PERMISSION_STATE_SETUP_CREATE])
redirect_url = reverse('setup_state_list')
if request.method == 'POST':
form = StateSetupForm(request.POST)
if form.is_valid():
state = form.save()
messages.success(request, _(u'State created succesfully.'))
return HttpResponseRedirect(redirect_url)
else:
form = StateSetupForm()
return render_to_response('generic_form.html', {
'title': _(u'create state'),
'form': form,
},
context_instance=RequestContext(request))
def setup_state_edit(request, state_pk):
Permission.objects.check_permissions(request.user, [PERMISSION_STATE_SETUP_EDIT])
state = get_object_or_404(State, pk=state_pk)
if request.method == 'POST':
form = StateSetupForm(instance=state, data=request.POST)
if form.is_valid():
form.save()
messages.success(request, _(u'State "%s" updated successfully.') % state)
return HttpResponseRedirect(reverse('setup_state_list'))
else:
form = StateSetupForm(instance=state)
return render_to_response('generic_form.html', {
'title': _(u'edit state: %s') % state,
'form': form,
'object': state,
'object_name': _(u'state'),
},
context_instance=RequestContext(request))
def setup_state_delete(request, state_pk=None, state_pk_list=None):
post_action_redirect = None
if state_pk:
states = [get_object_or_404(State, pk=state_pk)]
post_action_redirect = reverse('setup_state_list')
elif state_pk_list:
states = [get_object_or_404(State, pk=state_pk) for state_pk in state_pk_list.split(',')]
else:
messages.error(request, _(u'Must provide at least one state.'))
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
try:
Permission.objects.check_permissions(request.user, [PERMISSION_STATE_SETUP_DELETE])
except PermissionDenied:
states = AccessEntry.objects.filter_objects_by_access(PERMISSION_STATE_SETUP_DELETE, request.user, states)
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':
for state in states:
try:
state.delete()
messages.success(request, _(u'States "%s" deleted successfully.') % state)
except Exception, e:
messages.error(request, _(u'Error deleting state "%(state)s": %(error)s') % {
'state': state, 'error': e
})
return HttpResponseRedirect(next)
context = {
'object_name': _(u'state'),
'delete_view': True,
'previous': previous,
'next': next,
'form_icon': u'transmit_delete.png',
}
if len(states) == 1:
context['object'] = states[0]
context['title'] = _(u'Are you sure you wish to delete the state: %s?') % ', '.join([unicode(d) for d in states])
context['message'] = _('Will be removed from all documents.')
elif len(states) > 1:
context['title'] = _(u'Are you sure you wish to delete the states: %s?') % ', '.join([unicode(d) for d in states])
context['message'] = _('Will be removed from all documents.')
return render_to_response('generic_confirm.html', context,
context_instance=RequestContext(request))