Ejemplo n.º 1
0
 def extra_context(self):
     extra = super(OpenPLMSearchView, self).extra_context()
     obj, ctx = get_generic_data(self.request, search=False)
     ctx["type"] = type = self.request.session["type"]
     ctx["object_type"] = _("Search")
     ctx["suggestion"] = self.suggestion
     ctx["extra_types"] = [c.__name__ for c in models.IObject.__subclasses__()]
     try:
         cls = models.get_all_plmobjects()[type]
         if issubclass(cls, models.PLMObject):
             main_cls = models.Part if issubclass(cls, models.Part) else models.Document
             ctx["subtypes"] = models.get_subclasses(main_cls)
     except KeyError:
         pass
     extra.update(ctx)
     return extra
Ejemplo n.º 2
0
 def extra_context(self):
     extra = super(OpenPLMSearchView, self).extra_context()
     obj, ctx = get_generic_data(self.request, search=False)
     ctx["type"] = type = self.request.session["type"]
     ctx["object_type"] = _("Search")
     ctx["suggestion"] = self.suggestion
     ctx["extra_types"] = [
         c.__name__ for c in models.IObject.__subclasses__()
     ]
     try:
         cls = models.get_all_plmobjects()[type]
         if issubclass(cls, models.PLMObject):
             main_cls = models.Part if issubclass(
                 cls, models.Part) else models.Document
             ctx["subtypes"] = models.get_subclasses(main_cls)
     except KeyError:
         pass
     extra.update(ctx)
     return extra
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)