Пример #1
0
    def _get_user_actions(self, request):

        user_actions = []

        if request.user.has_perm(EDIT,
                                 obj=ObjectWithContext(request.resource)):
            user_actions += [
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=VIEW,
                    verbose_name=_("Show"),
                    popup_form=False,
                    method="get",
                ),
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=EDIT_MULTIPLE,
                    verbose_name=_("Edit"),
                    popup_form=False,
                    method="get",
                ),
            ]

        return user_actions
Пример #2
0
    def _get_user_actions(self, request):

        user_actions = []
        des = Siteattr.get_site()

        if request.user.has_perm(CREATE, \
            obj=ObjectWithContext(Supplier, context={'site':des})):

            user_actions.append(
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=CREATE,
                    verbose_name=_("Add supplier"),
                    #WAS Supplier admin: url=urlresolvers.reverse('admin:supplier_supplier_add')
                ))

        user_actions += [
            ResourceBlockAction(block_name=self.BLOCK_NAME,
                                resource=request.resource,
                                name="export",
                                verbose_name="GDXP",
                                popup_form=False,
                                url="%s?%s" %
                                (reverse('gdxp.views.suppliers'),
                                 "pk__in=%s&opt_catalog=1" % ",".join(
                                     map(lambda x: str(x.pk),
                                         self._get_resource_list(request)), )),
                                method="OPENURL"),
        ]

        return user_actions
Пример #3
0
    def _get_user_actions(self, request):

        user_actions = []

        order = self.resource.order

        if request.user.has_perm(CASH, obj=ObjectWithContext(order.gas)) or \
            request.user == order.referrer_person.user:

            if order.is_closed() or order.is_unpaid():

                user_actions += [
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=request.resource,
                        name=VIEW,
                        verbose_name=_("Show"),
                        popup_form=False,
                        method="get",
                    ),
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=request.resource,
                        name=EDIT_MULTIPLE,
                        verbose_name=_("Edit"),
                        popup_form=False,
                        method="get",
                    ),
                ]

        return user_actions
Пример #4
0
    def _get_user_actions(self, request):

        user_actions = []

        if request.user.has_perm(EDIT,
                                 obj=ObjectWithContext(request.resource)):
            user_actions += [
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=VIEW,
                    verbose_name=_("Show"),
                    popup_form=False,
                    method="get",
                ),
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=EDIT_MULTIPLE,
                    verbose_name=_("Edit"),
                    popup_form=False,
                    method="get",
                ),
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=CREATE,
                    verbose_name=_("Add"),
                    popup_form=True,
                    method="get",
                ),
            ]

        user_actions += [
            ResourceBlockAction(block_name=self.BLOCK_NAME,
                                resource=request.resource,
                                name="export",
                                verbose_name="GDXP",
                                popup_form=False,
                                url="%s?%s" %
                                (reverse('gdxp.views.suppliers'),
                                 "pk=%s&opt_catalog=1" % request.resource.pk),
                                method="OPENURL"),
        ]

        return user_actions
Пример #5
0
    def _get_user_actions(self, request):
        """Who can edit Supplier informations, has also the ability to configure it."""

        user_actions = super(Block, self)._get_user_actions(request)

        if request.user.has_perm(EDIT,
                                 obj=ObjectWithContext(request.resource)):

            act_configure = ResourceBlockAction(
                block_name=self.BLOCK_NAME,
                resource=request.resource,
                name="configure",
                verbose_name=_("Configure"),
                popup_form=True,
                url=reverse('admin:supplier_supplierconfig_change',
                            args=(request.resource.config.pk, )))

            for i, act in enumerate(user_actions):
                # Change URL for action EDIT, insert "configure" action
                if act.name == EDIT:
                    #                   act.url = reverse('admin:supplier_supplier_change', args=(request.resource.pk,))
                    user_actions.insert(i + 1, act_configure)
                    break

            user_actions += [
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name="export",
                    verbose_name="GDXP",
                    popup_form=False,
                    url="%s?%s" %
                    (reverse('gdxp.views.suppliers'),
                     "pk=%s&opt_catalog=1" % request.resource.pk),
                    method="OPENURL"),
            ]

        return user_actions
Пример #6
0
    def _get_user_actions(self, request):

        user_actions = []

        if not request.resource.gas.config.gasmember_auto_confirm_order:

            #TODO seldon: does this work for a GASMember?
            #if request.user.has_perm(EDIT, obj=request.resource):
            if request.user == request.resource.person.user:
                user_actions += [
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=request.resource,
                        name=CONFIRM,
                        verbose_name=_("Confirm all"),
                        popup_form=False,
                    ),
                ]

        if request.user == request.resource.person.user:

            user_actions += [
                ResourceBlockAction(block_name=self.BLOCK_NAME,
                                    resource=request.resource,
                                    name=CREATE_PDF,
                                    verbose_name=_("Create PDF"),
                                    popup_form=False,
                                    method="OPENURL"),
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=SENDME_PDF,
                    verbose_name=_("Send email PDF gasmember"),
                    popup_form=False,
                )
            ]

        return user_actions
Пример #7
0
    def _get_user_actions(self, request):
        user_actions = super(Block, self)._get_user_actions(request)
        if request.user.has_perm(EDIT,
                                 obj=ObjectWithContext(request.resource)):

            user_actions.append(
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name="changepw",
                    verbose_name=_("Change password"),
                    popup_form=True,
                ))

        return user_actions
Пример #8
0
    def _get_user_actions(self, request):

        user_actions = []

        if request.user.has_perm(CREATE,
                                 obj=ObjectWithContext(
                                     GASSupplierSolidalPact,
                                     context={'gas': request.resource.gas})):
            user_actions.append(
                ResourceBlockAction(block_name=self.BLOCK_NAME,
                                    resource=request.resource.gas,
                                    name=CREATE,
                                    verbose_name=_("Add pact"),
                                    popup_form=True))

        return user_actions
Пример #9
0
    def _get_user_actions(self, request):

        user_actions = []
        gas_list = self.resource.gas.gas_list
        for gas in gas_list:
            if request.user.has_perm(CASH, obj=ObjectWithContext(gas)):
                user_actions += [
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=self.resource,
                        name=INCOME,
                        verbose_name=ugettext("Account transaction"),
                        popup_form=False,
                    ),
                ]
                break
        return user_actions
Пример #10
0
    def _get_user_actions(self, request):

        user_actions = []
        ctx = {'site': Siteattr.get_site()}
        if request.user.has_perm(CREATE,
                                 obj=ObjectWithContext(Person, context=ctx)):

            user_actions.append(
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=CREATE,
                    verbose_name=_("Add person"),
                    #WAS admin: url=urlresolvers.reverse('admin:base_person_add')
                ))

        return user_actions
Пример #11
0
    def _get_user_actions(self, request):

        user_actions = []

        resource_type = request.resource.resource_type

        if self._check_permission(request):
            user_actions += [
                ResourceBlockAction(
                    block_name = self.BLOCK_NAME,
                    resource = request.resource,
                    name=CREATE_CSV, verbose_name=_("Create CSV"),
                    popup_form=False,
                    method="OPENURL",
                ),
            ]

        return user_actions
Пример #12
0
    def _get_user_actions(self, request):

        user_actions = []

        des = Siteattr.get_site()

        if request.user.has_perm(CREATE,
                                 obj=ObjectWithContext(GAS,
                                                       context={'site': des})):
            user_actions.append(
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=CREATE,
                    verbose_name=_("Add GAS"),
                    #WAS admin: url=urlresolvers.reverse('admin:gas_gas_add')
                ))

        return user_actions
Пример #13
0
    def _get_user_actions(self, request):

        user_actions = []
        ctx = {self.resource.resource_type: self.resource}

        if request.user.has_perm(CREATE,
                                 obj=ObjectWithContext(GASSupplierOrder,
                                                       context=ctx)):

            if self.resource.resource_type in ["gas", "supplier", "pact"]:
                user_actions += [
                    ResourceBlockAction(block_name=self.BLOCK_NAME,
                                        resource=request.resource,
                                        name=CREATE,
                                        verbose_name=_("Add order"),
                                        popup_form=True),
                ]

        return user_actions
Пример #14
0
    def _get_user_actions(self, request):
        #COMMENT BY fero: no need for these actions now
        return []

        user_actions = []
        gas_list = self.resource.gas_list

        for gas in gas_list:
            if request.user.has_perm(CASH, obj=ObjectWithContext(gas)):

                user_actions += [
                    ResourceBlockAction(
                        block_name = self.BLOCK_NAME,
                        resource = self.resource,
                        name=INCOME, verbose_name=ug("Balance state"),
                        popup_form=False,
                    ),
                ]
                break

        return user_actions
Пример #15
0
    def _get_user_actions(self, request):

        user_actions = []
        order = self.resource.order

        if request.user.has_perm(CASH, obj=ObjectWithContext(order.gas)) or \
            request.user == order.referrer_person.user:

            if order.is_closed() or order.is_unpaid():

                user_actions += [
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=self.resource,
                        name=INCOME,
                        verbose_name=_("Register"),
                        popup_form=False,
                    ),
                ]

        return user_actions
Пример #16
0
    def _get_user_actions(self, request):

        user_actions = []
        order = self.resource.order

        if request.user.has_perm(CASH,
                                 obj=ObjectWithContext(self.resource.gas)):

            if order.is_closed() or order.is_unpaid():

                user_actions += [
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=self.resource,
                        name=INCOME,
                        verbose_name=ug("Insolute payment"),
                        popup_form=False,
                    ),
                ]

        return user_actions
Пример #17
0
    def _get_user_actions(self, request):
        """Who can edit GAS informations, has also the ability to configure it."""

        user_actions = super(Block, self)._get_user_actions(request)

        if request.user.has_perm(EDIT, obj=ObjectWithContext(request.resource)):
            
            act_configure = ResourceBlockAction(
                    block_name = self.BLOCK_NAME,
                    resource = request.resource,
                    name="configure", verbose_name=_("Configure"),
                    popup_form=True,
                    url = reverse('admin:gas_gasconfig_change', args=(request.resource.config.pk,))
            )

            for i,act in enumerate(user_actions):
                # Change URL for action EDIT, insert "configure" action
                if act.name == EDIT:
#                   act.url = reverse('admin:gas_gas_change', args=(request.resource.pk,)) 
                   user_actions.insert(i+1, act_configure)
                   break
                   
        return user_actions
Пример #18
0
    def _get_user_actions(self, request):

        user_actions = []

        try:
            #TODO: block refactory needed!
            # We need this control because gas attribute is a NoSense in "site" resource (DES)
            gas = request.resource.gas
        except NotImplementedError:
            pass
        else:
            if request.user.has_perm(CREATE,
                                     obj=ObjectWithContext(
                                         GASMember, context={'gas': gas})):

                user_actions.append(
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=request.resource,
                        name=CREATE,
                        verbose_name=_("Add GAS member"),
                        url=urlresolvers.reverse('admin:gas_gasmember_add')))

        return user_actions
Пример #19
0
    def _get_user_actions(self, request):

        user_actions = []

        if request.user.has_perm(EDIT,
                                 obj=ObjectWithContext(request.resource)):

            # Duck-typing
            # Invoke an unneeded method just to check if an exception happen
            try:
                self._get_edit_form_class()
            except NotImplementedError as e:
                # If edit_form_class is not implemented, log the event
                log.debug(str(e))
            else:
                klass_name = self.resource.__class__.__name__
                url = None

                user_actions.append(
                    ResourceBlockAction(block_name=self.BLOCK_NAME,
                                        resource=request.resource,
                                        name=EDIT,
                                        verbose_name=_("Edit"),
                                        popup_form=True,
                                        url=url))

            if self._get_roles_formset_class():

                user_actions.append(

                    # Referrers assignment
                    ResourceBlockAction(
                        block_name=self.BLOCK_NAME,
                        resource=request.resource,
                        name="manage_roles",
                        verbose_name=_("Manage roles"),
                        popup_form=True,
                    ))

            # Show actions for transition allowed for this resource

            for t in get_allowed_transitions(request.resource, request.user):
                #FIXME: related to gas/workflows_data.py ugettext_laxy FIXME
                local_transitions = {
                    'Open': 'Apri',
                    'Close': 'Chiudi',
                    'Close and send email': 'Chiudi e invia email',
                    'Archive': 'Archivia',
                    'Cancel': 'Annulla',
                }

                translated_t = local_transitions.get(t.name, t.name)
                #ENDFIXME

                action = ResourceBlockAction(block_name=self.BLOCK_NAME,
                                             resource=request.resource,
                                             name="transition/%s" %
                                             t.name.lower(),
                                             verbose_name=translated_t,
                                             popup_form=False,
                                             url=None)

                user_actions.append(action)

        return user_actions
Пример #20
0
    def _get_user_actions(self, request):
  
        user_actions = []

        order = self.resource.order

        #TODO fero: add permission GET_ORDER_DOC
        if request.user == order.gas.tech_referrers \
            or request.user in order.gas.supplier_referrers \
            or request.user in order.supplier.referrers \
            or request.user.is_superuser:

            user_actions += [
                ResourceBlockAction(
                    block_name = self.BLOCK_NAME,
                    resource = request.resource,
                    name=CREATE_PDF, verbose_name=_("Create PDF"),
                    popup_form=False,
                    method="OPENURL",
                ),
            ]
            
            user_actions += [
                ResourceBlockAction(
                    block_name = self.BLOCK_NAME,
                    resource = request.resource,
                    name="createhtml", verbose_name=_("Create HTML"),
                    popup_form=False,
                ),
            ]

#            user_actions += [
#                ResourceBlockAction(
#                    block_name = self.BLOCK_NAME,
#                    resource = request.resource,
#                    name=VIEW_AS_HTML, verbose_name=_("Visualizza come HTML"),
#                    popup_form=True,
#                ),
#            ]

        #TODO fero: permission GET_ORDER_DOC
        if request.user == order.referrer_person.user \
            or request.user in order.gas.supplier_referrers \
            or request.user in order.supplier.referrers \
            or request.user.is_superuser:

            if order.is_closed() or order.is_unpaid():
                user_actions += [
                    ResourceBlockAction( 
                        block_name = self.BLOCK_NAME,
                        resource = request.resource,
                        name=SENDME_PDF, verbose_name=_("Send email PDF me"),
                        popup_form=False,
                    )
                ]
                if order.supplier.config.receive_order_via_email_on_finalize:                        
                    user_actions += [
                        ResourceBlockAction(
                            block_name = self.BLOCK_NAME,
                            resource = request.resource,
                            name=SENDPROD_PDF, verbose_name=_("Send email PDF supplier"),
                            popup_form=False,
                        )
                    ]



        if request.user.has_perm(EDIT, obj=ObjectWithContext(request.resource)):
            user_actions += [
                ResourceBlockAction(
                    block_name = self.BLOCK_NAME,
                    resource = request.resource,
                    name=VIEW, verbose_name=_("Show"),
                    popup_form=False,
                    method="get",
                ),
                ResourceBlockAction(
                    block_name = self.BLOCK_NAME,
                    resource = request.resource,
                    name=EDIT_MULTIPLE, verbose_name=_("Edit"),
                    popup_form=False,
                    method="get",
                ),
            ]
        return user_actions
Пример #21
0
    def _get_user_actions(self, request):

        user_actions = []
        des = Siteattr.get_site()

        if request.user.has_perm(CREATE, \
            obj=ObjectWithContext(Supplier, context={'site':des})):

            user_actions.append(
                ResourceBlockAction(
                    block_name=self.BLOCK_NAME,
                    resource=request.resource,
                    name=CREATE,
                    verbose_name=_("Add supplier"),
                    #WAS Supplier admin: url=urlresolvers.reverse('admin:supplier_supplier_add')
                ))

        user_actions += [
            ResourceBlockAction(block_name=self.BLOCK_NAME,
                                resource=request.resource,
                                name=CREATE_PDF,
                                verbose_name=_("Create PDF"),
                                popup_form=False,
                                method="OPENURL"),
        ]

        user_actions += [
            ResourceBlockAction(block_name=self.BLOCK_NAME,
                                resource=request.resource,
                                name="export",
                                verbose_name="GDXP",
                                popup_form=False,
                                url="%s?%s" %
                                (reverse('gdxp.views.suppliers'),
                                 "pk__in=%s&opt_catalog=1" % ",".join(
                                     map(lambda x: str(x.pk),
                                         self._get_resource_list(request)), )),
                                method="OPENURL"),
        ]

        # COMMENT fero: disabled because it does not work
        # COMMENT fero: (calls Supplier.product which is a no-sense, probably Supplier.products?)
        # COMMENT fero: but also for needs to change SupplierForm in SingleSupplierForm (a row in formset)
        #        if request.user.has_perm(EDIT, obj=ObjectWithContext(request.resource)):
        #            user_actions += [
        #                ResourceBlockAction(
        #                    block_name = self.BLOCK_NAME,
        #                    resource = request.resource,
        #                    name=VIEW, verbose_name=_("Show"),
        #                    popup_form=False,
        #                    method="get",
        #                ),
        #                ResourceBlockAction(
        #                    block_name = self.BLOCK_NAME,
        #                    resource = request.resource,
        #                    name=EDIT_MULTIPLE, verbose_name=_("Edit"),
        #                    popup_form=False,
        #                    method="get",
        #                ),
        #            ]
        return user_actions