Skip to content

Commit

Permalink
Clean up Python files to pass CI Pylinter
Browse files Browse the repository at this point in the history
  • Loading branch information
RoBizMan committed Nov 27, 2024
1 parent 42923da commit fb0dc9a
Show file tree
Hide file tree
Showing 25 changed files with 1,333 additions and 427 deletions.
41 changes: 36 additions & 5 deletions booking/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,52 @@
class BookingAdmin(admin.ModelAdmin):
"""
Custom admin configuration for the Booking model.
Attributes:
list_display (tuple): Fields to display in the admin list view.
list_filter (tuple): Fields to filter bookings in the admin view.
search_fields (tuple): Fields to search bookings by.
ordering (tuple): Default ordering for bookings.
readonly_fields (tuple): Fields that cannot be modified in the admin.
fieldsets (tuple): Grouping of fields in the admin form.
"""
list_display = ('booking_id', 'booking_date', 'user_fullname', 'user_email', 'tutor_fullname', 'tutor_email', 'total_price', 'session_date')

list_display = (
'booking_id', 'booking_date', 'user_fullname',
'user_email', 'tutor_fullname', 'tutor_email',
'total_price', 'session_date'
)
list_filter = ('session_date', 'booking_date')
search_fields = ('booking_id', 'user__personal_firstname', 'user__personal_lastname', 'tutor__tutor_firstname', 'tutor__tutor_lastname')
search_fields = (
'booking_id', 'user__personal_firstname',
'user__personal_lastname',
'tutor__tutor_firstname',
'tutor__tutor_lastname'
)
ordering = ('-booking_date',)

# Read-only fields to prevent modification
readonly_fields = ('booking_id', 'booking_date', 'stripe_pid', 'user_fullname', 'user_email', 'tutor_fullname', 'tutor_email', 'total_price', 'session_date', 'session_time')
readonly_fields = (
'booking_id', 'booking_date', 'stripe_pid',
'user_fullname', 'user_email',
'tutor_fullname', 'tutor_email',
'total_price', 'session_date',
'session_time'
)

# Add the ability to filter bookings by user and tutor
# Fieldsets for grouping fields in the admin form
fieldsets = (
(None, {
'fields': ('booking_id', 'booking_date', 'stripe_pid', 'user_fullname', 'user_email', 'tutor_fullname', 'tutor_email', 'total_price', 'session_date', 'session_time')
'fields': (
'booking_id', 'booking_date', 'stripe_pid',
'user_fullname', 'user_email',
'tutor_fullname', 'tutor_email',
'total_price', 'session_date',
'session_time'
)
}),
)


# Register the Booking model with the custom admin configuration
admin.site.register(Booking, BookingAdmin)
113 changes: 92 additions & 21 deletions booking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,49 @@
from tutor.models import Tutor, TimeSlot, DayAvailability
from personaluser.models import Profile


# Create your models here.
class Booking(models.Model):
"""
Represents a tutoring session booking.
Attributes:
- booking_id (CharField): Unique identifier for the booking.
- booking_date (DateTimeField): Timestamp of when the booking was made.
- stripe_pid (CharField): Stripe's unique transaction ID for payment tracking.
- user (ForeignKey to :model:`personaluser.Profile`): The user who made the booking.
- tutor (ForeignKey to :model:`tutor.Tutor`): The tutor assigned to the booking.
- total_price (DecimalField): Total price for the tutoring session.
- session_date (DateField): The date of the tutoring session.
- session_time (ManyToManyField to :model:`tutor.TimeSlot`): The time slot selected for the tutoring session.
- booking_id (CharField): Unique identifier for the booking,
automatically generated using UUID.
- booking_date (DateTimeField): Timestamp of when the booking was
made, set automatically on creation.
- stripe_pid (CharField): Stripe's unique transaction ID for payment
tracking, ensuring each transaction is identifiable.
- user (ForeignKey to :model:`personaluser.Profile`): The user who
made the booking, linked to their profile.
- user_fullname (CharField): Full name of the user making the
booking, stored for display purposes.
- user_email (CharField): Email address of the user making the
booking, used for communication and notifications.
- tutor (ForeignKey to :model:`tutor.Tutor`): The tutor assigned to
the booking, linking to the Tutor model.
- tutor_fullname (CharField): Full name of the assigned tutor,
stored for display purposes.
- tutor_email (CharField): Email address of the assigned tutor,
used for communication and notifications.
- total_price (DecimalField): Total price for the tutoring session,
stored as a decimal value with two decimal places.
- session_date (DateField): The date of the tutoring session,
indicating when the session will occur.
- session_time (ManyToManyField to :model:`tutor.TimeSlot`): The
time slot(s) selected for the tutoring session, allowing for
flexibility in scheduling.
Methods:
- _generate_booking_id(): Generates a random, unique booking ID
using UUID.
- save(): Overrides the default save method to ensure a unique
booking ID and Stripe PID are set before saving.
- __str__(): Returns a string representation of the Booking instance,
showing the booking number.
- is_available(tutor, session_date, time_slot): Checks if the
specified tutor is available for the given session date and time
slot.
"""

PAYMENT_STATUS_CHOICES = [
Expand All @@ -26,19 +55,60 @@ class Booking(models.Model):
('failed', 'Failed'),
]

booking_id = models.CharField(max_length=32, unique=True, editable=False, verbose_name="Booking ID")
booking_date = models.DateTimeField(auto_now_add=True, editable=False, verbose_name="Booking Date")
stripe_pid = models.CharField(max_length=254, unique=True, null=False, blank=False, default='', editable=False, verbose_name="Stripe Payment ID")
user = models.ForeignKey(Profile, on_delete=models.SET_NULL, related_name="bookings", null=True)
user_fullname = models.CharField(max_length=101, null=True, blank=False, verbose_name="User's Full Name")
user_email = models.CharField(max_length=254, null=True, blank=False, verbose_name="User's Email address")
tutor = models.ForeignKey(Tutor, on_delete=models.SET_NULL, related_name="bookings", null=True)
tutor_fullname = models.CharField(max_length=101, null=True, blank=False, verbose_name="Tutor's Full Name")
tutor_email = models.CharField(max_length=254, null=True, blank=False, verbose_name="Tutor's Email address")
booking_id = models.CharField(
max_length=32, unique=True,
editable=False,
verbose_name="Booking ID"
)
booking_date = models.DateTimeField(
auto_now_add=True,
editable=False,
verbose_name="Booking Date"
)
stripe_pid = models.CharField(
max_length=254, unique=True,
null=False, blank=False,
default='', editable=False,
verbose_name="Stripe Payment ID"
)
user = models.ForeignKey(
Profile, on_delete=models.SET_NULL,
related_name="bookings", null=True
)
user_fullname = models.CharField(
max_length=101, null=True,
blank=False,
verbose_name="User's Full Name"
)
user_email = models.CharField(
max_length=254, null=True,
blank=False,
verbose_name="User's Email address"
)
tutor = models.ForeignKey(
Tutor, on_delete=models.SET_NULL,
related_name="bookings", null=True
)
tutor_fullname = models.CharField(
max_length=101, null=True,
blank=False,
verbose_name="Tutor's Full Name"
)
tutor_email = models.CharField(
max_length=254, null=True,
blank=False,
verbose_name="Tutor's Email address"
)
total_price = models.DecimalField(max_digits=6, decimal_places=2)
session_date = models.DateField()
session_time = models.ManyToManyField(TimeSlot, related_name="bookings")
payment_status = models.CharField(max_length=10, choices=PAYMENT_STATUS_CHOICES, default='pending')
session_time = models.ManyToManyField(
TimeSlot, related_name="bookings"
)
payment_status = models.CharField(
max_length=10,
choices=PAYMENT_STATUS_CHOICES,
default='pending'
)

class Meta:
ordering = ['-booking_date']
Expand All @@ -57,7 +127,7 @@ def save(self, *args, **kwargs):
if not self.booking_id:
self.booking_id = self._generate_booking_id()

if not self.stripe_pid: # Ensure a unique Stripe PID is always generated
if not self.stripe_pid:
self.stripe_pid = self._generate_stripe_pid()

super().save(*args, **kwargs)
Expand All @@ -67,7 +137,8 @@ def __str__(self):

def is_available(tutor, session_date, time_slot):
"""
Check if the tutor is available for the given session date and time slot.
Check if the tutor is available for the given session date and
time slot.
"""
bookings = Booking.objects.filter(
tutor=tutor,
Expand Down
40 changes: 28 additions & 12 deletions booking/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
"""signcoding URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
The `urlpatterns` list routes URLs to views. For more information please
see: https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
1. Add an import: from my_app import views
2. Add a URL to urlpatterns:
path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns:
path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
2. Add a URL to urlpatterns:
path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
Expand All @@ -22,12 +28,22 @@

urlpatterns = [
path('create/', views.booking_create, name='booking_create'),
path('get-available-time-slots/', views.get_available_time_slots, name='get_available_time_slots'),
path('create-payment-intent/', views.create_payment_intent, name='create_payment_intent'),
path('booking-success/<int:booking_id>', views.booking_success, name='booking_success'),
path(
'get-available-time-slots/', views.get_available_time_slots,
name='get_available_time_slots'
),
path(
'create-payment-intent/', views.create_payment_intent,
name='create_payment_intent'
),
path(
'booking-success/<int:booking_id>/', views.booking_success,
name='booking_success'
),
path('wh/stripe/', stripe_webhook, name='stripe-webhook'),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)
Loading

0 comments on commit fb0dc9a

Please sign in to comment.