Beispiel #1
0
    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()
Beispiel #2
0
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")
Beispiel #3
0
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)
Beispiel #4
0
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')
Beispiel #5
0
 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)
Beispiel #6
0
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)
Beispiel #7
0
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")
Beispiel #8
0
    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='******'))
Beispiel #9
0
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))
Beispiel #10
0
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")
Beispiel #11
0
 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)
Beispiel #12
0
    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='******'))
Beispiel #13
0
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')
Beispiel #14
0
    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='******'))
Beispiel #15
0
 def add_bookmark(url, description, tags):
     db.session.add(
         Bookmark(url=url, description=description, user=adi, tags=tags))
Beispiel #16
0
def index():
    return render_template('index.html', new_bookmarks=Bookmark.newest(5))
Beispiel #17
0
 def add_bookmark(url, description, tags):
     db.session.add(
         Bookmark(url=url, description=description, tags=tags, user=xarisd))
def index():
    return render_template('index.html', new_bookmarks=Bookmark.newest(5))
Beispiel #19
0
def newbookmarks(num):
    # return sorted(bookmarks, key=lambda bm: bm['date'], reverse=True)[:num]
    return Bookmark.newbookmarks(num=num)
Beispiel #20
0
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))