Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
    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
Пример #4
0
    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)
Пример #5
0
def list_notification_methods():
    methods = NotificationMethod.objects(user=current_user.id)
    return render_template("notifications/list.html", notification_methods=methods)