def thank(self, topic_id=None, reply_id=None): now = int(time.time()) self.active = now thank = m.Thank.get(user_id=self.id, topic_id=topic_id, reply_id=reply_id) if not thank: thank = m.Thank(user_id=self.id, topic_id=topic_id, reply_id=reply_id) notification = m.Notification.get(topic_id=topic_id, reply_id=reply_id, role='thank') if notification: if notification.switch == 1: notification.status = 0 notification.updated_at = now else: notification = m.Notification(topic_id=topic_id, reply_id=reply_id, role='thank').save() result = thank.save() if result: return {'status': 'success', 'message': '感谢成功', 'type': 1} else: return {'status': 'error', 'message': '感谢失败', 'type': -1} else: delta = int(time.time()) - thank.created_at if delta < config.thank_delta_time: thank.remove() return {'status': 'success', 'message': '取消感谢成功', 'type': 0} return {'status': 'info', 'message': '已超过取消感谢时间', 'type': -1}
def up(self, topic_id=None, reply_id=None): now = int(time.time()) self.active = now up = m.Up.get(user_id=self.id, topic_id=topic_id, reply_id=reply_id) if not up: down = m.Down.get(user_id=self.id, topic_id=topic_id, reply_id=reply_id) if down: down.remove() up = m.Up(user_id=self.id, topic_id=topic_id, reply_id=reply_id) notification = m.Notification.get(topic_id=topic_id, reply_id=reply_id, role='up') if notification: if notification.switch == 1: notification.status = 0 notification.updated_at = now else: m.Notification(topic_id=topic_id, reply_id=reply_id, role='up').save() result = up.save() if result: return {'status': 'success', 'message': '赞同成功', 'type': 1, 'category': 'up'} else: return {'status': 'error', 'message': '赞同失败', 'type': -1} up.remove() return {'status': 'success', 'message': '取消赞同成功', 'type': 0, 'category': 'up'}
def get(self): """Polls stats for experiments for the configured project and sends a significance notification if appropriate. Note: This example assumes there is only one goal for each experiment. """ call_sids = [] for experiment in self._get_experiments_for_project(): experiment_id = experiment['id'] existing_notification_record = models.Notification.get_by_experiment_id( experiment_id) if existing_notification_record: continue experiment_stats = self._get_stats_for_experiment(experiment_id) for entry in experiment_stats: if entry['status'] in self.CONCLUSIVE_STATUSES: call_sids.append(make_the_call(experiment['description'])) notification_record = models.Notification( experiment_id=experiment_id) notification_record.put() break self.response.write('Made calls with Twilio SIDs: %s' % call_sids)
def put_notifier(self): if 'class="mention"' not in self.content: return self names = get_mention_names(self.content) for name in names: user = m.User.get(name=name) if user and user.id != self.user_id: m.Notification(tweet_id=self.id, receiver_id=user.id, role='mention').save() return self
def save(self, category='create', user=None): bank = m.Bank.get_one() now = int(time.time()) if category == 'create': self.created_at = now self.topic.reply_count += 1 self.topic.last_reply_date = now self.topic.active = now self.floor = self.topic.reply_count self.author.reply_count += 1 self.author.spend(coin=config.reply_create_coin, role='reply-create', reply_id=self.id) bank.income(coin=config.reply_create_coin, role="reply-create", reply_id=self.id, spender_id=self.author.id) if self.user_id != self.topic.user_id: receiver_id = self.topic.user_id topic_id = self.topic_id notification = m.Notification.get(receiver_id=receiver_id, topic_id=topic_id, role='reply') if notification: if notification.switch == 1: notification.status = 0 notification.updated_at = now else: notification = m.Notification(receiver_id=receiver_id, topic_id=topic_id, role='reply').save() if category == 'edit' and not user: self.author.spend(coin=config.reply_edit_coin, role='reply-edit', reply_id=self.id) bank.income(coin=config.reply_edit_coin, role='reply-edit', reply_id=self.id, spender_id=self.author.id) if not user: user = self.author self.updated_at = now self.active = now user.active = now return super(Reply, self).save()
def addnotif(): if request.json['allversion'] is True and request.json[ 'allproduct'] is False: notification = models.Notification( user_id=current_user.id, vendor=escape(request.json['queryvendor'].lower()), product=escape(request.json['queryproduct'].lower()), version='') elif request.json['allproduct'] is True: notification = models.Notification( user_id=current_user.id, vendor=escape(request.json['queryvendor'].lower()), product='', version='') else: notification = models.Notification( user_id=current_user.id, vendor=escape(request.json['queryvendor'].lower()), product=escape(request.json['queryproduct'].lower()), version=escape(request.json['queryversion'].lower())) # Checking Integrity Before Insert # if models.Notification.query.filter_by( user_id=notification.user_id, vendor=notification.vendor, product=notification.product, version=notification.version).first() is None: models.db.session.add(notification) models.db.session.commit() flash('Notification Successfully Created.', 'success') syslog.syslog(syslog.LOG_DEBUG, "New notification created by: " + current_user.email) return redirect(url_for("notif.notiftab")) else: flash('Notification Already existing.', 'warning') syslog.syslog(syslog.LOG_ERR, "Notification Already existing: " + current_user.email) return redirect(url_for("notif.notiftab"))
def put_notifier(reply): up = UsernameParser() up.feed(reply.content) up.close() names1 = up.names names = {}.fromkeys(names1).keys() print names for name in names: user = m.User.get(name=name) if user and user.id != reply.topic.user_id: m.Notification(reply_id=reply.id, receiver_id=user.id, role='mention').save() return
def searchnotif(): notification = models.Notification(user_id=current_user.id, fulltxt=True, vendor=escape( request.json['searchquery']), product='', version='') # Checking Integrity Before Insert # if models.Notification.query.filter_by( user_id=notification.user_id, vendor=notification.vendor, fulltxt=notification.fulltxt).first() is None: models.db.session.add(notification) models.db.session.commit() flash('Notification Successfully Created.', 'success') syslog.syslog(syslog.LOG_DEBUG, "New notification created by: " + current_user.email) return redirect(url_for("notif.notiftab")) else: flash('Notification Already existing.', 'warning') syslog.syslog(syslog.LOG_ERR, "Notification Already existing: " + current_user.email) return redirect(url_for("notif.notiftab"))
def notification_count(self): return models.Notification().count_by_receiver_id_and_is_new(self.current_user.id, 1)