Git Product home page Git Product logo

final-project's Introduction

Menu for Canton House

Description:

Introduction

This is a restaraunt menu based off of a real restaraunt menu in Dundee. In this website, you can add and remove items from a basket, and the basket will automatically calculate the total cost for you. As well as this, you can search the menu and using AJAX, it will automatically display the menu items containing the query. Finally, you can click on the dish name to expand it and show more details. It uses the flask framework.

To run the website, type flask --app menu_package --debug run

Static and templates

The static folder contains all the js and css. The js folders contain the code necessary for making the AJAX work, and it also attaches listeners whenever a new element is created, so that you can add and remove items to the session in the server. The listeners also control the opening and closing of the details of a dish.

All of the CSS here I wrote myself. I didn't use bootstrap because I felt that it confined me to a certain style, and the freedom of being able to design anything pretty much exactly the way I wanted felt promising. There is also a little bit of responsive web design, for the navbar changes from vertical to horizontal at a certain viewport width. As well as this, I debated adding more responsive features to the website. However, every change I added actually made it look worse.

The templates folder contains the html JINJA files. There is a base.html file which the other files inherit from. The basket.html and index.html just contain the skeleton for the website, and the query.html template is where the list of dishes is generated. The query.html template takes an array of dishes, and then takes all the information based off those dishes and turns into into a list of dishes.

.py files

The db.py file holds all the information necessary for connecting to a database and handling commands. This was actually really hard, and I had to look up a guide for how to do this on the official flask website. I picked this instead of the cs50 database because I wanted to gain skills with a database outside of the cs50 course. In order to actually initialise the database and have show the changes you have made to the database, you need to run:

flask --app flaskr init-db

and it should come up with a message saying if the database has been initialized successfully.

The menu.py file contains all of the routes and handles pretty much everything in the site server side. It is a blueprint, and it gets imported from the init.py file. Every time the user presses 'add' or 'delete' on a menu item, it actually sends a hidden post request to menu.py, which updates the session. It also returns extra information for the JS to use in order to display a new count of a dish, or a new total.

I made my own decorator inside the menu.py file because it avoided me reduplicating the code. Essentailly, the add and delete routes did nearly the same thing, but one deleted an item and one added an item. So I took out the common parts and turned them into a decorator, and applied it to both.

The init.py file turns the folder it is in into a package. This is to make uploading and downloading the website easier, as you can import only this package with the website inside of it, and exclude other folders like tests and such. This file also sets up the flask website and bundles all of the files together into one nice website.

Other files

The schema.sql contains the commands that are ran when you initialise the database with the command up above. You need to create the tables and their relationships, and add the data.

The venv is a virtual environment in python. It allows me to work with a specific version of flask and other modules that are imported, without worrying about what version of flask I have on my pc.

The instance folder contains the actual database created from the initialise command.

The .gitignore file contains files for github to ignore pushing when I type 'git push'.

The notes_for_self is self explanatory. It contains coding conventions that I'm using in the project so I don't mix them up.

final-project's People

Contributors

keyboardguy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.