Exemplo n.º 1
0
def add_site(sender, instance, **kwargs):
	"""Adds the current page's site to the contact if it hasn't been set."""
	if not instance.site:
		instance.site = Site.objects.get_current()


def user_can_edit(self, user_obj):
	'''
	This function will be hooked up to the User model as a method.
	The rule says that a user can only be modified by the same user
	'''
	user_site = user_obj.get_profile().site
	if user_site is not None and self.site == user_site:
		return True
	return False
Product.add_to_class('can_edit', user_can_edit)
registry.register('can_edit', Product)


def is_shop_owner(self):
	"""Returns True when the User is in the 'shop_owner' group."""
	return self.groups.filter(name='shop_owner').count() == 1
User.add_to_class('is_shop_owner', is_shop_owner)


def is_multishop_owner(self):
	"""Returns True when the User is in the 'virtual_shop_owner' group."""
	# TODO: Maybe asking the user's site is a better approach to determine if
	#       the user is running a multishop or a normal shop. This would at
	#       least eliminate the need for the group 'multishop_owner' to have
	#       a hardcoded name.
Exemplo n.º 2
0
        verbose_name_plural = _("products featured sorting")


# Patch Product
def get_main_units(self):
    product = self
    units = [p for p in product.productattribute_set.all() \
                                        if p.option.name == 'unita-di-misura']
    if units:
        units = units[0].value
    else:
        units = u'Kg'  # default value
    return units


Product.add_to_class("get_main_units", get_main_units)


# Patch Order
def shipping_extimated_date(self):
    order = self
    method = shipping_method_by_key(order.shipping_model)
    if method.valid():
        expected_delivery = method.expectedDelivery(order.contact)

    try:
        shipment = Shipment.objects.get(order=order)
        humanize_times = HumanizeTimes()
        start = shipment.mission.starts
        end = shipment.mission.ends
        start_str = start.strftime("%H:%M")
Exemplo n.º 3
0
        verbose_name = _("product featured sorting")
        verbose_name_plural = _("products featured sorting")


# Patch Product
def get_main_units(self):
    product = self
    units = [p for p in product.productattribute_set.all() \
                                        if p.option.name == 'unita-di-misura']
    if units:
        units = units[0].value
    else:
        units = u'Kg' # default value
    return units

Product.add_to_class("get_main_units", get_main_units)


# Patch Order
def shipping_extimated_date(self):
    order = self
    method = shipping_method_by_key(order.shipping_model)
    if method.valid():
        expected_delivery = method.expectedDelivery(order.contact)

    try:
        shipment = Shipment.objects.get(order=order)
        humanize_times = HumanizeTimes()
        start = shipment.mission.starts
        end = shipment.mission.ends
        start_str = start.strftime("%H:%M")