Esempio n. 1
0
def video_detail(link):
    session = DBSession()
    comments_array = session.query(Comment).filter_by(
        video_id="https://www.youtube.com/embed/" + link).all()
    return render_template("comments.html",
                           video_link="https://www.youtube.com/embed/" + link,
                           comments=comments_array)
Esempio n. 2
0
def lesson_detail():
    try:
        session = DBSession()
        video_values = session.query(Videos).filter_by(
            user_id=current_user.get_id()).all()
        return render_template("lesson_page.html", videos=video_values)
    except Exception as e:
        raise e
Esempio n. 3
0
def story(sid):
	name = session.get('name')
	if not name:
		return redirect(url_for('signin'))
	else:
		user=DBSession.query(User).filter_by(name = name).first()
		story = DBSession.query(Story).filter_by(id = sid).first()
		return render_template("story.html", story = story, user = user)
Esempio n. 4
0
def lesson_plan():
    try:
        if request.method == "POST":
            session = DBSession()
            unit_value = request.form.get("unit", None)
            title_value = request.form.get("title", None)
            purpose_value = request.form.get("purpose")
            grade_value = request.form.get("grade")
            description_value = request.form.get("description", None)
            time_value = request.form.get("time", None)
            user_id_value = current_user.get_id()
            file = request.files["video"]
            if file is not None:
                file.save(
                    os.path.join("./uploads", secure_filename(file.filename)))
            lesson_plan = LessonPlan(unit=unit_value,
                                     title=title_value,
                                     purpose=purpose_value,
                                     class_value=grade_value,
                                     user_id=user_id_value,
                                     description=description_value,
                                     timestamp=time_value)
            session.add(lesson_plan)
            if file is not None:
                added_lesson_plans = session.query(LessonPlan).all()
                pic = Pics(path=application.config["UPLOAD_FOLDER"] +
                           file.filename,
                           lesson_id=added_lesson_plans[-1].id)
                session.add(pic)
            session.commit()
            return redirect(url_for("lesson_detail"))
        else:
            return render_template("create_lesson.html")
    except Exception as e:
        raise e
Esempio n. 5
0
def newstory():
	if request.method == 'GET':
		return render_template('test.html')
	else:
		new_name = request.form['username']
		new_writer = request.form['email']
		new_content = request.form['password']
		new_pic = request.form['age']
		new_story=Story(name= new_name,writer=new_writer, story= new_content , pic= new_pic)
		DBSession.add(new_story)
		DBSession.commit()
		return redirect(url_for('signin'))
Esempio n. 6
0
def signup():
	if request.method == 'GET':
		return render_template('signup2.html')
	else:
		new_name = request.form['username']
		new_email = request.form['email']
		new_password = hash_password(request.form['password'])
		new_age = request.form['age']
		new_user= User(name=new_name,email=new_email,password=new_password,age = new_age)
		DBSession.add(new_user)
		DBSession.commit()
		session['name'] = new_name
		return redirect(url_for('home'))
def menu_item_delete(restaurant_id, menu_id):
    if request.method == "POST":
        with DBSession() as sess:
            menuitem = sess.query(MenuItem).filter_by(
                restaurant_id=restaurant_id).filter_by(id=menu_id).one()
            sess.delete(menuitem)
        flash("Menu item has been deleted")
        return redirect(url_for('restaurant', restaurant_id=restaurant_id))
    else:
        with DBSession() as sess:
            menuitem = sess.query(MenuItem).filter_by(
                restaurant_id=restaurant_id).filter_by(id=menu_id).one()
        return render_template("deletemenuitem.html",
                               restaurant_id=restaurant_id,
                               menuitem=menuitem)
Esempio n. 8
0
def about():
	name = session.get('name')
	if not name:
		return redirect(url_for('signin'))
	else:
		user=DBSession.query(User).filter_by(name = name).first()
		return render_template("about.html",user = user)
def restaurant(restaurant_id):
    with DBSession() as sess:
        restaurant = sess.query(Restaurant).filter_by(id=restaurant_id).one()
        menuitems = sess.query(MenuItem).filter_by(restaurant_id=restaurant.id)
    return render_template("menu.html",
                           restaurant=restaurant,
                           menuitems=menuitems)
def restaurant_edit(restaurant_id):
    if request.method == "POST":
        with DBSession() as sess:
            restaurant = sess.query(Restaurant).filter_by(
                restaurant_id=restaurant_id).one()
            restaurant.name = request.form.get('name')
        flash("Restaurant has been renamed")
        return redirect(url_for(
            'restaurant',
            restaurant_id=restaurant_id,
        ))
    else:
        with DBSession() as sess:
            restaurant = sess.query(Restaurant).filter_by(
                restaurant_id=restaurant_id).one()
        return render_template("editrestaurant.html", restaurant=restaurant)
def menu_item_edit(restaurant_id, menu_id):
    if request.method == "POST":
        with DBSession() as sess:
            menuitem = sess.query(MenuItem).filter_by(
                restaurant_id=restaurant_id).filter_by(id=menu_id).one()
            menuitem.name = request.form.get('name')
            menuitem.price = request.form.get('price')
            menuitem.description = request.form.get('description')
            menuitem.course = request.form.get('course')
        flash("Menu item has been edited")
        return redirect(url_for('restaurant', restaurant_id=restaurant_id))
    else:
        with DBSession() as sess:
            menuitem = sess.query(MenuItem).filter_by(
                restaurant_id=restaurant_id).filter_by(id=menu_id).one()
        return render_template("editmenuitem.html",
                               restaurant_id=restaurant_id,
                               menuitem=menuitem)
Esempio n. 12
0
def signup():
    try:
        if request.method == "POST":
            session = DBSession()
            email_value = request.form.get("email", None)
            name_value = request.form.get("name", None)
            password_value = (hashlib.md5(
                request.form["password"].encode())).hexdigest()
            location_value = request.form.get("location", None)
            unit_preferred_value = request.form.get("unit", None)
            phone_number_value = request.form.get("phone", None)
            school_value = request.form.get("school", None)
            user = User(email=email_value,
                        name=name_value,
                        password=password_value,
                        location=location_value,
                        unit_preferred=unit_preferred_value,
                        school=school_value,
                        phone_number=phone_number_value)
            session.add(user)
            session.commit()
            return redirect(url_for('dashboard'))
        else:
            return render_template("login.html")
    except Exception as e:
        raise e
Esempio n. 13
0
    def do_POST(self):
        print(self.log_request())
        try:
            if self.path.endswith(NEW_LINK) or self.path.endswith(EDIT_LINK) or self.path.endswith(DELETE_LINK):
                self.send_response(301)
                self.send_header("Content-type", "text/html")
                self.send_header('Location', '/restaurants')
                out = ""
                if self.path.endswith(NEW_LINK):
                    fields = self._get_post_param()
                    nameofrestaurant = fields.get("restaurantName")[0] if fields else None
                    with DBSession() as sess:
                        restaurant = Restaurant(name=nameofrestaurant)
                        sess.add(restaurant)
                    out += wrapwithh1("Restaurant {} was added successfully!".format(nameofrestaurant))
                elif self.path.endswith(EDIT_LINK):
                    fields = self._get_post_param()
                    nameofrestaurant = fields.get("restaurantName")[0] if fields else None
                    if nameofrestaurant:
                        id = self.path.split("/")[-2]
                        with DBSession() as sess:
                            restaurant = sess.query(Restaurant).filter_by(id=id).first()
                            restaurant.name = nameofrestaurant
                        out += wrapwithh1("Restaurant {} was edited successfully!".format(nameofrestaurant))
                elif self.path.endswith(DELETE_LINK):
                    id = self.path.split("/")[-2]
                    with DBSession() as sess:
                        restaurant = sess.query(Restaurant).filter_by(id=id).first()
                        nameofrestaurant = restaurant.name
                        sess.delete(restaurant)
                    out += wrapwithh1("Restaurant {} was deleted successfully!".format(nameofrestaurant))

                out += "<br/>"
                out += link(text="Back to Restaurants list", link=LIST_LINK)
                self.end_headers()
                self._send_responce(out)
        except Exception as e:
            raise
def menu_item_new(restaurant_id):
    if request.method == "POST":
        with DBSession() as sess:
            menuitem = MenuItem()
            menuitem.restaurant_id = restaurant_id
            menuitem.name = request.form.get('name')
            menuitem.price = request.form.get('price')
            menuitem.description = request.form.get('description')
            menuitem.course = request.form.get('course')
            sess.add(menuitem)
        flash("The new menu item has been created")
        return redirect(url_for('restaurant', restaurant_id=restaurant_id))
    else:
        return render_template("newmenuitem.html", restaurant_id=restaurant_id)
Esempio n. 15
0
def add_video(videoid):
    try:
        session = DBSession()
        video = Videos(user_id=current_user.get_id(), video_link=videoid)
        session.add(video)
        session.commit()
        return redirect(url_for("lesson_detail"))
    except Exception as e:
        raise e
Esempio n. 16
0
 def _restaurants(self):
     self._create_ok_header()
     path = self._get_server_path()
     out = ""
     out += link(text="Make a new restaurant here", link=path + NEW_LINK)
     out += "<br/><br/>"
     with DBSession() as sess:
         restaurants = sess.query(Restaurant).all()
         for rest in restaurants:
             out += "".join(["<br/>",
                             str(rest.name),
                             link("Edit", link="/{}/edit".format(rest.id)),
                             link("Delete", link="/{}/delete".format(rest.id))
                             ])
     self._send_responce(out)
Esempio n. 17
0
    def _delete_restaurant_form(self):
        self._create_ok_header()
        out = ""
        id = self.path.split("/")[-2]
        with DBSession() as sess:
            restaurant = sess.query(Restaurant).filter_by(id=id).first()
            nameofrestaurant = restaurant.name

        out += wrapwithh1("Are you sure that you want to delete the Restaurant {}?".format(nameofrestaurant))
        out += "<form method='POST' enctype='multipart/form-data' action='{}'>" \
               "<input name='action' type='submit' value='Delete'>" \
               " </form>".format(self.path)

        out += "<br/>"
        out += link(text="Back to Restaurants list", link=LIST_LINK)
        self._send_responce(out)
Esempio n. 18
0
def comments():
    try:
        if request.method == "POST":
            session = DBSession()
            comment = request.form.get("comment", None)
            time = request.form.get("time", None)
            video = request.form.get("video_link", None)
            comment_value = Comment(data=comment,
                                    timestamp=time,
                                    video_id=video,
                                    user_id=current_user.get_id(),
                                    parent_id=1)
            session.add(comment_value)
            session.commit()
            data = ["video_detail", video]
            if (current_user.email == "*****@*****.**"):
                session = DBSession()
                video = session.query(Videos).all()
                login_user(user)
                return render_template("admin_dashboard.html", videos=video)
            return redirect(url_for('lesson_detail'))
    except Exception as e:
        print e
Esempio n. 19
0
def login():
    try:
        if request.method == "POST":
            session = DBSession()
            username = request.form["username"]
            candidate = 'secret'
            user = session.query(User).filter_by(email=username).first()
            password_value = (hashlib.md5(
                request.form["password"].encode())).hexdigest()
            if user.email == "*****@*****.**":
                session = DBSession()
                video = session.query(Videos).all()
                login_user(user)
                return render_template("admin_dashboard.html", videos=video)
            elif user is not None and password_value == user.password:
                login_user(user)
                return redirect(url_for("dashboard"))
            return "Error"
        else:
            return render_template("login.html")
    except Exception as e:
        print e
Esempio n. 20
0
def dashboard():
    session = DBSession()
    lesson_plans = session.query(LessonPlan).filter_by(
        user_id=current_user.get_id()).all()
    return render_template('dashboard.html', plans=lesson_plans)
Esempio n. 21
0
def validate(name, password):
	query = DBSession.query(User).filter(User.name.in_([name]),User.password.in_([hash_password(password)]))
	return query.first() != None
Esempio n. 22
0
def create_session():
    # create instance of DBSession
    return DBSession()
def restaurants():
    with DBSession() as sess:
        restaurant = sess.query(Restaurant).all()
    return render_template("restaurants.html", restaurant=restaurant)
def menu_item_json(restaurant_id, menu_id):
    with DBSession() as sess:
        menuitem = sess.query(MenuItem).filter_by(
            restaurant_id=restaurant_id).filter_by(id=menu_id).one()
    return jsonify(menuitem.serialize())
def restaurant_menu_json(restaurant_id):
    with DBSession() as sess:
        restaurant = sess.query(Restaurant).filter_by(id=restaurant_id).one()
        menuitems = sess.query(MenuItem).filter_by(restaurant_id=restaurant.id)
    return jsonify(list(item.serialize() for item in menuitems))
import random

from database_setup import DBSession, MenuItem, Restaurant

session = DBSession()

items = [
    'Burger',
    'Fries',
    'Ice Cream Cone',
    'Chicken Sandwich',
    'Salad',
    'Onion Rings',
    'Soft Drink'
]

description_list = """Bacon ipsum dolor amet tri-tip spare ribs kevin strip steak, andouille beef ribs corned beef pastrami shank pork porchetta tail turducken sirloin. Kielbasa meatball short ribs hamburger jerky flank, shoulder chuck. Ground round venison boudin pork belly brisket. Drumstick ball tip ground round doner, landjaeger sausage pork chop venison chicken jowl hamburger. Sausage brisket pork, ham jowl ribeye alcatra. Ribeye jowl flank, ham hock tail fatback boudin ball tip shoulder drumstick shankle andouille. Swine shoulder leberkas, brisket ribeye tail pork chop tongue fatback cupim.
Ground round pork belly shankle frankfurter, ball tip meatball cow. Brisket salami porchetta ground round pig hamburger short ribs ball tip shank. Shankle venison pork belly shank. Beef rump kevin biltong meatloaf andouille capicola bacon. Shankle rump kevin drumstick cow.
Shankle drumstick landjaeger pork loin shoulder ribeye swine. Swine boudin jowl ball tip prosciutto bresaola flank bacon. Rump flank ground round swine cupim. Chuck drumstick frankfurter pork chop, hamburger meatloaf meatball cupim pastrami salami turkey bresaola tri-tip. Tri-tip turkey bresaola brisket strip steak sausage short ribs pastrami beef venison. Pancetta frankfurter pork loin, shank short ribs short loin brisket sirloin meatball tail shankle pastrami. Rump capicola meatball ham hock beef ham t-bone tongue turducken bresaola doner andouille.
Sausage jerky ground round short loin. Brisket kevin strip steak hamburger. Turducken jerky pastrami, leberkas bresaola picanha drumstick porchetta ground round beef. Rump alcatra meatball fatback strip steak ribeye. Cow tongue biltong brisket, alcatra andouille frankfurter shankle bresaola bacon sausage corned beef pork venison.
Filet mignon tongue ham, landjaeger pastrami jowl meatloaf pork belly. Short loin chuck swine pork chop. Cupim andouille spare ribs doner shank pork meatball, pancetta ribeye short loin pork loin turducken tri-tip tongue. Ham hock meatloaf short loin prosciutto, ham turducken short ribs beef pork chop jowl cow pancetta bresaola venison turkey. Tri-tip landjaeger alcatra chicken cupim. Boudin jowl doner, pastrami porchetta turkey ham hock. Beef ribs leberkas ham hock pork chop, spare ribs meatball boudin.""".split(
    '\n')

restaurants = list(session.query(Restaurant).all())

for item in items:
    m = MenuItem(
        name=item,
        description=random.choice(description_list),
        price=round(random.uniform(1.0, 5.0), 2),
        restaurant=random.choice(restaurants)
def restaurant_json(restaurant_id):
    with DBSession() as sess:
        restaurant = sess.query(Restaurant).filter_by(id=restaurant_id).one()
    return jsonify(restaurant.serialize())
Esempio n. 28
0
''' Helper functions for DB operations '''

from database_setup import DBSession
from database_setup import User, Item, Category

session = DBSession()

def clear_database():
    session.query(User).delete()
    session.query(Item).delete()
    session.query(Category).delete()
    session.commit()

def create_category(name):
    category = Category(name = name)
    session.add(category)
    session.commit()
    return category

def create_user(login_session):
    username = login_session['username']
    new_user = User(name = username)
    session.add(new_user)
    session.commit()
    user = session.query(User).filter_by(name = username).one()
    return user.id

def create_item(name, description, category_id, user_id):
    item = Item(name = name, description = description, category_id = category_id, user_id = user_id)
    session.add(item)
    session.commit()
from database_setup import Restaurant, DBSession

names = [
    'Crab Shack',
    'Burger Heaven',
    'Taco Palace',
    'Some Greek Food',
    'Lotsa Italian',
    'Eat Grass And Live!'
]

session = DBSession()
for name in names:
    r = Restaurant(name=name)
    session.add(r)
    session.commit()