Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Omarmoatz committed Sep 29, 2024
1 parent 1e759a0 commit 606666d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
25 changes: 15 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ repos:
- id: check-docstring-first
- id: detect-private-key

- repo: https://github.com/joaopalmeiro/djlint
rev: v1.21.0
hooks:
- id: djlint
args: [--ignore, templates, --ignore, static]
exclude: templates/|static/

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
Expand All @@ -36,18 +30,29 @@ repos:
- id: check-docstring-first
exclude: templates/

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.281
# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
hooks:
- id: ruff
args: ["--ignore=templates"]
# Linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
# Formatter
- id: ruff-format


- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: templates/

- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.35.2
hooks:
- id: djlint
args: [--ignore, templates, --ignore, static]
exclude: templates/|static/

# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
Expand Down
35 changes: 24 additions & 11 deletions apps/booking/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from decimal import Decimal
from zoneinfo import ZoneInfo

import pytz
from django.contrib import messages
Expand Down Expand Up @@ -33,8 +34,9 @@ def check_avilability(request, slug):
room_type = get_object_or_404(RoomType, hotel=hotel, slug=room_type)

url = reverse("hotel:room_type_detail", args=(slug, room_type.slug))
rest_url = f"&checkout={checkout}&adults={adults}&children={children}&room_type={room_type}"
url_with_params = f"{url}?hotel_id={hotel.id}&name={name}&email={email}&checkin={checkin}{rest_url}"
url2 = f"&email={email}&checkin={checkin}&checkout={checkout}"
rest_url = f"&adults={adults}&children={children}&room_type={room_type}"
url_with_params = f"{url}?hotel_id={hotel.id}&name={name}{url2}{rest_url}"
return HttpResponseRedirect(url_with_params)
return messages.error(request, "something Happened")

Expand Down Expand Up @@ -92,7 +94,7 @@ def selected_rooms(request):
messages.warning(request, "You deleted all your booked rooms!")
return redirect("/")

for hid, item in request.session["room_selection_obj"].items():
for _hid, item in request.session["room_selection_obj"].values():
hotel_id = int(item["hotel_id"])
room_id = int(item["room_id"])
checkin = item["checkin"]
Expand All @@ -107,9 +109,15 @@ def selected_rooms(request):
hotel = Hotel.objects.get(id=hotel_id)

date_format = "%Y-%m-%d"
chickin_date = datetime.strptime(checkin, date_format)
chickout_date = datetime.strptime(checkout, date_format)
total_days = (chickout_date - chickin_date).days
timezone = ZoneInfo(
"UTC",
)

checkin_date = datetime.strptime(checkin, date_format).replace(tzinfo=timezone)
checkout_date = datetime.strptime(checkout, date_format).replace(
tzinfo=timezone,
)
total_days = (checkout_date - checkin_date).days

total_cost = float(rooms_price * total_days)

Expand Down Expand Up @@ -147,7 +155,7 @@ def delete_room_from_session(request):
{"rooms_len": len(request.session["room_selection_obj"])},
)

for rid, item in request.session["room_selection_obj"].items():
for _rid, item in request.session["room_selection_obj"].values():
hotel_id = int(item["hotel_id"])
room_id = int(item["room_id"])
checkin = item["checkin"]
Expand All @@ -162,9 +170,14 @@ def delete_room_from_session(request):
hotel = Hotel.objects.get(id=hotel_id)

date_format = "%Y-%m-%d"
chickin_date = datetime.strptime(checkin, date_format)
chickout_date = datetime.strptime(checkout, date_format)
total_days = (chickout_date - chickin_date).days
timezone = pytz.UTC
checkin_date = datetime.strptime(checkin, date_format).replace(tzinfo=timezone)
checkout_date = datetime.strptime(checkout, date_format).replace(
tzinfo=timezone,
)

# Calculate total days
total_days = (checkout_date - checkin_date).days

total_cost = float(rooms_price * total_days)

Expand Down Expand Up @@ -204,7 +217,7 @@ def create_booking(request):
rooms_obj = []
if "room_selection_obj" in request.session:
if request.method == "POST":
for rid, item in request.session["room_selection_obj"].items():
for _rid, item in request.session["room_selection_obj"].values():
hotel_id = item["hotel_id"]
room_id = item["room_id"]
checkin = item["checkin"]
Expand Down
3 changes: 2 additions & 1 deletion apps/hotel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def get_absolute_url(self):
return reverse("hotel:hotel_detail", kwargs={"slug": self.slug})

def get_api_url(self):
return f"http://127.0.0.1:8000{reverse('hotel:hotel-detail', kwargs={'slug': self.slug})}"
localhost = "http://127.0.0.1:8000"
return f"{localhost}{reverse('hotel:hotel-detail', kwargs={'slug': self.slug})}"

@property
def avg_rating(self):
Expand Down
2 changes: 1 addition & 1 deletion apps/users/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UserFactory(DjangoModelFactory[User]):
@post_generation
def password(
self,
create: bool,
create: bool, # noqa: FBT001
extracted: Sequence[Any],
**kwargs,
):
Expand Down

0 comments on commit 606666d

Please # to comment.