Ejemplo n.º 1
0
def site_settings(request):
    """ main entrance page (following index ;))"""

    site = Siteattr.get_site()
    
    user = request.user
    base_usercontainer_id = None
    
#    if not user.is_anonymous():
#        base_usercontainer_id = UserContainer.objects.filter(creator=user, parent=None)    [0].id
    
    ctx = {
        'user'                 : request.user.username,
        'user_id'              : request.user.pk,
        'base_usercontainer_id': base_usercontainer_id,
        'url_prefix'           : settings.URL_PREFIX,
        'type'                 : 'site',
        'id'                   : site.pk,
        'site_id'              : site.pk,
        'site_name'            : unicode(site),
        'isdebug'              : settings.DEBUG,
        'isdbghost'            : request.get_host(),
    }
#WAS        'isdbghost'            : string.find(request.get_host(), ":"),
    return render_to_xml_response("settings.xml", ctx)
Ejemplo n.º 2
0
def site_settings(request):
    """ main entrance page (following index ;))"""

    site = Siteattr.get_site()

    user = request.user
    base_usercontainer_id = None

    #    if not user.is_anonymous():
    #        base_usercontainer_id = UserContainer.objects.filter(creator=user, parent=None)    [0].id

    ctx = {
        'user': request.user.username,
        'user_id': request.user.pk,
        'base_usercontainer_id': base_usercontainer_id,
        'url_prefix': settings.URL_PREFIX,
        'type': 'site',
        'id': site.pk,
        'site_id': site.pk,
        'site_name': unicode(site),
        'isdebug': settings.DEBUG,
        'isdbghost': request.get_host(),
    }
    #WAS        'isdbghost'            : string.find(request.get_host(), ":"),
    return render_to_xml_response("settings.xml", ctx)
Ejemplo n.º 3
0
def staff_registration(request, *args, **kw):
    """This view is used by staff that wants to register new users
    without using the email confirmation procedure.

    """
    des = Siteattr.get_site()

    if request.user in des.admins | des.gas_tech_referrers:

        form_class = DESStaffRegistrationForm
        if request.method == "POST":
            form = form_class(request.POST)
            if form.is_valid():
                form.save()
                messages.info(request, "Complimenti o tecnico! Hai registrato un nuovo utente :)")
                return HttpResponseRedirect(settings.LOGIN_URL)
        else:
            form = form_class()

        context = {
            'registration_form' : form,
            'VERSION': settings.VERSION,
            'THEME' : settings.THEME,
            'MEDIA_URL' : settings.MEDIA_URL,
            'ADMIN_MEDIA_PREFIX' : settings.ADMIN_MEDIA_PREFIX
        }

        return render_to_response("registration/staff_register.html", context,
                                  context_instance=RequestContext(request)
        )

    else:
        return django_auth_login(request, *args, **kw)
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def quick_search(request):

    site = Siteattr.get_site()
    #TODO: fero TOCHECK, no filter needed for "VIEW" permission
    #if not request.user.is_superuser:
    #   site = site.filter(request.user)
    q = request.GET['q']
    limits = request.REQUEST.getlist('l')
    if len(limits) == 0:
        search_result = site.quick_search(q=q)
    else:
        search_result = site.quick_search(q=q, limits=limits)
    context = {'search_result': search_result}
    return render_to_response("html/quick_search_result.html", context)
Ejemplo n.º 7
0
def quick_search(request):

    site = Siteattr.get_site()
    #TODO: fero TOCHECK, no filter needed for "VIEW" permission
    #if not request.user.is_superuser:
    #   site = site.filter(request.user)
    q = request.GET['q']
    limits = request.REQUEST.getlist('l')
    if len(limits) == 0:
        search_result = site.quick_search(q = q)
    else:
        search_result = site.quick_search(q = q, limits = limits)
    context = {
        'search_result': search_result 
    }
    return render_to_response("html/quick_search_result.html", context)
Ejemplo n.º 8
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,
            ),
        ]

# 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
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def notify_order_state_update(sender, **kwargs):

    order = sender
    transition = kwargs['transition']

    extra_content = {
        'gas': order.gas,
        'order': order,
        'action': transition.name,
        'state': transition.destination.name,
        'site': Siteattr.get_site(),
        'protocol': 'http',
    }

    #--- Transition name ---#

    recipients = []

    try:
        if transition.destination.name.lower() in ["open", "closed"]:
            recipients = [order.referrer_person.user]
        elif transition.destination.name.lower() in ["sent", "paid"]:
            recipients = list(
                order.supplier.referrers) + [order.referrer_person.user]
            recipients = unordered_uniq(recipients)
    except AttributeError as e:
        #TODO Matteo: complete exception handling here
        raise exceptions.ReferrerIsNoneException()

    log.debug("Transition to: %s" % transition.destination.name)
    log.debug("Recipients: %s" %
              zip(recipients, map(lambda x: x.email, recipients)))
    try:
        notification.send(recipients, "order_state_update", extra_content)
    except Exception as e:
        log.error("Send msg notify_order_state_update: %s (%s)" %
                  (e.message, type(e)))
        pass
Ejemplo n.º 12
0
def notify_order_state_update(sender, **kwargs):

    order = sender
    transition = kwargs['transition']

    extra_content = {
        'gas' : order.gas,
        'order' : order,
        'action' : transition.name,
        'state' : transition.destination.name,
        'site' : Siteattr.get_site(),
        'protocol' : 'http',
    }

    #--- Transition name ---#

    recipients = []

    try:
        if transition.destination.name.lower() in ["open", "closed"]:
            recipients = [order.referrer_person.user]
        elif transition.destination.name.lower() in ["sent", "paid"]:
            recipients = list(order.supplier.referrers) + [order.referrer_person.user]
            recipients = unordered_uniq(recipients)
    except AttributeError as e:
        #TODO Matteo: complete exception handling here
        raise exceptions.ReferrerIsNoneException()

    log.debug("Transition to: %s" % transition.destination.name)
    log.debug("Recipients: %s" % zip(recipients, map(lambda x: x.email, recipients)))
    try:
        notification.send(recipients, "order_state_update", 
            extra_content
        )
    except Exception as e:
        log.error("Send msg notify_order_state_update: %s (%s)" % (e.message, type(e)))
        pass
Ejemplo n.º 13
0
    def des(self):
        """Return the DES instance bound to the resource"""
        from gasistafelice.des.models import Siteattr
        return Siteattr.get_site()

        raise NotImplementedError("class: %s method: des" % self.__class__.__name__)
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def des(self):
     return Siteattr.get_site()
Ejemplo n.º 16
0
 def des(self):
     from gasistafelice.des.models import Siteattr
     return Siteattr.get_site()
Ejemplo n.º 17
0
 def des(self):
     return Siteattr.get_site()
Ejemplo n.º 18
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