def saveNewArticle(self): appid, title, sub_title, validate_date, desc, content = _gs('appid', 'title', 'sub_title', 'validate_date', 'desc', 'content') if not appid : flash(MSG_NO_ID_SUPPLIED, MESSAGE_WARNING) return redirect(url_for('.view')) if not title: flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createArticle', appid = appid)) try: article = AppArticle( app_id = appid, title = title, sub_title = sub_title, desc = desc, content = content, validate_date = validate_date, ) DBSession.add(article) DBSession.flush() article.seq = article.id DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for(".view", action = "listArticle", appid = appid)) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) traceback.print_exc() return redirect(url_for(".view", action = "listArticle", appid = appid))
def saveNewApp(self): appName, appDesc = _gs('appName', 'appDesc') if not appName: flash(MSG_NO_APP_NAME, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createApp')) try: DBSession.query(AppObject).filter(and_(AppObject.active == 0, AppObject.name == appName)).one() except: try: app = AppObject(name = appName, desc = appDesc) DBSession.add(app) DBSession.flush() url = createApp(session['user_profile']['id'], APP_FOLDER, APP_PACKAGE, 'app%s' % app.id, app.name) if not url : raise Exception('App generation error!') url = '%s%s' % (WEBSITE_ROOT, url) imgFile = createQR(url) if not imgFile : raise Exception('QR code generation error!') DBSession.add(imgFile) app.appfile = imgFile DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) self._updateAppInSession() return redirect(url_for('.view')) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view')) else: flash(MSG_APP_NAME_DUPLICATED, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createApp'))
def ajaxListArticle(self): print "*" * 20 print "Get the article list!" print "_" * 20 appid, page = _gs('appid', 'page') if not page : page = 1 articles = DBSession.query(AppArticle).filter(and_(AppArticle.active == 0, AppArticle.app_id == appid,)).order_by(AppArticle.seq) return jsonify({ 'code' : 0, 'data' : [[a.id, unicode(a)] for a in articles[(page - 1) * PAGINATE_PER_PAGE : page * PAGINATE_PER_PAGE]] })
def saveApp(self): appid, appDesc = _gs('id', 'appDesc') try: app = DBSession.query(AppObject).filter(and_(AppObject.id == appid, AppObject.create_by_id == session['user_profile']['id'])).one() except: flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR) return redirect(url_for('.view')) try: app.desc = appDesc DBSession.commit() flash(MSG_UPDATE_SUCC, MESSAGE_INFO) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view'))
def savePassword(self): oldpassword, newpassword, newconfirmpassword = _gs('oldpassword', 'newpassword', 'newconfirmpassword') if not oldpassword or not newpassword or not newconfirmpassword: flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING) return redirect(url_for('.view')) user = DBSession.query(User).get(session['user_profile']['id']) if not user.validate_password(oldpassword): flash(MSG_WRONG_PASSWORD, MESSAGE_WARNING) return redirect(url_for('.view')) if newconfirmpassword != newpassword: flash(MSG_WRONG_CONFIRM_PASSWORD, MESSAGE_WARNING) return redirect(url_for('.view')) try: user.password = newpassword DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view'))
def check(self): email, password = _gs('email', 'password') if not email or not password : flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING) return redirect(url_for('bpRoot.view', action = 'login', next = _g('next'))) try: # u = DBSession.query(User).filter(and_(User.active == 0, User.email.op('ilike')(_g('email')))).one() u = DBSession.query(User).filter(and_(User.active == 0, User.email == email)).one() except: _error(traceback.print_exc()) flash(MSG_USER_NOT_EXIST, MESSAGE_WARNING) return redirect(url_for('bpRoot.view', action = 'login', next = _g('next'))) else: if not u.validate_password(_g('password')): flash(MSG_WRONG_PASSWORD, MESSAGE_WARNING) return redirect(url_for('bpRoot.view', action = 'login', next = _g('next'))) else: # fill the info into the session session['login'] = True session['user_profile'] = u.populate() permissions = set() for g in u.groups: for p in g.permissions: permissions.add(p.name) session['user_profile']['groups'] = [g.name for g in u.groups] session['user_profile']['permissions'] = list(permissions) apps = DBSession.query(AppObject).filter(and_(AppObject.active == 0, AppObject.create_by_id == u.id)).order_by(AppObject.create_time) session['apps'] = [(app.id, unicode(app)) for app in apps] u.last_login = dt.now() session.permanent = True DBSession.commit() if _g('next') : return redirect(_g('next')) return redirect(url_for('bpConsoles.view', action = 'index'))
def saveArticle(self): aid, title, sub_title, validate_date, desc, content = _gs('id', 'title', 'sub_title', 'validate_date', 'desc', 'content') if not aid : flash(MSG_NO_ID_SUPPLIED, MESSAGE_WARNING) return redirect(url_for('.view')) if not title: flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING) return redirect(url_for('.view', action = 'updateArticle', id = aid)) try: article = DBSession.query(AppArticle).get(aid) article.title = title article.sub_title = sub_title article.validate_date = validate_date article.desc = desc article.content = content DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'listArticle', appid = article.app_id)) except: DBSession.rollback() traceback.print_exc() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view', action = 'updateArticle', id = aid))