def new(): form = NotificationForm(user=current_user.id) if request.method == "GET": return render_template("notifications/new.html", form=form) if request.method == "POST": if form.validate_on_submit(): notification_method = NotificationMethod(user=current_user.id) form.populate_obj(notification_method) notification_method.save() return jsonify(status="success", next=url_for("notifications.list_notification_methods")) return jsonify(status="error", errors=form.errors)
def index(): person_count = MissedPerson.objects(user=current_user.id).count() notification_count = NotificationMethod.objects(user=current_user.id).count() not_seen = Detection.objects(user=current_user.id, seen=False).count() return render_template("index.html", person_count=person_count, notification_count=notification_count, not_seen=not_seen)
def validate(self): valid = super(NotificationForm, self).validate() filters = self.data filters['user'] = self.user if NotificationMethod.objects(**filters): self.errors['__all__'] = [u"Método de notificação já cadastrado."] valid = False return valid
def run(self, detection): if detection is None: return None print(detection.person.name) self.detection = detection methods = NotificationMethod.objects(user=detection.person.user) for method in methods: self.notify(method)
def list_notification_methods(): methods = NotificationMethod.objects(user=current_user.id) return render_template("notifications/list.html", notification_methods=methods)