Example #1
0
def view(person_id):
    try:
        p = get_person(person_id)
    except NoResultFound:
        return common_render("404.jinja"), 404
    except UnauthorizedException:
        return common_render("error.jinja"), 403

    entries = Entry.query.filter(Entry.subject_id == p.id).all()
    return common_render("view.jinja", person=p, entries=entries)
Example #2
0
def view(person_id):
    try:
        p = get_person(person_id)
    except NoResultFound:
        return common_render("404.jinja"), 404
    except UnauthorizedException:
        return common_render("error.jinja"), 403

    entries = Entry.query.filter(Entry.subject_id == p.id).all()
    return common_render("view.jinja", person=p, entries=entries)
Example #3
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        salt = app.config.get("PW_SALT")
    
        user = User(
            form.email.data,
            form.password.data
        )

        db.session.add(user)
        db.session.commit()
        
        person = Person(
            user.id,
            form.first_name.data, 
            form.last_name.data
        )

        db.session.add(person)
        db.session.commit()

        login_user(user)
        return redirect(url_for('index.index'))
    return common_render('register.jinja', form=form)
Example #4
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        salt = app.config.get("PW_SALT")
        password_hash = bcrypt.hashpw(form.password.data, salt)

        clause = and_(User.email == form.email.data, User.password_hash == password_hash)

        try:
            user = User.query.filter(clause).one()
        except NoResultFound:
            flash("Incorrect email address or password.")
            return common_render('login.jinja', form=form)

        login_user(user)
        return redirect(url_for('index.index'))
    return common_render('login.jinja', form=form)
Example #5
0
def add():
    form = PersonForm(request.form)
    if request.method == 'POST' and form.validate():
        current_person_id = current_user.person.id

        p = Person(None, form.first_name.data, form.last_name.data,
                   current_person_id)

        db.session.add(p)
        db.session.commit()
        flash("Person successfully added.")
        return redirect(url_for("people.all"))
    else:
        return common_render('add.jinja', form=form)
Example #6
0
def add():
    form = PersonForm(request.form)
    if request.method == 'POST' and form.validate():
        current_person_id = current_user.person.id

        p = Person(
            None,
            form.first_name.data,
            form.last_name.data,
            current_person_id
        )

        db.session.add(p)
        db.session.commit()
        flash("Person successfully added.")
        return redirect(url_for("people.all"))
    else:
        return common_render('add.jinja', form=form)
Example #7
0
def add_entry(person_id):
    try:
        subject = get_person(person_id)
    except NoResultFound:
        return common_render("404.jinja"), 404
    except UnauthorizedException:
        return common_render("error.jinja"), 403

    #fetch and serlialize all people managed by the current user
    current_person_id = current_user.person.id

    managed_by = Person.query.filter(and_(\
            Person.managed_by_id == current_person_id,\
            Person.id != subject.id))\
            .all()

    managed_by = [to_json(p, Person) for p in managed_by]
    managed_by_str = json.dumps(managed_by)

    # get all pinned notes
    pinned = Note.query.filter(and_(\
            Note.is_pinned == True, \
            Note.author_id == current_person_id, \
            Note.subject_id == subject.id)).all()

    pinned = [to_json(p, Note) for p in pinned]
    pinned_str = json.dumps(pinned)

    # get all feedback
    feedback = Feedback.query.filter(and_(\
            Feedback.to_id == subject.id,
            Feedback.has_communicated == False)).all()

    feedback = [to_json(p, Feedback) for p in feedback]
    feedback_str = json.dumps(feedback)

    if request.method == 'POST':

        e = Entry(current_user.person.id, subject.id, datetime.date.today())
        db.session.add(e)
        db.session.commit()

        notes = json.loads(request.form['notes'])

        for note in notes:
            if note['body']:
                if note['type'] == "FEEDBACK":
                    f = Feedback()
                    f.from_id = subject.id
                    f.to_id = int(note['meta']['feedback-for'])
                    f.has_communicated = False
                    f.body = note['body']

                    #FIXME: this could lead to numerous commits
                    db.session.add(f)
                    db.session.commit()
                else:
                    f = None

                is_pinned = note['type'] == 'CHECKIN'
                n = Note(e, note["type"], note['body'], is_pinned=is_pinned)

                if f:
                    n.linked_feedback = f.id

                db.session.add(n)

        db.session.commit()
        return redirect(url_for("people.view", person_id=subject.id))

    return common_render("add_entry.jinja", \
            person=subject,\
            managed_by_str=managed_by_str,\
            feedback_str=feedback_str,\
            pinned_str=pinned_str)
Example #8
0
def all():
    return common_render('all.jinja')
Example #9
0
def add_entry(person_id):
    try:
        subject = get_person(person_id)
    except NoResultFound:
        return common_render("404.jinja"), 404
    except UnauthorizedException:
        return common_render("error.jinja"), 403

    #fetch and serlialize all people managed by the current user
    current_person_id = current_user.person.id

    managed_by = Person.query.filter(and_(\
            Person.managed_by_id == current_person_id,\
            Person.id != subject.id))\
            .all()

    managed_by = [to_json(p, Person) for p in managed_by]
    managed_by_str = json.dumps(managed_by)

    # get all pinned notes
    pinned = Note.query.filter(and_(\
            Note.is_pinned == True, \
            Note.author_id == current_person_id, \
            Note.subject_id == subject.id)).all()

    pinned = [to_json(p, Note) for p in pinned]
    pinned_str = json.dumps(pinned)

    # get all feedback
    feedback = Feedback.query.filter(and_(\
            Feedback.to_id == subject.id,
            Feedback.has_communicated == False)).all()

    feedback = [to_json(p, Feedback) for p in feedback]
    feedback_str = json.dumps(feedback)

    if request.method == 'POST':

        e = Entry(current_user.person.id, subject.id, datetime.date.today())
        db.session.add(e)
        db.session.commit()

        notes = json.loads(request.form['notes'])

        for note in notes:
            if note['body']:
                if note['type'] == "FEEDBACK":
                    f = Feedback()
                    f.from_id = subject.id
                    f.to_id = int(note['meta']['feedback-for'])
                    f.has_communicated = False
                    f.body = note['body']

                    #FIXME: this could lead to numerous commits
                    db.session.add(f)
                    db.session.commit()
                else:
                    f = None

                is_pinned = note['type'] == 'CHECKIN'
                n = Note(e, note["type"], note['body'], is_pinned=is_pinned)
            
                if f:
                    n.linked_feedback = f.id

                db.session.add(n)

        db.session.commit()
        return redirect(url_for("people.view", person_id=subject.id))

    return common_render("add_entry.jinja", \
            person=subject,\
            managed_by_str=managed_by_str,\
            feedback_str=feedback_str,\
            pinned_str=pinned_str)
Example #10
0
def all():
    return common_render('all.jinja')
Example #11
0
def index():
    if current_user.is_anonymous():
        return common_render('splash.jinja')
    else:
        return common_render('dashboard.jinja')