def send_email_to_subscribers(subject, html, categories=None): _utils = Utils(api.portal.get(), getRequest()) public_url = _utils.get_public_url() check_categories = (categories is not None and len(categories) != 0) for subscriber in subscribe.all(): if check_categories: # If there's no chosen categories, they recieve everything if 'categories' in subscriber and len( subscriber['categories']) > 0: # make sure that this message falls under one of their categories if len(categories.intersection(subscriber['categories'])) == 0: return query = urlencode({ 'email': subscriber.get('email'), 'code': subscriber.get('code') }) unsubscribe_url = '%s/@@unsubscribe?%s' % (public_url.rstrip('/'), query) change_url = '%s/@@changesubscription?%s' % (public_url.rstrip('/'), query) unsubscribe_url = unsubscribe_url.encode('utf8') change_url = change_url.encode('utf8') html = html.replace('{{unsubscribe_url}}', unsubscribe_url) html = html.replace('{{change_url}}', change_url) utils.send_email([subscriber.get('email')], subject, html)
def handle_send2(self, action): data, errors = self.extractData() if not errors: utils = Utils(self.context, self.request) public_url = utils.get_public_url() html = data['body'].output filters = [ f for _, f in getAdapters((self.context, self.request), IFilter) ] html = apply_filters(filters, html) html = html.replace(self.context.absolute_url(), public_url.encode('utf8')) categories = set() if 'form.widgets.send_to_categories' in self.request.form: categories = set(data['send_to_categories']) sender = None if 'form.widgets.send_from' in self.request.form: sender = data['send_from'] send_email_to_subscribers.delay(data['subject'], html=html, categories=categories, sender=sender) api.portal.show_message('Sending emails', request=self.request, type='info') self.request.response.redirect('%s/@@announcements-controlpanel' % (self.context.absolute_url()))
def handle_send(self, action): data, errors = self.extractData() if not errors: addresses = data['send_to_custom'] or [] for group in data['send_to_groups'] or []: for user in api.user.get_users(groupname=group): email = user.getProperty('email') if email: addresses.append(email) for username in data['send_to_users'] or []: user = api.user.get(username=username) if user: email = user.getProperty('email') if email: addresses.append(email) try: sender = data['send_from'] except Exception: sender = None utils = Utils(self.context, self.request) public_url = utils.get_public_url() html = data['body'].output filters = [f for _, f in getAdapters((self.context, self.request), IFilter)] html = apply_filters(filters, html) html = html.replace(self.context.absolute_url(), public_url.encode('utf8')) send_email.delay(list(set(addresses)), data['subject'], html=html, sender=sender) self.request.response.redirect('%s/@@announcements-controlpanel' % ( self.context.absolute_url()))
def get_data(self): registry = getUtility(IRegistry) btype = registry.get('castle.business_type', None) bname = registry.get('castle.business_name', None) utils = Utils(self.context, getRequest()) if not btype and bname: # return subset that uses site name, org type registry = getUtility(IRegistry) site_settings = registry.forInterface(ISiteSchema, prefix="plone", check=False) return { "@context": "http://schema.org", "@type": 'Organization', "name": site_settings.site_title, "url": utils.get_public_url(), "logo": { "@type": "ImageObject", "url": getSiteLogo() } } data = { "@context": "http://schema.org", "@type": btype, "name": bname, "url": utils.get_public_url(), 'telephone': registry.get('castle.business_telephone', ''), "logo": { "@type": "ImageObject", "url": getSiteLogo() } } address = registry.get('castle.business_address', None) if address: data['address'] = { '@type': 'PostalAddress', 'streetAddress': address, 'addressLocality': registry.get('castle.business_city', ''), 'addressRegion': registry.get('castle.business_state', ''), 'postalCode': registry.get('castle.business_postal_code', ''), 'addressCountry': registry.get('castle.business_country', '') } coordinates = registry.get('castle.business_coordinates', '') if coordinates: try: coordinates = json.loads(coordinates) except Exception: coordinates = None if coordinates: data['geo'] = { '@type': 'GeoCoordinates', 'latitude': coordinates.get('lat', ''), 'longitude': coordinates.get('lng', '') } days = registry.get('castle.business_days_of_week', []) hours = [] if days: hours.append({ '@type': "OpeningHoursSpecification", 'dayOfWeek': days, 'opens': registry.get('castle.business_opens', ''), 'closes': registry.get('castle.business_closes', ''), }) for special in registry.get('castle.business_special_hours', []) or []: if special.count('|') != 2: continue day, opens, closes = special.split('|') hours.append({ '@type': "OpeningHoursSpecification", 'dayOfWeek': day, 'opens': opens, 'closes': closes }) if hours: data['openingHoursSpecification'] = hours menu = registry.get('castle.business_menu_link', None) if menu: data["menu"] = menu if registry.get('castle.business_accepts_reservations', False): data["acceptsReservations"] = "True" try: data.update(json.loads( registry.get( 'castle.business_additional_configuration', '{}'))) except Exception: pass return data