Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial updates - working code base #266

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
myvenv/*
__pycache__/
file.json
2 changes: 1 addition & 1 deletion 1-pack_web_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def do_pack():
file_name = "versions/web_static_{}.tgz".format(date)
local("tar -cvzf {} web_static".format(file_name))
return file_name
except:
except Exception:
return None
2 changes: 1 addition & 1 deletion 2-do_deploy_web_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def do_deploy(archive_path):
run('rm -rf /data/web_static/current')
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext))
return True
except:
except Exception:
return False
4 changes: 2 additions & 2 deletions 3-deploy_web_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def do_pack():
file_name = "versions/web_static_{}.tgz".format(date)
local("tar -cvzf {} web_static".format(file_name))
return file_name
except:
except Exception:
return None


Expand All @@ -40,7 +40,7 @@ def do_deploy(archive_path):
run('rm -rf /data/web_static/current')
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext))
return True
except:
except Exception:
return False


Expand Down
14 changes: 14 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
Jennifer Huang <[email protected]>
Alexa Orrico <[email protected]>
Joann Vuong <[email protected]>

Patrick Odhiambo <[email protected]>
Steve Murimi <[email protected]>

The following new features and improvements have been added to the project:

- **Selector**: Methods to select and manipulate HTML elements using various selectors.
- **Get and set content**: Functions to retrieve and update the content of HTML elements.
- **Manipulate CSS classes**: Utilities to add, remove, and toggle CSS classes on HTML elements.
- **Manipulate DOM elements**: Functions to create, remove, and modify HTML elements in the DOM.
- **Document ready**: Ensures that the DOM is fully loaded before executing JavaScript code.
- **Introduction**: Added introductory documentation and examples for new users.
- **GET & POST request**: Methods to perform asynchronous HTTP GET and POST requests.
- **HTTP access control (CORS)**: Implemented Cross-Origin Resource Sharing (CORS) to allow secure communication between different domains.
1 change: 1 addition & 0 deletions README2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 0x06. AirBnB clone - Web dynamic
1 change: 1 addition & 0 deletions api/v1/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def not_found(error):
"""
return make_response(jsonify({'error': "Not found"}), 404)


app.config['SWAGGER'] = {
'title': 'AirBnB clone Restful API',
'uiversion': 3
Expand Down
9 changes: 5 additions & 4 deletions console.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def _key_value_parser(self, args):
else:
try:
value = int(value)
except:
except ValueError:
try:
value = float(value)
except:
except ValueError:
continue
new_dict[key] = value
return new_dict
Expand Down Expand Up @@ -140,12 +140,12 @@ def do_update(self, arg):
if args[2] in integers:
try:
args[3] = int(args[3])
except:
except ValueError:
args[3] = 0
elif args[2] in floats:
try:
args[3] = float(args[3])
except:
except ValueError:
args[3] = 0.0
setattr(models.storage.all()[k], args[2], args[3])
models.storage.all()[k].save()
Expand All @@ -160,5 +160,6 @@ def do_update(self, arg):
else:
print("** class doesn't exist **")


if __name__ == '__main__':
HBNBCommand().cmdloop()
1 change: 1 addition & 0 deletions models/city.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class City(BaseModel, Base):
"""Representation of city """
if models.storage_t == "db":
__tablename__ = 'cities'
id = Column(String(60), primary_key=True, nullable=False)
state_id = Column(String(60), ForeignKey('states.id'), nullable=False)
name = Column(String(128), nullable=False)
places = relationship("Place",
Expand Down
2 changes: 1 addition & 1 deletion models/engine/file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def reload(self):
jo = json.load(f)
for key in jo:
self.__objects[key] = classes[jo[key]["__class__"]](**jo[key])
except:
except FileNotFoundError:
pass

def delete(self, obj=None):
Expand Down
1 change: 1 addition & 0 deletions models/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Place(BaseModel, Base):
"""Representation of Place """
if models.storage_t == 'db':
__tablename__ = 'places'
id = Column(String(60), primary_key=True, nullable=False)
city_id = Column(String(60), ForeignKey('cities.id'), nullable=False)
user_id = Column(String(60), ForeignKey('users.id'), nullable=False)
name = Column(String(128), nullable=False)
Expand Down
1 change: 1 addition & 0 deletions models/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class State(BaseModel, Base):
"""Representation of state """
if models.storage_t == "db":
__tablename__ = 'states'
id = Column(String(60), primary_key=True, nullable=False)
name = Column(String(128), nullable=False)
cities = relationship("City",
backref="state",
Expand Down
26 changes: 26 additions & 0 deletions myfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Starting a python env named myvenv:
```sh
python -m venv myvenv
source myvenv/bin/activate
deactivate
```

To set an empty password for the MySQL root user, follow these steps:
Log in to MySQL as the root user using sudo:
sudo mysql -u root

Switch to the mysql database:
USE mysql;

Update the authentication method for the root user to use the mysql_native_password plugin and set an empty password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

Flush the privileges to ensure that the changes take effect:
FLUSH PRIVILEGES;

Exit the MySQL shell:
EXIT;

Run the cat command again with the updated root user credentials:
cat 7-dump.sql | mysql -u root --password=""
cat 7-dump.sql | mysql -u root -p
17 changes: 11 additions & 6 deletions tests/test_models/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@ def test_datetime_attributes(self):
"""Test that two BaseModel instances have different datetime objects
and that upon creation have identical updated_at and created_at
value."""
tic = datetime.now()
time.sleep(1e-4) # Small delay to ensure correct time capture
tic = datetime.utcnow()
inst1 = BaseModel()
toc = datetime.now()
self.assertTrue(tic <= inst1.created_at <= toc)
toc = datetime.utcnow()
self.assertTrue(
tic <= inst1.created_at <= toc,
f"inst1.created_at {inst1.created_at} not in range {tic} - {toc}")
time.sleep(1e-4)
tic = datetime.now()
tic = datetime.utcnow()
inst2 = BaseModel()
toc = datetime.now()
self.assertTrue(tic <= inst2.created_at <= toc)
toc = datetime.utcnow()
self.assertTrue(tic <= inst2.created_at <= toc,
f"inst2.created_at {inst2.created_at} "
f"not in range {tic} - {toc}")
self.assertEqual(inst1.created_at, inst1.updated_at)
self.assertEqual(inst2.created_at, inst2.updated_at)
self.assertNotEqual(inst1.created_at, inst2.created_at)
Expand Down
51 changes: 51 additions & 0 deletions web_dynamic/0-hbnb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from models import storage
from models.state import State
from models.city import City
from models.amenity import Amenity
from models.place import Place
from os import environ
from flask import Flask, render_template
app = Flask(__name__)
# app.jinja_env.trim_blocks = True
# app.jinja_env.lstrip_blocks = True


@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()


@app.route('/', strict_slashes=False)
def index():
""" Redirect to /hbnb """
return hbnb()


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" HBNB is alive! """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
st_ct = []

for state in states:
st_ct.append([state, sorted(state.cities, key=lambda k: k.name)])

amenities = storage.all(Amenity).values()
amenities = sorted(amenities, key=lambda k: k.name)

places = storage.all(Place).values()
places = sorted(places, key=lambda k: k.name)

return render_template('100-hbnb.html',
states=st_ct,
amenities=amenities,
places=places)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
Empty file added web_dynamic/__init__.py
Empty file.
Binary file added web_dynamic/static/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_dynamic/static/images/icon_bath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_dynamic/static/images/icon_bed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_dynamic/static/images/icon_group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_dynamic/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions web_dynamic/static/styles/3-footer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
footer {
position: fixed;
background: white;
height: 60px;
width: 100%;
bottom: 0;
border-top: 1px solid #CCCCCC;
}
footer p {
position: absolute;
text-align: center;
top: 10%;
bottom: 0;
right: 0;
left: 0;
}
11 changes: 11 additions & 0 deletions web_dynamic/static/styles/3-header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
header {
background: white;
height: 70px;
width: 100%;
border-bottom: 1px solid #CCCCCC;
}
header .logo {
background: url("../images/logo.png") no-repeat;
left: 20px;
height: 100%;
}
11 changes: 11 additions & 0 deletions web_dynamic/static/styles/4-common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
margin: 0;
padding: 0;
color: #484848;
font-size: 14px;
font-family: Circular,"Helvetica Neue",Helvetica,Arial,sans-serif;
}
body .container {
max-width: 1000px;
margin: 30px auto;
}
103 changes: 103 additions & 0 deletions web_dynamic/static/styles/6-filters.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
.container .filters {
position: relative;
background: white;
height: 70px;
width: 100%;
border: 1px solid #DDDDDD;
border-radius: 4px;
}
button {
position: absolute;
font-size: 18px;
background: #FF5A5F;
color: #FFFFFF;
height: 48px;
width: 20%;
border-style: none;
border-radius: 4px;
top: 15%;
right: 30px;
}
button:hover {
opacity: 0.9;
}
.filters div {
display: inline-grid;
}
.filters h2 {
margin-left: 15%;
margin-top: 0;
margin-bottom: 0;
font-weight: 600;
}
.filters h3 {
margin-left: 15%;
margin-bottom: 0;
font-weight: 600;
}
.filters h4 {
margin-left: 15%;
margin-top: 0;
font-weight: 400;
font-size: 14px;
}
.locations {
height: 100%;
width: 25%;
border-right: 1px solid #DDDDDD;
}
.amenities {
height: 100%;
width: 25%;
}

.popover {
visibility: hidden;
width: 100%;
border: 1px solid #DDDDDD;
border-radius: 4px;
background: #FAFAFA;
padding-bottom: 15px;
height: 300px;
overflow-y: scroll;
scrollbar-width: none;
max-height: 300px;
}

.popover::-webkit-scrollbar{
width: 0px;
}

.amenities .popover {
padding: 10px 0;
margin-left: -5px;
margin-top: 0%;
}

.amenities .popover ul{
margin: 0px;
}

.locations .popover {
margin-top: 0%;
}
.popover ul {
list-style-type: none;
padding-bottom: 10px;
padding-left: 10px;
}
.popover ul li{
padding: 4px;
padding-left: 10px;
}

.popover ul h2{
margin-top: 1.5%;
margin-bottom: 5%;
margin-left: 0px;
}

.amenities:hover .popover,
.locations:hover .popover {
visibility: visible;
}
Loading