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()
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)
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'
def all(cls): return dbSession.query(cls).all()
def _getHeaderUrl(): imageTag = dbSession.query(ImageTag).filter(ImageTag.tag == "header").first() return '/uploads/' + imageTag.path
def page(pageId): page = dbSession.query(Page).get(pageId) page.title = request.form['title'] dbSession.commit() return 'done'
def menu(menuId): menu = dbSession.query(Menu).get(menuId) menu.title = request.form['title'] dbSession.commit() return 'done'
def p(pageId, dummy): menus = getMenusWithPages() page = dbSession.query(Page).get(pageId) return render_template('page.html', menus=menus, page=page)