def create_list(W_count, U_list): L = [] U_count = len(U_list) while W_count > 0: for this_Unit in U_list: U = Units.objects(Title=this_Unit).first() li = U.List if W_count / U_count > len(li): random.shuffle(li) for this_word in li: L.append(Words.objects(Title=this_word).first().Meaning) W_count = W_count - len(li) U_count = U_count - 1 else: k = W_count / U_count while k > 0: wo = random.choice(li) Mean = Words.objects(Title=wo).first().Meaning if Mean in L: continue else: k = k - 1 W_count = W_count - 1 L.append(Mean) return L
def trans_out(T): Lin = '' U = Units.objects(Title=T).first() for i in U.List: W = Words.objects(Title=i).first() Lin = Lin + str(W.Title) + "\n" return Lin
def enter(Len): Len = str(Len) Len = Len.split('\r\n') print(Len) for group in Len: group = group.split('|') print(group) Wo = Words.objects(Title=group[0]).first() if Wo != None: Wo.update(Meaning=group[1]) continue Wo = Words(Title = group[0],Meaning = group[1]) Wo.save() return
def ones(T): U = Units.objects(Title=T).first() Woli = U.List Li = [] for i in Woli: l = Words.objects(Title=i).first() Li.append({'Title': l.Title, 'Meaning': l.Meaning}) return render_template('U/ones.html', title=T, L=Li)
def trans_in(Lin, T): U = Units.objects(Title=T).first() L = U.List Lin = Lin.split('\r\n') Eor = [] for i in Lin: title = i if Words.objects(Title=title).first() == None: Eor.append(title) continue if title not in L: L.append(title) U.update(List=L) return Eor
def change(): change_title = request.args.get('title','') Wo = Words.objects(Title=change_title).first() if Wo is None: abort(404) Form = WordsForm() if Form.validate_on_submit(): Wo.update(Title= Form.Title.data,Meaning= Form.Meanging.data) flash('Yeah!') return redirect(url_for('Words_views.ones',T=Wo.Title)) Form.Title.data=Wo.Title Form.Meaning.data=Wo.Meaning return render_template('W/change.html',title='Change-'+Wo.Title, Form = Form)
def ones(T): Wo = Words.objects(Title=T).first() return render_template('W/ones.html', title=Wo.Title, Wo = Wo)