def testExactSearch(self): text = 'Hello world', 'New world' Entry(text=text[0], tags=text[0].split()).put() Entry(text=text[1], tags=text[1].split()).put() search_text = 'Hello world' results = Entry.exact_search(search_text) self.assertEqual(1, len(results)) self.assertEqual(search_text, results[0].text)
def testDeleteEntity(self): text = 'Hello world' Entry(text=text, tags=text.split()).put() results = Entry.exact_search(text) self.assertEqual(1, len(results)) results[0].delete_entry() results = Entry.exact_search(text) self.assertEqual(0, len(results))
def submission(): text = request.form['text'] if not Entry.already_exists(text): Entry(text=text, tags=text.split()).put() feedback = 'SUCCESS' else: feedback = 'ERROR: Duplicate text entered!!!' return render_template('home.html', submit_feedback=feedback)
def testKeywordSearch(self): text = 'Hello world', 'New world', 'Hello in ndb' Entry(text=text[0], tags=text[0].split()).put() Entry(text=text[1], tags=text[1].split()).put() Entry(text=text[2], tags=text[2].split()).put() search_text = 'world' results = Entry.keyword_search(search_text) self.assertEqual(2, len(results)) search_text = 'ndb' results = Entry.keyword_search(search_text) self.assertEqual(1, len(results)) self.assertEqual('Hello in ndb', results[0].text)
def show(entry_id): entry_schema = EntrySchema() entry = Entry.get(id=entry_id) if not entry: abort(404) return entry_schema.dumps(entry), 200
def login_confirm_exec(): entry = Entry( title=request.form['title'], text=request.form['text'], name=current_user.id ) db.session.add(entry) db.session.commit()
def create(): entry_schema = EntrySchema() try: data = entry_schema.load(request.get_json()) entry = Entry(**data, created_by=g.current_user) db.commit() except ValidationError as err: return jsonify({'error': err.messages}), 422 return entry_schema.dumps(entry), 201
def delete(entry_id): entry = Entry.get(id=entry_id) if not entry: abort(404) try: entry.delete() db.commit() except ValidationError as err: return jsonify({'error': err.messages}), 422 return jsonify({'message': 'Entry deleted'}), 201
def update(entry_id): entry_schema = EntrySchema() entry = Entry.get(id=entry_id) if not entry: abort(404) try: data = entry_schema.load(request.get_json()) entry.set(**data) db.commit() except ValidationError as err: return jsonify({'error': err.messages}), 422 return entry_schema.dumps(entry), 201
def _create_entries(self, texts: List[str], labels: List[str], speaker_names: List[str], parsed_speaker_names: List[tuple]) -> List[Entry]: """converts data into a list of Entry objects. """ entries = [] for i in range(len(texts)): # if entry_type in ['speech_new', 'speech_ctd']: # entry_type = 'speech' title, speaker_cleaned, appointment = parsed_speaker_names[i] entry = Entry(entry_type=labels[i], text=texts[i], speaker=speaker_names[i], page_number=None, speaker_cleaned=speaker_cleaned, title=title, appointment=appointment) entries.append(entry) return entries
def add_entry(): if not session.get('logged_in'): abort(401) try: entry = Entry(title=request.form['title'], text=request.form['text']) db = get_db() # 添加到session: ret = db.add(entry) print "add ret:", ret # 提交即保存到数据库: db.commit() # 关闭session: db.close() flash('New entry was successfully posted') except: flash('New entry posted failed') db.rollback() db.close() return redirect(url_for('show_entries'))
def all_text(): entries = Entry.get_all_entries() return render_template( 'all_entries.html', texts=entries)
def index(): entry_schema = EntrySchema(many=True) entries = Entry.select() return entry_schema.dumps(entries), 200
def testInsertEntity(self): text = 'Hello world', 'New world' Entry(text=text[0], tags=text[0].split()).put() Entry(text=text[1], tags=text[1].split()).put() self.assertEqual(2, len(Entry.get_all_entries()))
def search(): text = request.form['text'] entries = Entry.keyword_search(text) return render_template( 'search_result.html', results=entries)
def cleared(): Entry.delete_all() return render_template('home.html')
west_bengal = State(name="West Bengal") andaman_and_nicobar_islands = State(name="Andaman and Nicobar Islands") chandigarh = State(name="Chandigarh") dadar_and_nagar_haveli = State(name="Dadar and Nagar Haveli") daman_and_diu = State(name="Daman and Diu") daman = State(name="Daman") dehli = State(name="Delhi") lakshadeep = State(name="Lakshadeep") pondicherry = State(name="Pondicherry") Entry( title="Majestic shopping town on majestic lake!", description='Udaipur has a romance of setting unmatched in Rajasthan and arguably in all India – snuggling beside tranquil Lake Pichola, with the purple ridges of the Aravalli Range stretching away in every direction. Fantastical palaces, temples, havelis (traditional, ornately decorated residences) and countless narrow, crooked, timeless streets add the human counterpoint to the city’s natural charms. For the visitor theres the serenity of boat rides on the lakes, the bustle and colour of bazaars, a lively arts scene, the quaint old world feel of its heritage hotels, tempting shops and some lovely countryside to explore on wheels, feet or horseback.', location="Udaipur, Rajasthan, India", state=rajastan, category=going, lng=73.712479, lat=24.585445, created_by=stuseem, photo="https://img.traveltriangle.com/blog/wp-content/uploads/2018/07/udaipur-city-palace-blue-boat-cover-image.jpg" ) Entry( title="Quaint, bustling village perched on ghats.", description='Pushkar has a magnetism all of its own – it’s quite unlike anywhere else in Rajasthan. It is world famous for its spectacular Camel Fair, which takes place in the Hindu month of Kartika (October/November). If you are anywhere nearby at the time you would be crazy to miss it. For the rest of the year Pushkar remains a prominent Hindu pilgrimage town, humming with puja (prayers), bells, drums and devotional songs. The town wraps itself around a holy lake featuring 52 bathing ghats and 400 milky-blue temples, including one of the world’s few Brahma temples. The main street is one long bazaar, selling anything to tickle a traveller’s fancy, from hippy-chic tie-dye to didgeridoos. The result is a muddle of religious and tourist scenes. Yet, despite the commercialism, the town remains enchantingly mystic and relaxed. Pushkar is only 11km from Ajmer, separated from it by rugged Nag Pahar (Snake Mountain)', location="Pushkar, Rajasthan, India", state=rajastan, category=going, lng=74.557300, lat=26.492000, created_by=stuseem,