def filteredVocabulary(self): utility = getUtility(ICountriesStates) # Remeber that this widget must work for browsers without javascript # So, by default, there is no country selected, and all possible states # must be displayed. country = None # Try to get the country from the form. # We are replacing 'state' occurences on field name with 'country' country_field_id = self.name.replace('state', 'country') form_country = self.request.form.get(country_field_id, '') # If a country is known we can safely ignore any possible # setting of the state and just return the states for that # country: if the chosen country is The Netherlands there is # no sense in believing that the state is the Japanese # province of Hokkaido. if form_country == '': # No country is known. # Try to get the state from the form. state = self._getCurrentValue() if state and state not in utility.special_values: # A state has been chosen. Take the first two letters of # the state value as the country. country = state[:2] else: country = form_country states = utility.states(country, allow_no_values=not self.context.required) return TitledVocabulary.fromTitles(states)
def getAddressInfo(order,field): if not coreInterfaces.IShippableOrder.providedBy( order ): return "N/A" utility = zapi.getUtility(ICountriesStates) vocab_countries = TitledVocabulary.fromTitles(utility.countries) vocab_states = TitledVocabulary.fromTitles(utility.states()) infos = order.shipping_address #Check if the shipping info is the same that the billing one and add the resulting one if infos.ship_same_billing: infos = order.billing_address order_info= {'name': infos.bill_name, 'address': "%s %s" % (infos.bill_first_line or "" , infos.bill_second_line or ""), 'city': infos.bill_city, 'country': vocab_countries.getTerm(infos.bill_country).title, 'state': infos.bill_state.split("-").pop(), 'postal_code': infos.bill_postal_code} else: order_info= {'name': infos.ship_name, 'address': "%s %s" % (infos.ship_first_line or "", infos.ship_second_line or ""), 'city': infos.ship_city, 'country': vocab_countries.getTerm(infos.ship_country).title, 'state': infos.ship_state.split("-").pop(), 'postal_code': infos.ship_postal_code} #Add the contact information contact = order.contact_information order_info['contact_name'] = contact.name order_info['email'] = contact.email order_info['phone'] = contact.phone_number #Finally the shipment info #Total Weight totalShipmentWeight = 0 for eachProduct in order.shopping_cart.values(): if coreInterfaces.IShippableLineItem.providedBy( eachProduct ): weightValue = eachProduct.weight * eachProduct.quantity totalShipmentWeight += weightValue order_info['weight'] = totalShipmentWeight #Service type service = component.queryUtility( coreInterfaces.IShippingRateService, order.shipping_service ) order_info['service'] = service.getMethodName( order.shipping_method ) return '%s' % order_info[field]
def render( self ): # pull out the real order object from the traversable wrapper self.order = self.context._object pm = getToolByName(self.context, "portal_membership") # this check really shouldn't be hardcoded here.. -kapilt user = pm.getAuthenticatedMember() if not user.has_permission('PloneGetPaid: Manage Orders',self.context): user_id = user.getId() if 'Anonymous' in user.getRoles() or user_id != self.getUserId(): raise Unauthorized, "Arbitrary Order Access Only for Managers" utility = component.getUtility(ICountriesStates) self.vocab_countries = TitledVocabulary.fromTitles(utility.countries) self.vocab_states = TitledVocabulary.fromTitles(utility.states()) return self.__of__( self.__parent__ ).template()
def render(self): # pull out the real order object from the traversable wrapper self.order = self.context._object pm = getToolByName(self.context, "portal_membership") # this check really shouldn't be hardcoded here.. -kapilt user = pm.getAuthenticatedMember() if not user.has_permission('PloneGetPaid: Manage Orders', self.context): user_id = user.getId() if 'Anonymous' in user.getRoles() or user_id != self.getUserId(): raise Unauthorized, "Arbitrary Order Access Only for Managers" utility = component.getUtility(ICountriesStates) self.vocab_countries = TitledVocabulary.fromTitles(utility.countries) self.vocab_states = TitledVocabulary.fromTitles(utility.states()) return self.__of__(self.__parent__).template()