예제 #1
0
def add_shop():
	if flask_login.current_user.is_authenticated:
		if request.method == 'POST':
			title = request.form['name']
			description = request.form['description']
			photos = request.files.getlist('photo')
			shop = session.query(Shop).filter_by(user=flask_login.current_user.username).first().name
			new_article = Article(title=title,content=description,date_created=datetime.datetime.now().strftime("%Y-%m-%d"),shop=shop)
			session.add(new_article)
			for photo in photos:
				photoname = secure_filename(photo.filename)
				if(not allowed_file(photoname)):
					return ('photo type is not allowed')
				photodir =  os.path.join(app.config['UPLOAD_FOLDER'], photoname)
				i = 1
				while(session.query(ArticlePhoto).filter_by(dir=photodir).first() or session.query(ShopPhoto).filter_by(dir=photodir).first() or session.query(User).filter_by(photodir=photodir).first()):
					photoname = str(i) + photoname
					photodir =  os.path.join(app.config['UPLOAD_FOLDER'], photoname)	
				new_photo = ArticlePhoto(dir=photodir,articlename=title)
				session.add(new_photo)
				photo.save(os.path.join(app.config['UPLOAD_FOLDER'], photoname))
			session.commit()
			return(redirect(url_for('shop')))
		else:
			return render_template('addshop.html')
예제 #2
0
def create_article():
    if request.method == 'POST':
        article = Article(title=request.form['title'],
                          intro=request.form['intro'],
                          text=request.form['text'])
        session.add(article)
        session.commit()
        return redirect(url_for('posts'))
    else:
        return render_template("create_article.html")
예제 #3
0
def newArticle():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newArticle = Article(name=request.form['name'],
                             user_id=login_session['user_id'])
        session.add(newArticle)
        flash('New Article %s Successfully Created' % newArticle.name)
        session.commit()
        return redirect(url_for('showArticles'))
    else:
        return render_template('newArticle.html')
예제 #4
0
def newArticle():
    article = Article()
    # TODO: handle the authors, pics, etc whatever i do in edit--can i combine these?
    if not isEditorOrAdmin(login_session.get('role')):
        return redirect(url_for('showHome'))
    if request.method == 'POST':
        saveArticleFromForm(article, request.form)
        return redirect(
            url_for('showArticle',
                    article_id=article.id,
                    url_desc=article.url_desc))
    else:
        return render_template('editArticle.html', article=article)
예제 #5
0
def newArticle(company_id):
    session6 = DBSession()
    company = session6.query(Company).filter_by(id=company_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newCompany = Article(name=request.form['name'],
                             description=request.form['description'],
                             price=request.form['price'],
                             type=request.form['type'],
                             company_id=company_id,
                             user_id=company.user_id)

        session6.add(newCompany)
        session6.commit()
        session6.close()

        return redirect(url_for('showArticle', company_id=company_id))
    else:
        return render_template('newArticle.html', company_id=company_id)

    return render_template('newArticle.html')
예제 #6
0
session.commit()

User3 = User(name="Carlos Rodriguez", email="*****@*****.**",
             picture='https://unsplash.it/200/300/?random')
session.add(User3)
session.commit()

# Looping Section 
economySection = Section(name = "economy")

session.add(economySection)
session.commit()

article1 = Article(title = "War for the Planet of the Apes",
			body = "Caesar and his apes are forced into a deadly conflict with an army of humans led by a ruthless Colonel. After the apes suffer unimaginable losses, Caesar wrestles with his darker instincts and begins his own mythic quest to avenge his kind. As the journey finally brings them face to face, Caesar and the Colonel are pitted against each other in an epic battle that will determine the fate of both their species and the future of the planet",
			datetime = "Matt Reeves",
			image = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTeJ2_YwH8yyg_x-GOd9kjgkrNBblmvbSYMpqvlvLfCC0eWd2BF",
			section = economySection,
            user_id = 1)
session.add(article1)
session.commit()

article2 = Article(title = "Spider-Man: Homecoming",
			body = "Thrilled by his experience with the Avengers, Peter returns home, where he lives with his Aunt May, under the watchful eye of his new mentor Tony Stark, Peter tries to fall back into his normal daily routine - distracted by thoughts of proving himself to be more than just your friendly neighborhood Spider-Man - but when the Vulture emerges as a new villain, everything that Peter holds most important will be threatened",
			datetime = "Jon Watts",
			image = "https://images-na.ssl-images-amazon.com/images/M/MV5BNTk4ODQ1MzgzNl5BMl5BanBnXkFtZTgwMTMyMzM4MTI@._V1_SY1000_CR0,0,658,1000_AL_.jpg",
			section = economySection,
            user_id = 1)
session.add(article2)
session.commit()

tecnhologySection = Section(name = "tecnhology")
예제 #7
0
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

user1 = User(user_name = "Gbenga", user_email = "*****@*****.**")

session.add(user1)
session.commit()

user2 = User(user_name = "admin", user_email = "*****@*****.**")

session.add(user2)
session.commit()

article1 = Article(title = "Summer in Lodz", article_body = "I loved travelling in Lodz while interning at University of Lodz", user = user1)

session.add(article1)
session.commit()

comment1 = Comments(comment_text = "Sounds like a great summer !", article = article1)

session.add(comment1)
session.commit()

article2 = Article(title = "Missed flights and Christmases", article_body = "What's missing your first flight like? I'll tell you in 200 words", user = user1)

session.add(article2)
session.commit()

comment2 = Comments(comment_text = "Hope you got a great Christmas", article = article2)
예제 #8
0
session.add(user2)
session.add(user3)


# Add 2 channels
channel1 = Channel(channel_name='The JP Report', owner=user1, start_date=date(2018, 7, 27),
                   description='This is a channel for any news, on any thing')
channel2 = Channel(channel_name='The Michelley Report', owner=user2, start_date=date(2018, 7, 18),
                   description='This is the news Channel of Michelley welly')
session.add(channel1)
session.add(channel2)
session.commit()
#channel1 = Channel(channel_name = 'The JP Report', owner=user1, start_date=date(2018, 7, 27), description='This is a channel for any news, on any thing')
#channel1 = Channel(channel_name = 'The JP Report', owner=user1, start_date=date(2018, 7, 27), description='This is a channel for any news, on any thing')
# Then add 5 articles
article1 = Article(title='JP becomes richest main man', channel=channel1, description='Update on the rich list',
                   article_text='This is all the article text, man', date=date(2018, 6, 8))

article2 = Article(title='JP gets a job', channel=channel1, description='Finally, he\'s bringing in some cash!',
                   article_text='Wow, so JP is this guy, who has been thinking about coding for a loooong time, and he is quite good in some ways, but..',
                   date=date(2018, 6, 8))

article3 = Article(title='Mich out of night shift!', channel=channel2, description='Update on having to work at night!',
                   article_text='This is such a huge relief, we can now finally start looking forward with our life!', date=date(2018, 6, 22))

article4 = Article(title='Michelley makes Schone gifting', channel=channel2, description='Focus on new gifting startup',
                   article_text='This is all the article text, man', date=date(2018, 2, 8))
article5 = Article(title='Starting a new country', channel=channel1, description='People are worried, and they should be',
                   article_text='This is all the article text, man', date=date(2015, 6, 8))

session.add(article1)
session.add(article2)
예제 #9
0
def makeANewPost(title, intro, text):
    addedarticle = Article(title=title, intro=intro, text=text)
    session.add(addedarticle)
    session.commit()
    return jsonify(Article=addedarticle.serialize)
예제 #10
0
from database_setup import Base, User, Article, Author, ArticleAuthor, ArticleResource
from datetime import date
engine = create_engine('sqlite:///flood.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

today = date.today()

TEXT_1 = "By so delight of showing neither believe he present. Deal sigh up in shew away when. Pursuit express no or prepare replied. Wholly formed old latter future but way she. Day her likewise smallest expenses judgment building man carriage gay. Considered introduced themselves mr to discretion at. Means among saw hopes for. Death mirth in oh learn he equal on. He as compliment unreserved projecting. Between had observe pretend delight for believe. Do newspaper questions consulted sweetness do. Our sportsman his unwilling fulfilled departure law. Now world own total saved above her cause table. Wicket myself her square remark the should far secure sex. Smiling cousins warrant law explain for whether. Throwing consider dwelling bachelor joy her proposal laughter. Raptures returned disposed one entirely her men ham. By to admire vanity county an mutual as roused. Of an thrown am warmly merely result depart supply. Required honoured trifling eat pleasure man relation."
TEXT_2 = "Carried nothing on am warrant towards. Polite in of in oh needed itself silent course. Assistance travelling so especially do prosperous appearance mr no celebrated. Wanted easily in my called formed suffer. Songs hoped sense as taken ye mirth at. Believe fat how six drawing pursuit minutes far. Same do seen head am part it dear open to. Whatever may scarcely judgment had. Manor we shall merit by chief wound no or would. Oh towards between subject passage sending mention or it. Sight happy do burst fruit to woody begin at. Assurance perpetual he in oh determine as. The year paid met him does eyes same. Own marianne improved sociable not out. Thing do sight blush mr an. Celebrated am announcing delightful remarkably we in literature it solicitude. Design use say piqued any gay supply. Front sex match vexed her those great."

newArticle1 = Article(title="The very first test article",
                      subtitle="The first subtitle",
                      publish_date=date(today.year, today.month, today.day),
                      url_desc="the-very-first",
                      html_text=TEXT_1,
                      on_home=True,
                      featured=True)
session.add(newArticle1)
session.commit()

newAuthor1 = Author(name="Corey Poff")
session.add(newAuthor1)
session.commit()

newAuthor2 = Author(name="Jonah G.-S.")
session.add(newAuthor2)
session.commit()

newArticleAuthor1 = ArticleAuthor(article_id=newArticle1.id,
예제 #11
0
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()
User1 = User(name="vyshnavi", email="*****@*****.**")
session.add(User1)
session.commit()


company1 = Company(user_id=1, name="Titan")
session.add(company1)
session.commit()
article1 = Article(user_id=1, name="Analog", description="ladies watch",
                   price="$60", type="belt", company=company1)

session.add(article1)
session.commit()

article2 = Article(user_id=1, name="Digital", description="boys watches",
                   type="chain", price="$80", company=company1)

session.add(article2)
session.commit()

article3 = Article(user_id=1, name="Chronograph",
                   description="stop watch combined with a display watch",
                   type="metal", price="$20", company=company1)

session.add(article3)
예제 #12
0
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Check if category exists, if not, create one.
check_c = session.query(
    exists().where(Category.name == category_of_article)).scalar()
if not check_c:
    category1 = Category(name=category_of_article)
    session.add(category1)
    session.commit()

#check if article exists, if not, create one.
check_a = session.query(exists().where(Article.title == title)).scalar()
#Ad new article
if not check_a:
    category1 = session.query(Category).filter_by(
        name=category_of_article).first()
    article1 = Article(title=title,
                       slug=slug,
                       embeded_code=embeded_code,
                       text=text,
                       category=category1,
                       category_id=category1.id)
    session.add(article1)
    session.commit()
예제 #13
0
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

User1 = User(
    name="Robo Barista",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User1)
session.commit()

article1 = Article(user_id=1, name="Advanced Technology")

session.add(article1)
session.commit()

menuItem2 = MenuItem(
    user_id=1,
    name="Cyber Security News",
    description=
    "Focusing on cyberspace security issues, this open access journal Cybersecurity publishes high quality research and expert reviews to report the latest research.",
    price="$27.50",
    course="Computer Science",
    article=article1)

session.add(menuItem2)
session.commit()