def add_account_subscription(self, user_id, location, notif_type, lang): """ Subscribe the user `user_id` """ self._validate_subscription(user_id=user_id, location=location, notif_type=notif_type, lang=lang) obj = self.getSite().restrictedTraverse(location) subscription_container = ISubscriptionContainer(obj) subscription = AccountSubscription(user_id, notif_type, lang) subscription_container.add(subscription)
def add_account_subscription(self, user_id, location, notif_type, lang, content_types=[]): """ Subscribe the user `user_id` """ self._validate_subscription(user_id=user_id, location=location, notif_type=notif_type, lang=lang, content_types=content_types) try: self.remove_account_subscription(user_id, location, notif_type, lang) except ValueError: pass obj = self.getSite().restrictedTraverse(location) subscription_container = ISubscriptionContainer(obj) subscription = AccountSubscription(user_id, notif_type, lang, content_types) subscription_container.add(subscription)
def add_account_subscription(self, user_id, location, notif_type, lang): """ Subscribe the user `user_id` """ if notif_type not in ('instant', 'daily', 'weekly', 'monthly'): raise ValueError(('Unknown notification type "${type}"', {'type': notif_type}, )) if self.config['enable_%s' % notif_type] is False: raise ValueError(('Notifications of type "${type}" not allowed', {'type': notif_type}, )) if notif_type not in self.available_notif_types(location): raise ValueError(('Subscribing to notifications in "${location}" not allowed', {'location': location}, )) obj = self.getSite().restrictedTraverse(location) subscription_container = ISubscriptionContainer(obj) n = match_account_subscription(subscription_container, user_id, notif_type, lang) if n is not None: raise ValueError(('Subscription already exists', )) subscription = AccountSubscription(user_id, notif_type, lang) subscription_container.add(subscription)
def confirm(self, REQUEST=None, key=''): """ Verify confirmation key and redirect to success page """ if key: subscriptions = ISubscriptionContainer(self.getSite()) # Check if the key is in the temporary list for subscription in self.pending_anonymous_subscriptions: if str(key) == subscription.key: # Verify if the email is not already subscribed for existing_subscription in subscriptions: if subscription.email == existing_subscription.email: return REQUEST.RESPONSE.redirect( self.absolute_url() + '/my_subscriptions_html') container = ISubscriptionContainer( self.getSite().restrictedTraverse( subscription.location)) container.add(subscription) # Add to subscribed list # Remove from temporary list self.pending_anonymous_subscriptions.remove(subscription) if REQUEST is not None: self.setSessionInfoTrans( 'You succesfully subscribed to ${notif_type} ' 'notifications for any changes in "${location}".', notif_type=subscription.notif_type, location=subscription.location or self.getSite().title) break else: if REQUEST is not None: self.setSessionErrorsTrans("Confirmation key not found") else: raise ValueError("Confirmation key not found") else: if REQUEST is not None: self.setSessionErrorsTrans("Confirmation key is invalid") else: raise ValueError("Confirmation key is invalid") if REQUEST is not None: return REQUEST.RESPONSE.redirect(self.absolute_url() + '/my_subscriptions_html')