def createUser(flask_session):
    newUser = User( name = flask_session['username'],
                    picture = flask_session['picture'],
                    link = flask_session['link'],
                    email = flask_session['email'],
                    google_plus_id = flask_session['google_plus_id'] )
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(google_plus_id = flask_session['google_plus_id']).one()
    return user.id
Exemple #2
0
def createUser(flask_session):
    newUser = User(name=flask_session['username'],
                   picture=flask_session['picture'],
                   link=flask_session['link'],
                   email=flask_session['email'],
                   google_plus_id=flask_session['google_plus_id'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(
        google_plus_id=flask_session['google_plus_id']).one()
    return user.id
Exemple #3
0
def mfw_create(category_name=""):
    """page to create a new Mental Framework."""
    #guard clauses:
    if 'access_token' not in flask_session:
        return logInRedirect()
    user_id = getUserId(flask_session['email'],
                        flask_session['google_plus_id'])
    #form initialization
    mfwForm = MFWForm(request.form)

    if request.method == "POST":  #and mfwForm.validate():
        mfw = MFW()
        mfwForm.populate_obj(mfw)
        mfw.creator_id = user_id
        duplicate_mfw = session.query(MFW).\
                                filter_by(name = mfw.name).\
                                first()
        if duplicate_mfw:
            flash("The name " + mfw.name + " already exists.")
            return redirect(url_for("mfw_create", form=mfwForm))
        try:
            uploaded_image = upload_image(request.files['image_file'])
        except:
            uploaded_image = False
        if uploaded_image: mfw.image_url = uploaded_image

        mfw = parse_categories(mfw, request.form['category'])
        session.add(mfw)
        session.commit()

        # add elements to mfw object from numbered element form fields
        i = 0
        while i < 20:
            try:
                element = Element(letter=request.form['element' + str(i) +
                                                      '-letter'],
                                  description=request.form['element' + str(i) +
                                                           '-description'],
                                  order=i,
                                  mfw_id=mfw.id)
                session.add(element)
                i = i + 1
            except:
                break
        session.commit()
        flash("new MFW '" + mfw.name + "' created!")
        print "\nmfw POST triggered, name is: ", mfw.name
        return redirect(url_for("mfw_browse"))

    else:
        return render_template('mfw_create.html',
                               mfwForm=mfwForm,
                               category_name=category_name)
Exemple #4
0
def newElement(mfw_id):
    """page to create a new menu item."""

    if 'access_token' not in flask_session:
        return logInRedirect()
    mfw = session.query(MFW).filter_by(id = mfw_id).first()
    user_id = getUserId(flask_session['email'],flask_session['google_plus_id'])
    if not mfw.user_id == user_id:
        flash("Only MFW owners can add new items.")
        return redirect(url_for("publicMenu",mfw_id = mfw_id))

    if request.method == "POST":
        mfw_name = request.form['mfw_name']
        print "\nnewElement POST triggered, name is: ", mfw_name
        newElement = element( name=mfw_name, mfw_id=mfw.id )
        session.add(newElement)
        session.commit()
        flash( "new item '" + mfw_name + "' created!")
        print "POST worked!"
        return redirect(url_for("showMenu", mfw_id=mfw.id))

    else:
        return render_template('newElement.html', mfw = mfw )
Exemple #5
0
def category_create():
    """page to create a new Mental Framework."""
    form = CategoryForm(request.form)
    # if request.method == "POST" and form.validate():
    if request.method == "POST":
        if 'access_token' not in flask_session:
            return logInRedirect()
        user_id = getUserId(
                      flask_session['email'],flask_session['google_plus_id'] )
        new_category = Category( name = request.form['category_name'],
                                 description = request.form['category_description'],
                                 creator_id = user_id )
        session.add(new_category)
        session.commit()
        flash( "new Category '" + new_category.name + "' created!" )
        print "\nnew_category POST triggered, name is: ", new_category.name
        return redirect(url_for("category_browse"))

    else:
        if 'access_token' not in flask_session:
            return logInRedirect()
        user_id = getUserId(
                      flask_session['email'], flask_session['google_plus_id'] )
        return render_template('category_create.html')
Exemple #6
0
def mfw_edit(mfw_id):
    """page to edit a MFW. (authorized only for creators)"""
    # guard clauses:
    if 'access_token' not in flask_session:
        return logInRedirect()
    mfw = session.query(MFW).filter_by(id=mfw_id).first()
    user_id = getUserId(flask_session['email'],
                        flask_session['google_plus_id'])
    if not mfw.creator_id == user_id:
        return redirect(url_for("mfw_view", mfw_id=mfw_id))
        flash("Only the creator of a MFW can edit items.")

    # form initialization
    mfwForm = MFWForm(request.form, mfw)
    elementForms = []
    for element in mfw.elements:
        elementForm = ElementForm(None, element)
        elementForms.append(elementForm)

    if request.method == "POST":
        print "\nmfw_edit POST triggered, name is: ", mfwForm.name.data
        old_name = mfw.name
        mfwForm.populate_obj(mfw)

        # populate elements of the mfw object from numbered element form fields
        i = 0
        while i < 20:
            try:
                elementForm = ElementForm(
                    id=int(request.form['element' + str(i) + '-id']),
                    letter=request.form['element' + str(i) + '-letter'],
                    description=request.form['element' + str(i) +
                                             '-description'],
                    order=i)
                elementForm.populate_obj(mfw.elements[i])
                i = i + 1
            except:
                break

        try:
            edited_image_file = upload_image(
                request.files['edited_image_file'])
        except:
            edited_image_file = False
        if edited_image_file: mfw.image_url = edited_image_file

        mfw = parse_categories(mfw, request.form['edited_categories'])

        session.add(mfw)
        session.commit()
        flash("item '" + old_name + "' edited to '" + mfw.name + "'. Jawohl!")
        return redirect(url_for("mfw_view", mfw_id=mfw_id))

    else:
        # prep 'categories' field and serve page
        category_names = ""
        for category in mfw.categories:
            if category_names == "": category_names = category.name
            category_names = category_names + ", " + category.name
        return render_template('mfw_edit.html',
                               mfwForm=mfwForm,
                               elementForms=elementForms,
                               category_names=category_names)