Ejemplo n.º 1
0
    def setUp(self):
        super(PartDocControllerTestCase, self).setUp()
        self.other_owner = self.get_contributor("Otherowner")
        self.other_owner.groups.add(self.group)
        self.other_owner.save()

        lcl = LifecycleList("dpop", "official", "draft", "proposed", "official", "deprecated")
        lc = models.Lifecycle.from_lifecyclelist(lcl)
        self.states = dict((s, models.State.objects.get(name=s)) for s in lcl)
        self.states["cancelled"] = models.get_cancelled_state()
        self.lifecycles = dict.fromkeys(lcl, lc)
        self.lifecycles["cancelled"] = models.get_cancelled_lifecycle()
        data = self.DATA.copy()
        data["lifecycle"] = lc
        self.part = PartController.create("p1", "Part", "a", self.user, data, True, True)
        self.doc = DocumentController.create("d1", "Document", "a", self.user, data, True, True)
Ejemplo n.º 2
0
    def cancel(self):
        """
        Cancels the object:

            * Its lifecycle becomes "cancelled".
            * Its owner becomes the company.
            * It removes all signer.
        """
        company = models.User.objects.get(username=settings.COMPANY)
        self.lifecycle = models.get_cancelled_lifecycle()
        self.state = models.get_cancelled_state()
        self.set_owner(company, True)
        self.users.filter(role__startswith=models.ROLE_SIGN).end()
        self.plmobjects.end()
        self._clear_approvals()
        self.save(with_history=False)
        self._save_histo("Cancel", "Object cancelled")
Ejemplo n.º 3
0
    def cancel(self):
        """
        Cancels the object:

            * Its lifecycle becomes "cancelled".
            * Its owner becomes the company.
            * It removes all signer.
        """
        company = models.User.objects.get(username=settings.COMPANY)
        self.lifecycle = models.get_cancelled_lifecycle()
        self.state = models.get_cancelled_state()
        self.set_owner(company, True)
        self.users.filter(role__startswith=models.ROLE_SIGN).end()
        self._clear_approvals()
        self.save(with_history=False)
        self._save_histo("cancelled", "%s (%s//%s//%s) cancelled"%(self.object.name, self.object.type, self.object.reference, self.object.revision))
        self._update_state_history()
Ejemplo n.º 4
0
    def setUp(self):
        super(PartDocControllerTestCase, self).setUp()
        self.other_owner = self.get_contributor("Otherowner")
        self.other_owner.groups.add(self.group)
        self.other_owner.save()

        lcl = LifecycleList("dpop", "official", "draft", "proposed",
                            "official", "deprecated")
        lc = models.Lifecycle.from_lifecyclelist(lcl)
        self.states = dict((s, models.State.objects.get(name=s)) for s in lcl)
        self.states["cancelled"] = models.get_cancelled_state()
        self.lifecycles = dict.fromkeys(lcl, lc)
        self.lifecycles["cancelled"] = models.get_cancelled_lifecycle()
        data = self.DATA.copy()
        data["lifecycle"] = lc
        self.part = PartController.create("p1", "Part", "a", self.user, data,
                                          True, True)
        self.doc = DocumentController.create("d1", "Document", "a", self.user,
                                             data, True, True)
Ejemplo n.º 5
0
    def cancel(self):
        """
        Cancels the object:

            * Its lifecycle becomes "cancelled".
            * Its owner becomes the company.
            * It removes all signer.
        """
        company = models.User.objects.get(username=settings.COMPANY)
        self.lifecycle = models.get_cancelled_lifecycle()
        self.state = models.get_cancelled_state()
        self.set_owner(company, True)
        self.users.filter(role__startswith=models.ROLE_SIGN).end()
        self._clear_approvals()
        self.save(with_history=False)
        self._save_histo(
            "cancelled", "%s (%s//%s//%s) cancelled" %
            (self.object.name, self.object.type, self.object.reference,
             self.object.revision))
        self._update_state_history()
Ejemplo n.º 6
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.º 7
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)