def hardware_add(request, type_id=None, object_id=None): if object_id is None: web = webs.hardware_web() breadcrumbs = web.get_add_breadcrumbs() else: object = get_object_or_404(models.hardware, pk=object_id) object = object.get_object() web = webs.get_web_from_object(object) breadcrumbs = web.get_view_breadcrumbs(object) breadcrumbs.append(webs.breadcrumb(web.get_add_to_instance_url(object,type_id),"add hardware")) if request.method == 'POST': form = forms.hardware_type_form(request.POST, request.FILES) if form.is_valid(): new_type = form.cleaned_data['type'] url = web.get_add_url(new_type) url = request.GET.get("next",url) return HttpResponseRedirect(url) else: form = forms.hardware_type_form() return render_to_response("lintory/hardware_type.html", { 'breadcrumbs': breadcrumbs, 'form' : form, 'media' : form.media, },context_instance=RequestContext(request))
def show_hardware_list(context, object_list, sort="hardware_sort"): request = context['request'] web = webs.hardware_web() dict = defaults(context) dict['table'] = tables.hardware(request, web, object_list,request.GET.get(sort)) dict['rows'] = dict['table'].rows dict['web'] = web dict['sort'] = sort return dict
def hardware_install(request, object_id): object = get_object_or_404(models.hardware, pk=object_id) error_list = [ ] pks = [] if request.method == 'POST': pks = request.POST.getlist('pk') for pk in pks: requested_object = get_object_or_404(models.hardware, pk=pk) if requested_object.installed_on is not None: if requested_object.installed_on.pk != object.pk: error_list.append(u"Cannot install '%s' as it is already installed on another computer"%(requested_object)) else: requested_object.installed_on = object requested_object.save() web = webs.hardware_web() filter = filters.hardware(request.GET or {'is_installed': '3'}) table = tables.hardware_list_form(pks, request, web, filter.qs, order_by=request.GET.get('sort')) return web.object_list(request, filter.form, table, template="lintory/hardware_list_form.html", context={ 'object': object, 'error_list': error_list })
def hardware_list(request): web = webs.hardware_web() filter = filters.hardware(request.GET or None) table = tables.hardware(request, web, filter.qs, order_by=request.GET.get('sort')) return web.object_list(request, filter.form, table)