def show_item(request, app_name='', model_name='', object_id=None, template='dorsale/show_item.html', _c=0): """ Display one object: `app_name.model_name(id=object_id)`. Render 404 if object is not available. Allow customization by `template`. Available variables in the template: :item: the requested object :item_type: ContentType of the requested object :form: ModelForm for this object :notes: Notes on this object """ if not object_id: return render_404(request, locals()) object_model = get_model(app_name, model_name) try: item = object_model.objects.mine(request.user.id).get(pk=object_id) item_type = ContentType.objects.get_for_model(item) if hasattr(item, 'notes'): notes = item.notes.all() # else: # notes = Note.objects.filter(content_type__pk=item_type.id, object_id=object_id) except: return render_404(request, locals()) form = ModelFormFactory(object_model, user=request.user, instance=item, disabled=True) if not form.visible_fields() and _c < 3: # sometimes it works only in the second try, why? return show_item(request, app_name, model_name, object_id, template, _c + 1) return render(request, template, locals())
def show_item(request, app_name='', model_name='', object_id=None, template='dorsale/show_item.html', _c=0): """ Display one object: `app_name.model_name(id=object_id)`. Render 404 if object is not available. Allow customization by `template`. Available variables in the template: :item: the requested object :item_type: ContentType of the requested object :form: ModelForm for this object :notes: Notes on this object """ if not object_id: return render_404(request, locals()) object_model = get_model(app_name, model_name) try: item = object_model.objects.mine(request.user.id).get(pk=object_id) item_type = ContentType.objects.get_for_model(item) if hasattr(item, 'notes'): notes = item.notes.all() # else: # notes = Note.objects.filter(content_type__pk=item_type.id, object_id=object_id) except: return render_404(request, locals()) form = ModelFormFactory(object_model, user=request.user, instance=item, disabled=True) if not form.visible_fields() and _c < 3: # sometimes it works only in the second try, why? return show_item(request, app_name, model_name, object_id, template, _c + 1) return render_to_response(template, locals(), context_instance=RequestContext(request))