Beispiel #1
0
def reorderMenu(menuId, pageId=None, targetOrder=None):
    menu = dbSession.query(Menu).get(menuId)

    pages = dbSession.query(Page).order_by(Page.order).all()

    # make sure the page is in the correct spot
    if pageId:
        index = map(lambda page: page.id, pages).index(pageId)
        if index != targetOrder:
            pages.insert(targetOrder, pages.pop(index))

    for i,page in enumerate(pages):
        page.order = i
    dbSession.commit()
Beispiel #2
0
def header(forcedName=None):
    if request.method == 'POST':
        fileName = secure_filename(urlparse.unquote(request.headers['X-File-Name']))
        if allowed_file(fileName):
            filePath = os.path.join(app.config['UPLOAD_FOLDER'], fileName)
            with open(filePath, 'w') as fd:
                fd.write(request.data)

            # delete existing header
            dbSession.query(ImageTag).filter(ImageTag.tag == "header").delete()

            tag = ImageTag(hash=md5(filePath), tag='header', path=fileName)
            dbSession.add(tag)
            dbSession.commit()

        return 'done'
    else:
        imageTag = dbSession.query(ImageTag).filter(ImageTag.tag == "header").first()
        data = { 'url' : _getHeaderUrl() }

        return flask.jsonify(**data)
Beispiel #3
0
def pageOrder(pageId):
    page = dbSession.query(Page).get(pageId)

    prevOrder = int(request.form['srcIndex'])
    targetOrder = int(request.form['targetIndex'])

    srcMenuId = request.form['srcMenuId']
    targetMenuId = request.form['targetMenuId']

    # remove from one, put in another
    if targetMenuId != srcMenuId:
        page.menuId = targetMenuId
        dbSession.commit()

    reorderMenu(targetMenuId, pageId, targetOrder)

    return 'done'
Beispiel #4
0
 def all(cls):
     return dbSession.query(cls).all()
Beispiel #5
0
def _getHeaderUrl():
    imageTag = dbSession.query(ImageTag).filter(ImageTag.tag == "header").first()
    return '/uploads/' + imageTag.path
Beispiel #6
0
def page(pageId):
    page = dbSession.query(Page).get(pageId)
    page.title = request.form['title']
    dbSession.commit()

    return 'done'
Beispiel #7
0
def menu(menuId):
    menu = dbSession.query(Menu).get(menuId)
    menu.title = request.form['title']
    dbSession.commit()

    return 'done'
Beispiel #8
0
def p(pageId, dummy):
    menus = getMenusWithPages()
    page = dbSession.query(Page).get(pageId)
    return render_template('page.html', menus=menus, page=page)