def setUp(self): thermos.admin._views = [] #Workaround for blueprint registration #rest_api.resources = [] #Workaround for blueprint registration self.db = thermos.db with self.app.app_context(): self.db.create_all() self.client = self.app.test_client() self.test_user = User(username='******', email='*****@*****.**', password='******') self.db.session.add(self.test_user) bm = Bookmark(user=self.test_user, url='http://hackaday.com', description='A DIY hacking blog', tags='one,two,three') self.db.session.add(bm) self.db.session.commit() other_user = User(username='******', email='*****@*****.**', password='******') self.db.session.add(other_user) bm2 = Bookmark(user=other_user, url='http://phys.org', description='A phyics news site', tags='one,two,three') self.db.session.add(bm2) self.db.session.commit()
def init_db(): db.create_all() db.session.add(Bookmark(url="http://goole.com", description="dbuabda")) db.session.add(Bookmark(url="http://mama.com", description="dbudeddabda")) db.session.commit() print("Initialized the database")
def add(): form = BookmarkForm() application.logger.info('Route to /add') application.logger.debug('no reroute from root to /add') if form.validate_on_submit(): url = form.url.data description = form.description.data user = form.user.data application.logger.info(str(url), str(description), str(user)) print(db.session) bkusr = User.query.filter_by(username=user).first() if not bkusr and user: bkusr = User(username=user, email=user + "@thermos.com") db.session.add(bkusr) tags = form.tags.data bkm = Bookmark(url=url, description=description, user=bkusr or current_user, bkmrkusername=bkusr.username, tags=tags) db.session.add(bkm) db.session.commit() storebookmark(url, user, description) # if request.method == "POST": # url = request.form.get("url") # user = request.form.get("user") # storebookmark(url, user) application.logger.info("Added url for user url: {}, user: {}".format( url, user or "Debabrata")) flash("Bookmarked url: {} for user: {}".format( url, user if user else "Debabrata(Default)")) return redirect(url_for("index")) return render_template("bookmarkform.html", form=form)
def insert_data(): mickey = User(username="******", email="*****@*****.**", password="******") db.session.add(mickey) minnie = User(username="******", email="*****@*****.**", password="******") db.session.add(minnie) tag1 = Tag(name="news") db.session.add(tag1) tag2 = Tag(name="music") db.session.add(tag2) db.session.add(Bookmark(url="https://www.cnn.com", description="cnn", user=mickey, tags="news")) db.session.add(Bookmark(url="https://www.mtv.com", description="mtv", user=minnie, tags="music, news")) db.session.commit() print('Initialized the database')
def test_bookmark_newest(self): with self.app.app_context(): user = User.query.filter_by(username='******').first() self.db.session.add( Bookmark(user=user, url='http://hackaday.com', description='A DIY hacking blog', tags='one,two,three')) self.db.session.commit() response = self.client.get(url_for('main.index')) self.assertEqual(self.get_context_variable('new_bookmarks').count(), 1)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data bm = Bookmark(user=current_user, url=url, description=description) db.session.add(bm) db.session.commit() flash(f"stored : {description}") return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data bm = Bookmark(user=current_user, url=url, description=description) db.session.add(bm) db.session.commit() flash("Stored '{}'".format(description)) return redirect(url_for('index')) return render_template('bookmark_form.html', form=form, title="Add a bookmark")
def setUp(self): self.db = thermos.db self.db.create_all() self.client = self.app.test_client() u = User(username='******', email='*****@*****.**', password='******') bm = Bookmark(user=u, url="http://www.example.com", tags="one,two,three") self.db.session.add(u) self.db.session.add(bm) self.db.session.commit() self.client.post(url_for('auth.login'), data=dict(username='******', password='******'))
def index(): # return "Hello World in Flask WORLD!!!!!" application.logger.info('Route to /index via root') # return render_template("index.html", title="Title Passed from View to Template", # text="Sample text for the Web Application.", # user=Userobj("Debabrata", "Patnaik"), newbookmarks=newbookmarks(5)) return render_template("index.html", title="Title Passed from View to Template", text="Sample text for the Web Application.", user=current_user, newbookmarks=Bookmark.newbookmarks(5))
def add(): form = BookmarkForm() # Checks the http request method and the user submitted data in the form if form.validate_on_submit(): url = form.url.data description = form.description.data tags = form.tags.data bm = Bookmark(user=current_user, url=url, description=description, tags=tags) db.session.add(bm) db.session.commit() flash("Stored '{}'".format(description)) return redirect(url_for('main.index')) return render_template('bookmark_form.html', form=form, title="Add a bookmark")
def add_bookmark(url, desc, tags): bkm = Bookmark(url=url, description=desc, user=random.choice(ulist), tags=tags) # tglist = list() # for t in tags.split(","): # tg = Tag.query.filter_by(name=t).first() # if not tg: # tg = Tag(name=t) # db.session.add(tg) # tglist.append(tg) # for tgs in tglist: # bkm._tags.append(tgs) db.session.add(bkm)
def setUp(self): self.db = thermos.db self.db.create_all() # test_client instance will let us make requests keeps track of cookies etc so we can login self.client = self.app.test_client() u = User(username='******', email='*****@*****.**', password='******') bm = Bookmark(user=u, url="http://www.example.com", tags="one,two,three") self.db.session.add(u) self.db.session.add(bm) self.db.session.commit() # login as user we just created self.client.post(url_for('auth.login'), data=dict(username='******', password='******'))
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data tags = form.tags.data bookmark = Bookmark(user=current_user, url=url, description=description, tags=tags) db.session.add(bookmark) db.session.commit() flash(f'Stored "{description}"') return redirect(url_for('index')) return render_template('bookmark_form.html', form=form, title='Add a new bookmark')
def setUp(self): self.db = thermos.db self.db.create_all() self.client = self.app.test_client() password = '******' u = User(nm_firstName='Camila', nm_lastName='SerrĂ£o', nm_userName='******', nm_email='*****@*****.**', nm_passwordHash=password) bm = Bookmark(user=u, nm_url='http://example.com', nm_description='Just an example', tags='one,two,three') self.db.session.add(u) self.db.session.add(bm) self.db.session.commit() self.client.post(url_for('auth.login'), data=dict(nm_userName='******', password='******'))
def add_bookmark(url, description, tags): db.session.add( Bookmark(url=url, description=description, user=adi, tags=tags))
def index(): return render_template('index.html', new_bookmarks=Bookmark.newest(5))
def add_bookmark(url, description, tags): db.session.add( Bookmark(url=url, description=description, tags=tags, user=xarisd))
def newbookmarks(num): # return sorted(bookmarks, key=lambda bm: bm['date'], reverse=True)[:num] return Bookmark.newbookmarks(num=num)
def index(): #user = User("Berkan","Yavri") #return render_template('index.html', title="Title passed from view to template", text=user.firstname+" "+user.lastname) return render_template('index.html', new_bookmarks=Bookmark.newest(5))