def create(self, ctx, node): subtype = self._preconfig() if not subtype: return self.redirect(self.path(action='add', node_id=node.id)) viewargs = {'subtype': subtype, 'node': node, 'infl': Inflector(), 'params': self.params} if self.request.method != "POST": return self.view(viewargs) s = Subscription(user_id=self.session.user_id, node_id=node.id, type_name=subtype.shortname) s.setConfig(self.params, subtype) return s.save().addCallback(self._save, 'create', viewargs)
def publish(self, msg): def send(subscribers): ds = [] for subscriber in subscribers: d = self.subscribers[subscriber.type_name].send(msg, subscriber) ds.append(d) return DeferredList(ds) return Subscription.getByMessage(msg).addCallback(send)
def edit(self, ctx, sub, relations): subtype = self.appcontroller.router.subscribers[sub.type_name] node = relations['node'] viewargs = {'subtype': subtype, 'node': node, 'infl': Inflector(), 'params': self.params} if self.request.method != "POST": for key, value in sub.config.items(): self.params[key] = value return self.view(viewargs) self.addParams(*sub.config.keys()) s = Subscription(**self.params) attrs = {'user_id': self.session.user_id, 'node_id': sub.node_id, 'id': sub.id, 'type_name': subtype.shortname} s.updateAttrs(attrs) s.setConfig(self.params, subtype) return s.save().addCallback(self._save, 'edit', viewargs)