def browse_ecr(request): user = request.user if not user.profile.restricted: # only authenticated users can see all groups and users obj, ctx = bv.get_generic_data(request, search=False) object_list = ECR.objects.all() # this is only relevant for authenticated users ctx["state"] = state = request.GET.get("state", "all") if state == "official": object_list = object_list.\ exclude(lifecycle=models.get_cancelled_lifecycle()).\ filter(state=F("lifecycle__official_state")) ctx["plmobjects"] = False ctime_filter = SimpleDateFilter("ctime", request, ECR, "ctime") object_list = ctime_filter.queryset(request, object_list) mtime_filter = SimpleDateFilter("mtime", request, ECR, "mtime") object_list = mtime_filter.queryset(request, object_list) ctx["time_filters"] = [ctime_filter, mtime_filter] else: ctx = bv.init_ctx("-", "-", "-") ctx.update({ 'is_readable': True, 'restricted': True, 'object_menu': [], 'is_contributor': False, 'navigation_history': [], }) readable = user.ecrs.now().filter(role=models.ROLE_READER) readable |= user.ecrs.now().filter(role=models.ROLE_OWNER) object_list = ECR.objects.filter(id__in=readable) ctx.update(get_pagination(request, object_list, "ECR")) extra_types = [c.__name__ for c in models.IObject.__subclasses__()] ctx.update({ "object_type": _("Browse"), "type": "ECR", "extra_types": extra_types, }) return r2r("browse_ecr.html", ctx, request)
def display_public_3d(request, obj_ref, obj_revi): obj = get_obj("Document3D", obj_ref, obj_revi, request.user) if not obj.published and request.user.is_anonymous(): return redirect_to_login(request.get_full_path()) elif not obj.published and not obj.check_restricted_readable(False): raise Http404 ctx = init_ctx("Document3D", obj_ref, obj_revi) ctx['stl'] = False try: doc_file = obj.files.filter(models.is_stp)[0] except IndexError: doc_file = None javascript_arborescense="" try: doc_file = obj.files.filter(models.is_stl)[0] ctx["stl"] = True ctx["stl_file"] = doc_file except IndexError: pass else: product = obj.get_product(doc_file, True) javascript_arborescense = JSGenerator(product).get_js() ctx.update({ 'is_readable' : True, 'is_contributor': False, # disable the menu and the navigation_history 'object_menu' : [], 'navigation_history' : [], 'obj' : obj, 'javascript_arborescense' : javascript_arborescense, }) return r2r("public_3d_view.html", ctx, request)
def public(request, obj_type, obj_ref, obj_revi, template="public.html"): """ .. versionadded:: 1.1 Public view of the given object, this view is accessible to anonymous users. The object must be a published part or document. Redirects to the login page if the object is not published and the user is not authenticated. :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/public/` .. include:: views_params.txt **Template:** :file:`public.html` **Context:** ``RequestContext`` ``obj`` the controller ``object_attributes`` list of tuples(verbose attribute name, value) ``revisions`` list of published related revisions ``attached`` list of published attached documents and parts """ # do not call get_generic_data to avoid the overhead due # to a possible search and the update of the navigation history obj = get_obj(obj_type, obj_ref, obj_revi, request.user) if not (obj.is_part or obj.is_document): raise Http404 if not obj.published and request.user.is_anonymous(): return redirect_to_login(request.get_full_path()) elif not obj.published and not obj.check_restricted_readable(False): raise Http404 ctx = init_ctx(obj_type, obj_ref, obj_revi) object_attributes = render_attributes(obj, obj.published_attributes) object_attributes.insert( 4, (obj.get_verbose_name("state"), obj.state.name, False)) if request.user.is_anonymous(): test = lambda x: x.published is_contributor = False else: is_contributor = request.user.profile.is_contributor readable = request.user.plmobjectuserlink_user.now().filter(role=models.ROLE_READER)\ .values_list("plmobject_id", flat=True) test = lambda x: x.published or x.id in readable revisions = [rev for rev in obj.get_all_revisions() if test(rev)] if obj.is_part: attached = [ d.document for d in obj.get_attached_documents() if test(d.document) ] else: attached = [d.part for d in obj.get_attached_parts() if test(d.part)] ctx.update({ 'is_readable': True, 'is_contributor': is_contributor, # disable the menu and the navigation_history 'object_menu': [], 'navigation_history': [], 'obj': obj, 'object_attributes': object_attributes, 'revisions': revisions, 'attached': attached, }) return r2r(template, ctx, request)
def browse(request, type="object"): user = request.user if user.is_authenticated() and not user.profile.restricted: # only authenticated users can see all groups and users obj, ctx = get_generic_data(request, search=False) plmtypes = ("object", "part", "topassembly", "document") try: type2manager = { "object": models.PLMObject.objects, "part": models.Part.objects, "topassembly": models.Part.top_assemblies, "document": models.Document.objects, "group": models.GroupInfo.objects, "user": User.objects.select_related("profile"), } manager = type2manager[type] main_cls = manager.model stype = request.GET.get("stype") plmobjects = ctx["plmobjects"] = type in plmtypes if plmobjects and stype and stype != "Object": cls = models.get_all_plmobjects()[stype] if not issubclass(cls, main_cls): raise Http404 if type == "topassembly": manager = cls.top_assemblies else: manager = cls.objects else: stype = None ctx["stype"] = stype except KeyError: raise Http404 object_list = manager.all() # this is only relevant for authenticated users ctx["state"] = state = request.GET.get("state", "all") if plmobjects: ctx["subtypes"] = models.get_subclasses(main_cls) if type == "object": ctx["subtypes"][0] = (0, models.PLMObject, "Object") if state != models.get_cancelled_state().name: object_list = object_list.exclude_cancelled() if state == "official": object_list = object_list.officials() elif state == "published": object_list = object_list.filter(published=True) elif state != "all": object_list = object_list.filter(state=state) ctx["states"] = models.State.objects.order_by("name").values_list( "name", flat=True) ctx["template"] = request.GET.get("template", "0") if ctx["template"] == "1": object_list = object_list.filter( lifecycle__type=models.Lifecycle.TEMPLATE) # date filters model = object_list.model ctime = "date_joined" if type == "user" else "ctime" ctime_filter = SimpleDateFilter(ctime, request, model, "ctime") object_list = ctime_filter.queryset(request, object_list) ctx["time_filters"] = [ctime_filter] if plmobjects: mtime_filter = SimpleDateFilter("mtime", request, model, "mtime") object_list = mtime_filter.queryset(request, object_list) ctx["time_filters"].append(mtime_filter) else: try: manager = { "object": models.PLMObject.objects, "part": models.Part.objects, "topassembly": models.Part.top_assemblies, "document": models.Document.objects, }[type] except KeyError: raise Http404 ctx = init_ctx("-", "-", "-") ctx.update({ 'is_readable': True, 'is_contributor': False, 'plmobjects': True, 'restricted': True, 'object_menu': [], 'navigation_history': [], }) query = Q(published=True) if user.is_authenticated(): readable = user.plmobjectuserlink_user.now().filter( role=models.ROLE_READER) query |= Q(id__in=readable.values_list("plmobject_id", flat=True)) object_list = manager.filter(query).exclude_cancelled() ctx.update(get_pagination(request, object_list, type)) extra_types = [c.__name__ for c in models.IObject.__subclasses__()] ctx.update({ "object_type": _("Browse"), "type": type, "extra_types": extra_types, }) return r2r("browse.html", ctx, request)
def public(request, obj_type, obj_ref, obj_revi, template="public.html"): """ .. versionadded:: 1.1 Public view of the given object, this view is accessible to anonymous users. The object must be a published part or document. Redirects to the login page if the object is not published and the user is not authenticated. :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/public/` .. include:: views_params.txt **Template:** :file:`public.html` **Context:** ``RequestContext`` ``obj`` the controller ``object_attributes`` list of tuples(verbose attribute name, value) ``revisions`` list of published related revisions ``attached`` list of published attached documents and parts """ # do not call get_generic_data to avoid the overhead due # to a possible search and the update of the navigation history obj = get_obj(obj_type, obj_ref, obj_revi, request.user) if not (obj.is_part or obj.is_document): raise Http404 if not obj.published and request.user.is_anonymous(): return redirect_to_login(request.get_full_path()) elif not obj.published and not obj.check_restricted_readable(False): raise Http404 ctx = init_ctx(obj_type, obj_ref, obj_revi) object_attributes = render_attributes(obj, obj.published_attributes) object_attributes.insert(4, (obj.get_verbose_name("state"), obj.state.name, False)) if request.user.is_anonymous(): test = lambda x: x.published is_contributor = False else: is_contributor = request.user.profile.is_contributor readable = request.user.plmobjectuserlink_user.now().filter(role=models.ROLE_READER)\ .values_list("plmobject_id", flat=True) test = lambda x: x.published or x.id in readable revisions = [rev for rev in obj.get_all_revisions() if test(rev)] if obj.is_part: attached = [d.document for d in obj.get_attached_documents() if test(d.document)] else: attached = [d.part for d in obj.get_attached_parts() if test(d.part)] ctx.update({ 'is_readable' : True, 'is_contributor': is_contributor, # disable the menu and the navigation_history 'object_menu' : [], 'navigation_history' : [], 'obj' : obj, 'object_attributes': object_attributes, 'revisions' : revisions, 'attached' : attached, }) return r2r(template, ctx, request)
def browse(request, type="object"): user = request.user if user.is_authenticated() and not user.profile.restricted: # only authenticated users can see all groups and users obj, ctx = get_generic_data(request, search=False) plmtypes = ("object", "part", "topassembly", "document") try: type2manager = { "object" : models.PLMObject.objects, "part" : models.Part.objects, "topassembly" : models.Part.top_assemblies, "document" : models.Document.objects, "group" : models.GroupInfo.objects, "user" : User.objects.select_related("profile"), } manager = type2manager[type] main_cls = manager.model stype = request.GET.get("stype") plmobjects = ctx["plmobjects"] = type in plmtypes if plmobjects and stype and stype != "Object": cls = models.get_all_plmobjects()[stype] if not issubclass(cls, main_cls): raise Http404 if type == "topassembly": manager = cls.top_assemblies else: manager = cls.objects else: stype = None ctx["stype"] = stype except KeyError: raise Http404 object_list = manager.all() # this is only relevant for authenticated users ctx["state"] = state = request.GET.get("state", "all") if plmobjects: ctx["subtypes"] = models.get_subclasses(main_cls) if type == "object": ctx["subtypes"][0] = (0, models.PLMObject, "Object") if state != models.get_cancelled_state().name: object_list = object_list.exclude_cancelled() if state == "official": object_list = object_list.officials() elif state == "published": object_list = object_list.filter(published=True) elif state != "all": object_list = object_list.filter(state=state) ctx["states"] = models.State.objects.order_by("name").values_list("name", flat=True) ctx["template"] = request.GET.get("template", "0") if ctx["template"] == "1": object_list = object_list.filter(lifecycle__type=models.Lifecycle.TEMPLATE) # date filters model = object_list.model ctime = "date_joined" if type == "user" else "ctime" ctime_filter = SimpleDateFilter(ctime, request, model, "ctime") object_list = ctime_filter.queryset(request, object_list) ctx["time_filters"] = [ctime_filter] if plmobjects: mtime_filter = SimpleDateFilter("mtime", request, model, "mtime") object_list = mtime_filter.queryset(request, object_list) ctx["time_filters"].append(mtime_filter) else: try: manager = { "object" : models.PLMObject.objects, "part" : models.Part.objects, "topassembly" : models.Part.top_assemblies, "document" : models.Document.objects, }[type] except KeyError: raise Http404 ctx = init_ctx("-", "-", "-") ctx.update({ 'is_readable' : True, 'is_contributor': False, 'plmobjects' : True, 'restricted' : True, 'object_menu' : [], 'navigation_history' : [], }) query = Q(published=True) if user.is_authenticated(): readable = user.plmobjectuserlink_user.now().filter(role=models.ROLE_READER) query |= Q(id__in=readable.values_list("plmobject_id", flat=True)) object_list = manager.filter(query).exclude_cancelled() ctx.update(get_pagination(request, object_list, type)) extra_types = [c.__name__ for c in models.IObject.__subclasses__()] ctx.update({ "object_type" : _("Browse"), "type" : type, "extra_types" : extra_types, }) return r2r("browse.html", ctx, request)