def type_add(request, response_format='html'): "ItemType add" if not request.user.get_profile().is_admin('maker.infrastructure'): return user_denied(request, message="You don't have administrator access to the Infrastructure module", response_format=response_format) if request.POST: if not 'cancel' in request.POST: item_type = ItemType() form = ItemTypeForm(request.user.get_profile(), request.POST, instance=item_type) if form.is_valid(): item = form.save(request) item_type.set_user_from_request(request) return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item.id])) else: return HttpResponseRedirect(reverse('infrastructure_settings_view')) else: form = ItemTypeForm(request.user.get_profile()) context = _get_default_context(request) context.update({'form': form}) return render_to_response('infrastructure/item_type_add', context, context_instance=RequestContext(request), response_format=response_format)
def type_edit(request, type_id, response_format='html'): "ItemType edit" item_type = get_object_or_404(ItemType, pk=type_id) if not request.user.get_profile().has_permission(item_type, mode='w'): return user_denied(request, message="You don't have access to this Item Type", response_format=response_format) infrastructure = Object.filter_by_request(request, Item.objects.filter(item_type=item_type).order_by('name')) if request.POST: if not 'cancel' in request.POST: form = ItemTypeForm(request.user.get_profile(), request.POST, instance=item_type) if form.is_valid(): item_type = form.save(request) return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item_type.id])) else: return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item_type.id])) else: form = ItemTypeForm(request.user.get_profile(), instance=item_type) context = _get_default_context(request) context.update({'infrastructure': infrastructure, 'form': form, 'item_type': item_type}) return render_to_response('infrastructure/item_type_edit', context, context_instance=RequestContext(request), response_format=response_format)