def new_account(handler, route, params): username = params.get("nickname", None) password = params.get("password", None) if Writer.get_by_key_name(username): raise Exception("I don't think so") if not username or not password: raise Exception("Invalid request") account = Writer.get_or_insert(username, nickname=username, password=password) handler.session["account"] = str(account.key()) return {}
def save_as(self, event): options = QFileDialog.Options() path, format = QFileDialog.getSaveFileName( self, "caption", '', "SPSS Statistics (*.sav);;" "FatsStat (*.frs)", '', options) logger.debug(path) logger.debug(format) ext = os.path.splitext(path)[1][1:] logger.debug(ext) writer = Writer(path, Writer.ExtensionsFormat[ext]) try: writer.write() except Exception as e: logger.error(e) QMessageBox.critical(self, "Error", str(e))
def writers(): writers = Writer.query.all() if request.method == 'GET': writer_add_form = WriterAddForm() writer_edit_form = WriterEditForm() else: if request.form['btn'] == 'Edit': # handle writers edit form writer_add_form = WriterAddForm() writer_edit_form = WriterEditForm(request.form) if writer_edit_form.validate(): writer = Writer.query.filter_by( id=writer_edit_form.id.data).first() writer.edit(name=writer_edit_form.name.data) return redirect(url_for('writers')) else: # handle writers add form writer_edit_form = WriterEditForm() writer_add_form = WriterAddForm(request.form) if writer_add_form.validate(): Writer.add(name=writer_add_form.name.data) return redirect(url_for('writers')) return render_template('writers.html', writers=writers, writer_edit_form=writer_edit_form, writer_add_form=writer_add_form)
def delete_writer(writer_id): Writer.delete(writer_id) return redirect(url_for('writers'))
def doesuserexist(handler, route, params): return {"exists": Writer.get_by_key_name(params.get("nickname", None)) and True or False}
def add_videos(): req_Data = request.get_json() videoIdStr = req_Data.get("videoId") videoName = req_Data.get("videoName") replaceDateTimeStr = req_Data.get("replaceDateTime") videoInfoUrl = req_Data.get("videoInfoUrl") videoTypeStr = req_Data.get("videoType") address = req_Data.get("address") coverImgUrl = req_Data.get("coverImgUrl") photoListStr = req_Data.get("photoList") scenarioInfo = req_Data.get("scenarioInfo") # actorListStr = req_Data.get("actorList") # writeListStr = req_Data.get("writeList") # directorListStr = req_Data.get("directorList") actorListStr = remove_duplicate(req_Data.get("actorList"), "actorName", "actorHeadUrl") writeListStr = remove_duplicate(req_Data.get("writeList"), "writerName", "writerHeadUrl") directorListStr = remove_duplicate(req_Data.get("directorList"), "directorName", "directorHeadUrl") # print("传过来的数据处理前:", req_Data.get("actorList")) # print("传过来的数据处理后:", actorListStr) if not all(['videoId', 'videoName']): return jsonify(code=400, msg='参数不完整') videoItem = videos(videoId=videoIdStr, videoName=videoName, videoInfoUrl=videoInfoUrl, address=address, coverImgUrl=coverImgUrl, scenarioInfo=scenarioInfo, replaceDateTime = replaceDateTimeStr ) needSaveArr = [] # 剧照 for urlStr in photoListStr: ph = PhotoList(imgUrl=urlStr, videoId=videoIdStr) videoItem.photoList.append(ph) # 类型 type_list = [] for typeItem in videoTypeStr: if VideoTypes.query.filter_by(typeName=typeItem).first(): type_list.append(VideoTypes.query.filter_by(typeName=typeItem).first()) else: type_list.append(VideoTypes(typeName=typeItem)) videoItem.videoType = type_list # 演员 list_actors = [] for actorItem in actorListStr: acName = actorItem.get('actorName') acUrl = actorItem.get('actorHeadUrl') if ActorList.query.filter_by(actorName=acName).first(): list_actors.append(ActorList.query.filter_by(actorName=acName).first()) else: list_actors.append(ActorList(actorName=acName,actorHeadUrl=acUrl)) videoItem.actorList = list_actors # 编剧 list_writers = [] for writerItem in writeListStr: wrName = writerItem.get('writerName') wrUrl = writerItem.get('writerHeadUrl') if Writer.query.filter_by(writerName=wrName).first(): list_writers.append(Writer.query.filter_by(writerName=wrName).first()) else: list_writers.append(Writer(writerName=wrName, writerHeadUrl=wrUrl)) videoItem.writeList = list_writers # 导演 list_directors = [] for directorItem in directorListStr: diName = directorItem.get('directorName') diUrl = directorItem.get('directorHeadUrl') if Director.query.filter_by(directorName=diName).first(): list_directors.append(Director.query.filter_by(directorName=diName).first()) else: list_directors.append(Director(directorName=diName, directorHeadUrl=diUrl)) videoItem.directorList = list_directors needSaveArr.insert(0, videoItem) try: db.session.add_all(needSaveArr) db.session.commit() return jsonify(code=200, msg=videoName + ':保存成功') except Exception as e: db.session.rollback() print(e) return jsonify(code=400, msg=videoName + ':失败')