From 31080bddbc0b9f68d2cdd00fd5f229f0fc2e631b Mon Sep 17 00:00:00 2001 From: omarMoatz Date: Thu, 19 Sep 2024 17:06:11 +0300 Subject: [PATCH] added pre commit and linter --- .envs/.local/.postgres | 4 +- .gitignore | 186 ++-- .pre-commit-config.yaml | 49 + .readthedocs.yml | 20 + apps/booking/admin.py | 9 +- apps/booking/apps.py | 4 +- apps/booking/forms.py | 13 +- apps/booking/models.py | 99 +- apps/booking/templates/booking/checkout.html | 473 ++++----- .../includes/total_after_desount.html | 89 +- apps/booking/tests.py | 2 - apps/booking/urls.py | 39 +- apps/booking/views.py | 360 +++---- apps/home/admin.py | 8 +- apps/home/apps.py | 4 +- apps/home/models.py | 27 +- apps/home/site_context_processor.py | 2 +- apps/home/templates/home.html | 938 ++++++++++-------- apps/home/tests.py | 2 - apps/home/urls.py | 4 +- apps/home/views.py | 5 +- apps/hotel/admin.py | 33 +- apps/hotel/api/serializers.py | 84 +- apps/hotel/api/views.py | 28 +- apps/hotel/apps.py | 4 +- apps/hotel/management/commands/populate.py | 54 +- apps/hotel/models.py | 163 +-- apps/hotel/templates/hotel/hotel_detail.html | 697 ++++++------- apps/hotel/templates/hotel/hotel_list.html | 500 +++++----- .../hotel/templates/hotel/rooms_selected.html | 348 +++---- .../templates/hotel/roomtype_detail.html | 382 +++---- apps/hotel/templates/includes/rooms.html | 408 ++++---- apps/hotel/tests.py | 16 +- apps/hotel/urls.py | 27 +- apps/hotel/views.py | 55 +- apps/static/css/style.css | 4 +- apps/static/js/bootstrap.bundle.min.js | 2 +- apps/static/js/bootstrap.min.js | 2 +- apps/static/js/custom.js | 38 +- apps/static/js/main.js | 17 +- apps/static/scss/bootstrap.scss | 2 +- apps/templates/403.html | 4 +- apps/templates/403_csrf.html | 4 +- apps/templates/404.html | 4 +- apps/templates/500.html | 4 +- .../account/base_manage_password.html | 1 - apps/templates/allauth/layouts/entrance.html | 9 +- apps/templates/base.html | 434 ++++---- apps/templates/pages/about.html | 2 - apps/templates/pages/home.html | 2 - apps/templates/users/user_detail.html | 50 +- apps/templates/users/user_form.html | 32 +- apps/users/admin.py | 17 +- apps/users/forms.py | 106 +- apps/users/models.py | 31 +- apps/users/templates/auth_base.html | 99 +- apps/users/templates/users/activation.html | 47 +- apps/users/templates/users/login.html | 60 +- apps/users/templates/users/register.html | 80 +- apps/users/urls.py | 15 +- apps/users/views.py | 103 +- config/settings/base.py | 23 +- config/settings/local.py | 5 +- config/urls.py | 6 +- docker-compose.local.yml | 4 +- docker-compose.production.yml | 8 +- 66 files changed, 3346 insertions(+), 3005 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .readthedocs.yml diff --git a/.envs/.local/.postgres b/.envs/.local/.postgres index 814fdeb..f6044eb 100644 --- a/.envs/.local/.postgres +++ b/.envs/.local/.postgres @@ -3,5 +3,5 @@ POSTGRES_HOST=postgres POSTGRES_PORT=5432 POSTGRES_DB=hotel_hub -POSTGRES_USER=debug -POSTGRES_PASSWORD=debug \ No newline at end of file +POSTGRES_USER=debug +POSTGRES_PASSWORD=debug diff --git a/.gitignore b/.gitignore index 0833597..a2ad9ad 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,10 @@ __pycache__ db.sqlite3 media -# Backup files # -*.bak +# Backup files # +*.bak -# If you are using PyCharm # +# If you are using PyCharm # # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml @@ -45,94 +45,94 @@ out/ # JIRA plugin atlassian-ide-plugin.xml -# Python # -*.py[cod] -*$py.class - -# Distribution / packaging -.Python build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ *.whl -*.egg-info/ -.installed.cfg -*.egg -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -.pytest_cache/ -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery -celerybeat-schedule.* - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# Sublime Text # -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache -*.sublime-workspace -*.sublime-project - -# sftp configuration file -sftp-config.json - -# Package control specific files Package -Control.last-run -Control.ca-list -Control.ca-bundle -Control.system-ca-bundle -GitHub.sublime-settings - -# Visual Studio Code # -.vscode/* -.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -.history \ No newline at end of file +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Sublime Text # +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..eaa8939 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,49 @@ +exclude: '^docs/|/migrations/|devcontainer.json' +default_stages: [commit] + +default_language_version: + python: python3.12 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-json + - id: check-toml + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: check-builtin-literals + - id: check-case-conflict + - id: check-docstring-first + - id: detect-private-key + + - repo: https://github.com/adamchainz/django-upgrade + rev: '1.21.0' + hooks: + - id: django-upgrade + args: ['--target-version', '5.0'] + + # Run the Ruff linter. + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.4 + hooks: + # Linter + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + # Formatter + - id: ruff-format + + - repo: https://github.com/Riverside-Healthcare/djLint + rev: v1.35.2 + hooks: + - id: djlint-reformat-django + - id: djlint-django + +# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date +ci: + autoupdate_schedule: weekly + skip: [] + submodules: false diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..5564388 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,20 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the version of Python and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: '3.12' + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: docs/conf.py + +# Python requirements required to build your docs +python: + install: + - requirements: requirements/local.txt diff --git a/apps/booking/admin.py b/apps/booking/admin.py index cd1a194..b75d5e8 100644 --- a/apps/booking/admin.py +++ b/apps/booking/admin.py @@ -1,10 +1,13 @@ from django.contrib import admin -from apps.booking.models import Booking,Coupon +from apps.booking.models import Booking +from apps.booking.models import Coupon + @admin.register(Booking) class HotelAdmin(admin.ModelAdmin): - list_display = ('user', 'hotel', 'full_name') - search_fields = ('hotel', 'user') + list_display = ("user", "hotel", "full_name") + search_fields = ("hotel", "user") + admin.site.register(Coupon) diff --git a/apps/booking/apps.py b/apps/booking/apps.py index 0741ea7..1173726 100644 --- a/apps/booking/apps.py +++ b/apps/booking/apps.py @@ -2,5 +2,5 @@ class BookingConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'apps.booking' + default_auto_field = "django.db.models.BigAutoField" + name = "apps.booking" diff --git a/apps/booking/forms.py b/apps/booking/forms.py index 778cce6..82d2df2 100644 --- a/apps/booking/forms.py +++ b/apps/booking/forms.py @@ -2,12 +2,18 @@ from apps.booking.models import Booking + class BokingForm(forms.ModelForm): class Meta: model = Booking - fields = ('full_name', 'email', - 'check_in_date', 'check_out_date', - 'num_adults', 'num_children' ) + fields = ( + "full_name", + "email", + "check_in_date", + "check_out_date", + "num_adults", + "num_children", + ) # widgets = { # 'user': forms.Select(attrs={'class': 'form-control'}), # 'event': forms.Select(attrs={'class': 'form-control'}), @@ -18,4 +24,3 @@ class Meta: # # 'invoice_id': forms.TextInput(attrs={'class': 'form-control'}), # 'payment_url': forms.URLInput(attrs={'class': 'form-control'}), # } - \ No newline at end of file diff --git a/apps/booking/models.py b/apps/booking/models.py index 19c38ea..40105fb 100644 --- a/apps/booking/models.py +++ b/apps/booking/models.py @@ -1,65 +1,80 @@ +from datetime import timedelta + from django.db import models -from django.utils.crypto import get_random_string from django.utils import timezone -from datetime import timedelta +from django.utils.crypto import get_random_string from django.utils.translation import gettext_lazy as _ -from model_utils.models import TimeStampedModel, TimeFramedModel +from model_utils.models import TimeFramedModel +from model_utils.models import TimeStampedModel +from apps.hotel.models import Hotel +from apps.hotel.models import Room +from apps.hotel.models import RoomType from apps.users.models import User -from apps.hotel.models import Hotel, Room, RoomType + class Booking(TimeStampedModel): class PAYMENT_METHOD(models.TextChoices): - CASH = 'cash', _('Cash') - VISA = 'visa', _('Visa') - STRIPE = 'stripe', _('Stripe') - PAYPAL = 'paypal', _('Paypal') - - user = models.ForeignKey(User, related_name='booked_user', on_delete=models.CASCADE) - payment_method = models.CharField( max_length=10, choices=PAYMENT_METHOD.choices, blank=True, null=True) - - full_name = models.CharField( max_length=500, blank=True, null=True) - phone = models.CharField( max_length=500, blank=True, null=True) - email = models.EmailField( max_length=900, blank=True, null=True) - - hotel = models.ForeignKey( Hotel, related_name='hotel_booked', on_delete=models.CASCADE) - room_type = models.ManyToManyField( RoomType ) - room = models.ManyToManyField( Room ) - before_discount = models.DecimalField( max_digits=9, decimal_places=2, blank=True, null=True) - total = models.DecimalField( max_digits=9, decimal_places=2, blank=True, null=True) - money_saved = models.DecimalField( max_digits=7, decimal_places=2, blank=True, null=True) - - check_in_date = models.DateField( default=timezone.now, blank=True, null=True) - check_out_date = models.DateField( default=timezone.now, blank=True, null=True) + CASH = "cash", _("Cash") + VISA = "visa", _("Visa") + STRIPE = "stripe", _("Stripe") + PAYPAL = "paypal", _("Paypal") + + user = models.ForeignKey(User, related_name="booked_user", on_delete=models.CASCADE) + payment_method = models.CharField( + max_length=10, choices=PAYMENT_METHOD.choices, blank=True, null=True + ) + + full_name = models.CharField(max_length=500, blank=True, null=True) + phone = models.CharField(max_length=500, blank=True, null=True) + email = models.EmailField(max_length=900, blank=True, null=True) + + hotel = models.ForeignKey( + Hotel, related_name="hotel_booked", on_delete=models.CASCADE + ) + room_type = models.ManyToManyField(RoomType) + room = models.ManyToManyField(Room) + before_discount = models.DecimalField( + max_digits=9, decimal_places=2, blank=True, null=True + ) + total = models.DecimalField(max_digits=9, decimal_places=2, blank=True, null=True) + money_saved = models.DecimalField( + max_digits=7, decimal_places=2, blank=True, null=True + ) + + check_in_date = models.DateField(default=timezone.now, blank=True, null=True) + check_out_date = models.DateField(default=timezone.now, blank=True, null=True) total_days = models.PositiveIntegerField(blank=True, null=True) num_adults = models.PositiveIntegerField(blank=True, null=True) num_children = models.PositiveIntegerField(blank=True, null=True) check_in = models.BooleanField(default=False) check_out = models.BooleanField(default=False) - - booking_code = models.CharField( max_length=500, blank=True, null=True) - coupon = models.ForeignKey('Coupon', on_delete=models.CASCADE, blank=True, null=True) + + booking_code = models.CharField(max_length=500, blank=True, null=True) + coupon = models.ForeignKey( + "Coupon", on_delete=models.CASCADE, blank=True, null=True + ) def __str__(self): - return f'booking{self.id} for {str(self.user)}' - + return f"booking{self.id} for {self.user!s}" + def save(self, *args, **kwargs): - self.booking_code = get_random_string(10) - return super().save(*args, **kwargs) - + self.booking_code = get_random_string(10) + return super().save(*args, **kwargs) + class Meta: - ordering = ['-created'] - + ordering = ["-created"] + class Coupon(TimeFramedModel): - code = models.CharField( max_length=100, blank=True, null=True) - discount = models.PositiveIntegerField( blank=True, null=True) - quantity = models.PositiveIntegerField( blank=True, null=True) + code = models.CharField(max_length=100, blank=True, null=True) + discount = models.PositiveIntegerField(blank=True, null=True) + quantity = models.PositiveIntegerField(blank=True, null=True) def __str__(self): return f"{self.code} - {self.discount}% off" - + def save(self, *args, **kwargs): if not self.end: week = timedelta(days=7) @@ -67,8 +82,8 @@ def save(self, *args, **kwargs): if not self.code: self.code = get_random_string(10) - - return super(Coupon, self).save(*args, **kwargs) + + return super(Coupon, self).save(*args, **kwargs) class Meta: - ordering = ['-start'] + ordering = ["-start"] diff --git a/apps/booking/templates/booking/checkout.html b/apps/booking/templates/booking/checkout.html index 4d5fb63..66ca007 100644 --- a/apps/booking/templates/booking/checkout.html +++ b/apps/booking/templates/booking/checkout.html @@ -1,264 +1,275 @@ {% extends 'base.html' %} + {% load static %} -{% block body %} - -